You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Chris Adams <ch...@emaildatasource.com> on 2009/08/17 16:04:53 UTC

IndexSearcher.search Behavior

I'm not extremely familiar with Lucene, so I am confused at why the
following behavior is happening:
 
When I build up a BooleanQuery using the Lucene objects (combination of
RangeQueries, TermQuery, etc.) I am getting a different result than when
I do a QueryParser.parse(queryString).
 
The BooleanQuery that I build up produces the following output:

String queryString = baseQuery.toString();
Output: +date_received:[20030301 TO 20090913] +type:O24337
+(site_domains_reversed:moc.rettiwt site_domains_reversed:moc.rettiwt.*)

Hits results = indexSearcher.search(baseQuery);
Output: results.length = 0

-------------
However, if I do the following, I get results:
QueryParser stringParser = new QueryParser(LUCENE_SEARCH_FIELD,
PuntEmailIndexHelper.getAnalyzer());
Query parsedQuery = stringParser.parse(baseQuery.toString());
Hits results = indexSearcher.search(parsedQuery);
Output: results.length = 3

My question is, why are the results different?? The query in both cases
is the same, the only difference is that one was "built-up" while the
other one was "parsed" based upon the .toString() method of the built-up
query...

Hopefully, this is making sense and someone can explain why the results
are different.

Thanks for your help.

Chris Adams
Senior Software Engineer

Email Data Source, Inc.
816-448-2045 
chris@emaildatasource.com

EmailDataSource.com <http://www.emaildatasource.com/>   | 5 of the top
20 internet retailers use Email Data Source


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: IndexSearcher.search Behavior

Posted by Chris Adams <ch...@emaildatasource.com>.
Thanks, Mark. That info helped tremendously. 

The problem in my case was that the parse(querystring) was using our
custom analyzer when parsing the entire string, where as the
BooleanObject that was being putting together wasn't using our custom
analyzer for one of the terms when it should have been.

Thanks again. 

-----Original Message-----
From: Mark Miller [mailto:markrmiller@gmail.com] 
Sent: Monday, August 17, 2009 9:09 AM
To: java-user@lucene.apache.org
Subject: Re: IndexSearcher.search Behavior

Unfortunately, many Query's toString output is not actually parsable by
QueryParser (though some are).  If you look at the result Query object
that gets built from the toString output, its likely different than the
BooleanQuery you are putting together.


--
- Mark

http://www.lucidimagination.com



Chris Adams wrote:
> I'm not extremely familiar with Lucene, so I am confused at why the 
> following behavior is happening:
>  
> When I build up a BooleanQuery using the Lucene objects (combination 
> of RangeQueries, TermQuery, etc.) I am getting a different result than

> when I do a QueryParser.parse(queryString).
>  
> The BooleanQuery that I build up produces the following output:
>
> String queryString = baseQuery.toString();
> Output: +date_received:[20030301 TO 20090913] +type:O24337
> +(site_domains_reversed:moc.rettiwt 
> +site_domains_reversed:moc.rettiwt.*)
>
> Hits results = indexSearcher.search(baseQuery);
> Output: results.length = 0
>
> -------------
> However, if I do the following, I get results:
> QueryParser stringParser = new QueryParser(LUCENE_SEARCH_FIELD, 
> PuntEmailIndexHelper.getAnalyzer());
> Query parsedQuery = stringParser.parse(baseQuery.toString());
> Hits results = indexSearcher.search(parsedQuery);
> Output: results.length = 3
>
> My question is, why are the results different?? The query in both 
> cases is the same, the only difference is that one was "built-up" 
> while the other one was "parsed" based upon the .toString() method of 
> the built-up query...
>
> Hopefully, this is making sense and someone can explain why the 
> results are different.
>
> Thanks for your help.
>
> Chris Adams
> Senior Software Engineer
>
> Email Data Source, Inc.
> 816-448-2045
> chris@emaildatasource.com
>
> EmailDataSource.com <http://www.emaildatasource.com/>   | 5 of the top
> 20 internet retailers use Email Data Source
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>   





---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: IndexSearcher.search Behavior

Posted by Mark Miller <ma...@gmail.com>.
Unfortunately, many Query's toString output is not actually parsable by 
QueryParser (though some are).  If you look at the result Query object 
that gets built from the toString output, its likely different than the 
BooleanQuery you are putting together.


-- 
- Mark

http://www.lucidimagination.com



Chris Adams wrote:
> I'm not extremely familiar with Lucene, so I am confused at why the
> following behavior is happening:
>  
> When I build up a BooleanQuery using the Lucene objects (combination of
> RangeQueries, TermQuery, etc.) I am getting a different result than when
> I do a QueryParser.parse(queryString).
>  
> The BooleanQuery that I build up produces the following output:
>
> String queryString = baseQuery.toString();
> Output: +date_received:[20030301 TO 20090913] +type:O24337
> +(site_domains_reversed:moc.rettiwt site_domains_reversed:moc.rettiwt.*)
>
> Hits results = indexSearcher.search(baseQuery);
> Output: results.length = 0
>
> -------------
> However, if I do the following, I get results:
> QueryParser stringParser = new QueryParser(LUCENE_SEARCH_FIELD,
> PuntEmailIndexHelper.getAnalyzer());
> Query parsedQuery = stringParser.parse(baseQuery.toString());
> Hits results = indexSearcher.search(parsedQuery);
> Output: results.length = 3
>
> My question is, why are the results different?? The query in both cases
> is the same, the only difference is that one was "built-up" while the
> other one was "parsed" based upon the .toString() method of the built-up
> query...
>
> Hopefully, this is making sense and someone can explain why the results
> are different.
>
> Thanks for your help.
>
> Chris Adams
> Senior Software Engineer
>
> Email Data Source, Inc.
> 816-448-2045 
> chris@emaildatasource.com
>
> EmailDataSource.com <http://www.emaildatasource.com/>   | 5 of the top
> 20 internet retailers use Email Data Source
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>   





---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org