-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: [Hibernate Search] Via JPA - not getting anything from query
PostPosted: Fri Aug 24, 2007 10:05 am 
Beginner
Beginner

Joined: Tue Jun 27, 2006 6:14 am
Posts: 24
Hibernate version:
Core 3.2.5 (annot 3.3.0, entitymgr 3.3.1, search 3.0.0B4)

Mapping documents: using annotations

Quote:
@Entity
@Table(name = "RB_QM_TEMPLATE")
@javax.persistence.SequenceGenerator(
name="RB_QM_TEMPLATE_SEQ",
sequenceName="RB_QM_TEMPLATE_SEQ")
@Indexed(index="lucene/templates")
public class Template {
...
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="RB_QM_TEMPLATE_SEQ")
@Column(name = "qm_template_id")
@DocumentId
private int templateId = 0;

@Column(name = "qm_template_name")
@Field(index= Index.UN_TOKENIZED)
private String templateName = "";
...


and the persistence.xml
Quote:
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>

<property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
<property name="hibernate.search.worker.backend" value="lucene"/>
<property name="hibernate.search.worker.execution" value="sync"/>
<property name="hibernate.search.reader.strategy" value="shared"/>


</properties>


Code between sessionFactory.openSession() and session.close():
Quote:
ApplicationContext factory = new FileSystemXmlApplicationContext("quoteEngineContext.xml");
EntityManager sess = ((EntityManagerFactory) factory.getBean("entityManagerFactory")).createEntityManager();

FullTextEntityManager fullTextEntityManager = Search.createFullTextEntityManager(sess);

EntityTransaction txn = fullTextEntityManager.getTransaction();
txn.begin();
int idxCount = 0;

List<Inst> ilist = sess.createQuery("select i from Inst i where i.libelle like '%asian%'").getResultList();
for (Inst i: ilist){
fullTextEntityManager.index(i);
idxCount++;
}
log.info("Indexed "+idxCount+" insts");

txn.commit();


Then in same method, I do this:


Quote:
QueryParser parser = new QueryParser("", new StopAnalyzer() );

org.apache.lucene.search.Query luceneQuery = parser.parse( "8%" );
javax.persistence.Query fullTextQuery = fullTextEntityManager.createFullTextQuery( luceneQuery, Inst.class );

List result = fullTextQuery.getResultList(); //return a list of managed objects

The problem is that this result list is always empty. I can see the lucene index files have been created.

Full stack trace of any exception that occurs:
None

Name and version of the database you are using:
Oracle 10g

Thanks in advance for any tips.
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 24, 2007 8:19 pm 
Newbie

Joined: Mon Apr 23, 2007 6:57 pm
Posts: 12
I do not see anywhere you are passing the field name. It should be part of the query like field:8% or set the default field in QueryParser. You could also use MultiFieldQueryParser if you want to search on more than one field.

The field name is your entity property and not the DB column name. Use this tool http://getopt.org/luke/ to validate your search.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 28, 2007 4:02 am 
Beginner
Beginner

Joined: Tue Jun 27, 2006 6:14 am
Posts: 24
Hi,

Thanks - yes, I was confusing myself with what the default field name was.

With luke its a lot clearer now.

Regards
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 28, 2007 3:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Also note that % is not a wildcard for Lucene * is

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.