-->
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.  [ 5 posts ] 
Author Message
 Post subject: Searching a collection
PostPosted: Mon Sep 19, 2011 2:25 pm 
Newbie

Joined: Tue Jul 26, 2011 6:46 pm
Posts: 11
How do I search a collection through Lucene?

e.g.

Code:
String searchString = "what to search";
Query luceneQuery = mythQB.keyword().onField(fieldName).matching(searchString).createQuery();


This is what I can do right now.

Now I want to pass a collection of strings in place of one single string. How do I do that?


Top
 Profile  
 
 Post subject: Re: Searching a collection
PostPosted: Tue Sep 20, 2011 5:11 am 
Hibernate Team
Hibernate Team

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

you cannot pass a collection of strings, but you could concatenate the strings and pass it as single string. The matching method will apply the right analyzer for the field you are searching on and analyze your concatenate accordingly.

--Hardy


Top
 Profile  
 
 Post subject: Re: Searching a collection
PostPosted: Wed Sep 21, 2011 3:38 am 
Newbie

Joined: Tue Jul 26, 2011 6:46 pm
Posts: 11
Does that mean there is no simple way of saying search all the strings in the collection (i want to OR them). The query should return all the results that have atleast one word from the collection present in it.


Top
 Profile  
 
 Post subject: Re: Searching a collection
PostPosted: Wed Sep 21, 2011 3:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
This is what's going to happen. The analyzer will analyze your string and combine the tokens with a logical OR. This is the same for your example ""what to search" - the search terms would be "what", "to", "search" combined by OR. Well, "to" would probably discarded as a stop word, but that depends on the analyzer.

If this is not what you want have a look at phrase query. An alternative to concatenating the strings is to call onField(fieldName).matching(searchString) in a loop.

--Hardy


Top
 Profile  
 
 Post subject: Re: Searching a collection
PostPosted: Wed Sep 21, 2011 4:11 am 
Newbie

Joined: Tue Jul 26, 2011 6:46 pm
Posts: 11
Thanks a ton. Tried it and it worked!


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