-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need to add additional criteria to FTQ
PostPosted: Mon Mar 09, 2009 8:55 am 
Newbie

Joined: Mon Mar 09, 2009 7:43 am
Posts: 1
Hi all,

Can anyone assist in explaining to me how to modify a fulltext query I am using so that I can also add some 'WHERE' conditions to the query.

I currently have this query which acts on a 'Film' class. What I want to do is also say where a property called 'client' = a passed in parameter named client. In a normal query it would be something like "FROM Film f WHERE f.client = ?1" and set the client parameter accordingly. But I'm unsure how to do this when also using the lucene FTQ.

My FTQ looks like :

Code:
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
          // create native Lucene query
          String[] fields = new String[]{"title", "description"};
          MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
          org.apache.lucene.search.Query query = parser.parse(search);
// wrap Lucene query in a org.hibernate.Query
          FullTextQuery hibQuery = fullTextEntityManager.createFullTextQuery(query, Film.class);
          hibQuery.setFirstResult(startPosition);
          hibQuery.setMaxResults(maxResult);
// execute search
          //List result = hibQuery.list();
          results = hibQuery.getResultList();



Any advice greatly appreciated.

Thankyou


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 09, 2009 10:53 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

you can combine a freetext search with a Criteria query - see http://www.hibernate.org/hib_docs/searc ... e/#d0e2689.

However, this is not the recommended approach. Instead you should consider all information you need to just run a single Lucene query. Often Filters are also a good candidate for the usecase you are indicating. Check the online documentation for this feature.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.