lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject Re: QueryParser behaviour ..
Date Tue, 14 Feb 2006 19:38:18 GMT

: >they key to understanding why that resulted in a phrase query instead of
: >three term queries is that QueryParser doesn't treat comma as a special
: >character, so it saw the string word1,word2,word3 and gave it to your
: >analyzer.  Since your analyzer gave back several tokens QueryParser built
: >a phrase query out of it.
: >
: Exactly this is my question, why the QueryParser creates a Phrase query
: when he gets several tokens from analyzer
: and not a BooleanQuery?

Because if it did that, there would be no way to write phrase queries :)

QueryParser only returns a BooleanQuery when *it* can tell you have
several clauses.  For each "chunk" of text that it thinks of as one
continuous piece of text (either because it doesn't contain whitespaces or
because it has quotes around it) it gives it to the analyzer, if the
analyzer says there are multiple Terms there then QueryParser makes a
PhraseQuery out of it.   or in a nutshell:
   1) if the Parser detects multiple terms, it makes a boolean query
   2) if the Analyzer detects multiple terms, it makes a phrase query

if you don't like this behavior, it can all be circumvented by overriding
getFieldQuery().  you don't even have to teal with the analyzer if you
don't want to.  just call super.getFieldQuery() and if you get back a
PhraseQuery take it apart and build TermQueries wrapped in a boolean
query.




-Hoss


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


Mime
View raw message