lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Miller <>
Subject Re: Problem using wildcardsearch in phrase search
Date Sun, 13 May 2007 12:32:51 GMT
You cannot use wildcards in quotes simply because the QueryParser syntax 
does not look for such the top level it is either looking 
for a Wildcard token OR a Quoted token. There is good reason for this: a 
phrase query does not support wildcards. The hack that I suggested 
(looking for a wildcard in the token before returning the TermQuery) was 
only going to work because you where not generating a PhraseQuery with 
your quotes...the KeywordAnalyzer only emits a single token keeping a 
PhraseQuery from being generated....a TermQuery was being generated 
instead...which you wanted to turn into a WildcardQuery if you found a * 
or ? in the Term.

If you wanted Lucene to generally support wildcard queries within quotes 
you have to do a bit of work. One way: instead of generating 
PhraseQueries you override the QueryParser to generate SpanNearQueries, 
then you need to implement a simple SpanWildcardQuery and change some 
logic around in the QueryParser to look for wildcard characters in the 
quoted token and generate the correct Query of SpanNearQuery's and 

Again, I know I am not the clearest of explainers...I just have an itch 
to try and help out anyway <g>.

- Mark

Paul Taylor wrote:
> Mark Miller wrote:
>> You can't use a wildcard within double quotes. The Lucene syntax 
>> grammar does not look for such things. 
> This is the bit I don't get (I have got round the problem), why can't 
> you use wildcards within double quotes, this isnt mentioned anywhere 
> in
> Paul
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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

View raw message