lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <>
Subject Re: Negative Match
Date Fri, 11 Feb 2005 00:23:31 GMT

On Feb 10, 2005, at 4:06 PM, Luke Shannon wrote:

> I think I found a pretty good way to do a negative match.
> In this query I am looking for all the Documents that have a 
> kcfileupload
> field with any value except for jpg.
>         Query negativeMatch = new WildcardQuery(new 
> Term("kcfileupload",
> "*jpg*"));
>          BooleanQuery typeNegAll = new BooleanQuery();
>         Query allResults = new WildcardQuery(new Term("kcfileupload", 
> "*"));
>         IndexSearcher searcher = new IndexSearcher(fsDir);
>         BooleanClause clause = new BooleanClause(negativeMatch, false,
> true);
>         typeNegAll.add(allResults, true, false);
>         typeNegAll.add(clause);
>         Hits hits =;
> With the little testing I have done this *seems* to work. Does anyone 
> see a
> problem with this approach?

Sure.... do you realize what WildcardQuery does under the covers?  It 
literally expands to a BooleanQuery for all terms that match the 
pattern.  There is an adjustable limit built-in of 1,024 clauses to 
BooleanQuery.  You obviously have not hit that limit ... yet!

You're better off using the advice offered on this thread 
previously.... create a single dummy field with a fixed value for all 
documents.  Combine a TermQuery for that dummy value with a prohibited 
clause like y our negativeMatch above.


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

View raw message