-->
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.  [ 7 posts ] 
Author Message
 Post subject: dynamic hibernate search lucenne query
PostPosted: Thu Apr 21, 2011 12:46 pm 
Beginner
Beginner

Joined: Mon Apr 04, 2011 12:08 pm
Posts: 32
Is it possible to build a query dynamically, adding clauses depending of you want to search on, the same way it can be done with hibernate criterias ?

like
Code:
org.apache.lucene.search.Query keyWordsQuery = qb.keyword()
                     .onField("title")
                     .matching(keyWord)
                     .createQuery();

org.apache.lucene.search.Query categoryQuery = qb.keyword()
                     .onField("category")
                     .equals(categoryId)
                     .createQuery();

final BooleanJunction<BooleanJunction> bool = qb.bool();

bool.must( keyWordsQuery  );
                  
if (StringUtils.isNotBlank(category)) {
   bool.must(categoryQuery);
}

final Query finalQuery = bool.createQuery();


Top
 Profile  
 
 Post subject: Re: dynamic hibernate search lucenne query
PostPosted: Thu Apr 21, 2011 2:30 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
if course, using the dynamic DSL you can build queries dynamically.. but I don't understand what you're asking as you post an example already?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: dynamic hibernate search lucenne query
PostPosted: Fri Apr 22, 2011 6:06 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 12:08 pm
Posts: 32
I wasn't sure of the behavior
I find the criteria query with .add( ... ) is a bit clearer about what it does

but it works, thanks


Top
 Profile  
 
 Post subject: Re: dynamic hibernate search lucenne query
PostPosted: Fri Apr 22, 2011 6:20 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
If you can suggest a patch to improve docs or javadoc, I'll be glad to apply it.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: dynamic hibernate search lucenne query
PostPosted: Fri Apr 22, 2011 6:27 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 12:08 pm
Posts: 32
I used mostly this

http://docs.jboss.org/hibernate/stable/ ... query.html

I can't figure how to do things like " something and ( this or that ) and stuff in ( a,b,c,d ) "


Top
 Profile  
 
 Post subject: Re: dynamic hibernate search lucenne query
PostPosted: Fri Apr 22, 2011 7:56 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 12:08 pm
Posts: 32
so as far as i understand should is similar to logical "or" and must to a logical "and" ?


Top
 Profile  
 
 Post subject: Re: dynamic hibernate search lucenne query
PostPosted: Fri Apr 22, 2011 8:09 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
so as far as i understand should is similar to logical "or" and must to a logical "and" ?

roughly, yes.
The 'or' is called "should" as there are some implications with score: the more terms it matches, the higher the score.

_________________
Sanne
http://in.relation.to/


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