-->
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.  [ 3 posts ] 
Author Message
 Post subject: Search using parts of the sentence
PostPosted: Fri Dec 23, 2011 12:22 pm 
Newbie

Joined: Fri Dec 23, 2011 11:44 am
Posts: 2
Hi,

I need to build a search that compare parts of the sentence used and find entities that has this words.

Example text of entity:
1º - nigeria java shopia ção mormaii da ACQUA Preto Fosco

The search should to find entities that has this words, independently on the sequence in which they are in the sentence.

if I try to search with sentence "nigeria hibernate" for example, with this words couldnt get any result. The word "hibernate" no has matching with the text of entity.
Another hand, i try to search "nigeria shopia", the search should get one result. Because the text of entity has the words "nigeria" and "shopia".

I try to build using the method keyword(), but this mode use every word of the sentence.
Code:
junction.must(builder.keyword().onField(field).matching(value.toString()).createQuery());

or
This mode, the text of entity should be in order of value used.
Code:
junction.must(builder.phrase().onField(field).sentence(value.toString()).createQuery());


Thanks


Top
 Profile  
 
 Post subject: Re: Search using parts of the sentence
PostPosted: Fri Dec 23, 2011 12:45 pm 
Newbie

Joined: Fri Dec 23, 2011 11:44 am
Posts: 2
I found one solution for my problem. Do split of text and create a build using a method keyword() for each term.

Example of code:
Code:
String[] terms = value.toString().split(" ");
for (String term : terms) {
   junction.must(builder.keyword().onField(field).matching(term.toString()).createQuery());
}


Top
 Profile  
 
 Post subject: Re: Search using parts of the sentence
PostPosted: Wed Dec 28, 2011 8:53 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
right your approach seems correct, assuming you really need only results which include all the words listed in the sentence.
It is common to require "most" of the words, but not necessarily all of them, that usually makes the system easier to use; in this case you would use should instead of must when creating the Query. Or you can use a QueryParser and have it parse the original sentence directly.

_________________
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.  [ 3 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.