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: Custom filters and booleanquery (MUST_NOT)
Date Thu, 09 Feb 2006 23:14:58 GMT

: I am experimenting with using a custom filter with QueryParser and ran into
: some unanticipated issues with using NOT terms. I narrowed down the issue

    ...

:             bquery = new BooleanQuery();
:             bquery.add(new BooleanClause(fq, BooleanClause.Occur.MUST_NOT));
:             hits = this.searcher.search(bquery);
:             assertTrue(hits.length() == 1);       // <<<<<<<<<
returns 0, expecting doc #2 (t2) to return...

...this isn't really a Filter issue at all, you're trying to execute a
query that only contains prohibited (ie: MUST_NOT) clauses.  Thus you are
not positively selecting anything -- this is one of hte main use for
MatchAllDocsQuery, try...


          bquery = new BooleanQuery();
          bquery.add(new BooleanClause(fq, BooleanClause.Occur.MUST_NOT));
          bquery.add(new BooleanClause(new MatchAllDocsQuery(),
                     BooleanClause.Occur.MUST));
          hits = this.searcher.search(bquery);
          assertTrue(hits.length() == 1);

...incidently, if you are constructing a FilteredQuery arround a
MatchAllDocsQuery, you might as well use a ConstantScoreQuery instead.


-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