-->
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: Changing to DSL with search
PostPosted: Wed Jan 19, 2011 3:38 pm 
Newbie

Joined: Wed Jan 19, 2011 3:00 pm
Posts: 1
I don't find a way to translate this:

Code:
parser.setDefaultOperator(QueryParser.Operator.AND);


to DSL

It's an option for the users, it can activate, or not, the search for all the words or for at least one he write for the search.

Thanks


Top
 Profile  
 
 Post subject: Re: Changing to DSL with search
PostPosted: Wed Jan 19, 2011 4:00 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
the search for all the words or for at least one he write for the search.

beware, that's not about "at least one", it must contain each term inserted by the user: failing just a single word, the record won't be returned.

Boolean queries are possible by using the must operator, but across queries only:
Code:
Query queryNumber = monthQb.keyword()
      .onField( "monthRomanNumber" )
      .matching( 2 )
      .createQuery();
Query queryName = monthQb.keyword()
      .onField( "name" )
      .matching( "Frebruary" )
      .createQuery();
Query combined = monthQb.bool().must( queryNumber ).must( queryName ).createQuery();


To enforce the "AND" operator across each term of a single String (is that the question?), then the String must still be parsed and using the good old QueryParser should be a good approach. We're also looking into some way to provide this same feature via the DSL, would you have a suggestion for the API?

As far as common use cases, most people who want to enforce AND don't want to enforce it on every single word, so having the different fields not mandating it, and then mandating the "must" operation across queries, as in the example above.

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


Top
 Profile  
 
 Post subject: Re: Changing to DSL with search
PostPosted: Sun Feb 27, 2011 5:54 pm 
Newbie

Joined: Sat Jun 13, 2009 10:06 pm
Posts: 2
Quote:
As far as common use cases, most people who want to enforce AND don't want to enforce it on every single word, so having the different fields not mandating it, and then mandating the "must" operation across queries, as in the example above.


I disagree. I think that it is a very common use case to get a search query from the user, e.g. a query typed into a search text field, and then to have it parsed requiring that each term in the query is present in at least one of the specified fields.

In my code, whenever I use a QueryParser or a MultiFieldQueryParser, I always set its default operator to QueryParser.Operator.AND (I think that in terms of modern-day user's expectations, this makes more sense than Lucene's default QueryParser.Operator.OR).

I have a suggestion for the API: add a matchingAll() method to TermMatchingContext, which would be equivalent to the current matching() except that the parser's default operator will be set to QueryParser.Operator.AND.


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.