lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <>
Subject Re: Search question (newbie)
Date Fri, 04 Jul 2008 16:18:32 GMT

: How can I trap this situation correctly?  I receive user queries like this
: (quotes included):
:    /from:"fred flintston*"/
: Which produces a query string of
:    /+from:fred  body:flintston/       (where /body/ is the default field)

either you've left something out, or some aspect of your situation is 
broken ... passing the string you describe -- including the quotes -- to 
QueryParser will not create an optional clause for body:flinston ... it 
will create a PhraseQuery consisting of whatever Terms are produced by 
your analyzer for the (unquoted) string...
	 fred flinston*

...note that the "*" is included in the input passed to your analyzer, 
because it has no special meaning inside quotes.

: What I want is:
: /    +from:fred +from:flintston*/

that would require both fred, and something starting with flinston, but it 
wouldn't require them to be close together -- you can achieve that by 
overriding QueryParser.getFieldQuery(String,String).  inspect the 
termText, if it contains something that looks prefix/wildcardish, then 
split the input to get what you want, and delegate to 
QueryParser.getPrefixQuery or getWildCardQuery and then combine up your 
parts into a BooleanQuery.

Or... if you want to take it one step further and require that the clauses 
are near eachother, you can construct a MultiPhraseQuery -- but you'll 
need to have access to an IndexReader in your QueryParser so you can 
expand the prefix/wildcard into it's Terms.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message