-->
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: Creating and executing BooleanQuery
PostPosted: Mon Jan 24, 2011 11:01 pm 
Newbie

Joined: Mon Oct 26, 2009 3:38 pm
Posts: 18
When I manually create a BooleanQuery, as shown below, the resulting FullTextQuery returns a result size of zero even though there should be at least one matching result. However, if I use the MultiFieldQueryParser to create a query using the same criteria, the expected results are returned.

Based on the code snippets below, does anyone see what could be wrong?
Code:
BooleanQuery nameQuery = new BooleanQuery();
TermQuery nameTerms = new TermQuery(new Term("name", search.getCriteria()));
...
...
FullTextEntityManager ftem = org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager);
org.hibernate.search.jpa.FullTextQuery query = ftem.createFullTextQuery(nameQuery, entity);


Top
 Profile  
 
 Post subject: Re: Creating and executing BooleanQuery
PostPosted: Tue Jan 25, 2011 10:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
There is a lot of code missing in your example, but here is a guess.
A term query does not apply any analyzers, but the query parser does. Depending how your search criteria look that might explain the difference. For example the query parser would lowercase all search terms, whereas in your term query capital letters would be preserves and searched for.

--Hardy


Top
 Profile  
 
 Post subject: Re: Creating and executing BooleanQuery
PostPosted: Tue Jan 25, 2011 11:01 pm 
Newbie

Joined: Mon Oct 26, 2009 3:38 pm
Posts: 18
hardy.ferentschik wrote:
There is a lot of code missing in your example, but here is a guess.
A term query does not apply any analyzers, but the query parser does. Depending how your search criteria look that might explain the difference. For example the query parser would lowercase all search terms, whereas in your term query capital letters would be preserves and searched for.

--Hardy


Your guess was correct; the case where I was using the MultiFieldQueryParser (and thus a standard analyzer) the query was changed to lowercase, whereas in the BooleanQuery the search terms where left 'as is.'

Is there a way to have the BooleanQuery or the TermQuery apply an analyzer?

Thanks.


Top
 Profile  
 
 Post subject: Re: Creating and executing BooleanQuery
PostPosted: Wed Jan 26, 2011 2:44 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Afaik, there is not way to apply an analyzer to a TermQuery.


Top
 Profile  
 
 Post subject: Re: Creating and executing BooleanQuery
PostPosted: Wed Feb 02, 2011 12:53 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
Afaik, there is not way to apply an analyzer to a TermQuery.

that's right, what I usually do is to invoke the Analyzer directly, and from the several tokens which it returns you use them to combine in a BooleanQuery

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