-->
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: Boolean AND/OR/NOT searches in Sentences
PostPosted: Fri Sep 23, 2011 7:22 pm 
Regular
Regular

Joined: Tue May 17, 2011 1:45 am
Posts: 52
Hi,

I am building my query like this

String sentence="London";
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(xyz.class ).get();
qb.phrase().onField("city").boostedTo(10).sentence(sentence).createQuery();

The variable sentence will be populated by a form.

Question :

Supposing my end user enters a query like "London OR New York" the above query does not work . I would like to have end users enter that kind of strings and get boolean results.

How is it possible in Hibernate Search API. I am aware of how lucene does it by default but trying to use Hibernate DSL to do the same.

Thanks
D.


Top
 Profile  
 
 Post subject: Re: Boolean AND/OR/NOT searches in Sentences
PostPosted: Mon Sep 26, 2011 10:08 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
when entering "London OR New York" you want to parse the meaning for OR. To do that, use a org.apache.lucene.queryParser.QueryParser to return a Query instance from the string.
Then you can combine different Query instances with the Query DSL, or run it directly.

For example you could after that parsing add additional clauses:
Code:
Query parsedQuery = queryParser.parse( "London OR New York" );
orderQB.bool()
  .must(
      orderQB.range()
           .onField(“price”).above(100).excludeLimit().createQuery() )
  .must( parsedQuery )
      .createQuery()

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