Index: FilteredQuery.java =================================================================== RCS file: /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/search/FilteredQuery.java,v retrieving revision 1.5 diff -u -3 -p -u -r1.5 FilteredQuery.java --- FilteredQuery.java 18 Jun 2004 09:52:25 -0000 1.5 +++ FilteredQuery.java 6 Jan 2005 15:10:21 -0000 @@ -31,6 +31,7 @@ import java.util.BitSet; *

Created: Apr 20, 2004 8:58:29 AM * * @author Tim Jones + * @author Paul Elschot * @since 1.4 * @version $Id: FilteredQuery.java,v 1.5 2004/06/18 09:52:25 ehatcher Exp $ * @see CachingWrapperFilter @@ -69,22 +70,43 @@ extends Query { // return this query public Query getQuery() { return FilteredQuery.this; } - // return a scorer that overrides the enclosed query's score if - // the given hit has been filtered out. + // return a filtering scorer public Scorer scorer (IndexReader indexReader) throws IOException { final Scorer scorer = weight.scorer (indexReader); final BitSet bitset = filter.bits (indexReader); return new Scorer (query.getSimilarity (searcher)) { - // pass these methods through to the enclosed scorer - public boolean next() throws IOException { return scorer.next(); } + public boolean next() throws IOException { + do { + if (! scorer.next()) { + return false; + } + } while (! bitset.get(scorer.doc())); + /* When skipTo() is allowed on scorer it should be used here + * in combination with bitset.nextSetBit(...) + * See the while loop in skipTo() below. + */ + return true; + } + public int doc() { return scorer.doc(); } - public boolean skipTo (int i) throws IOException { return scorer.skipTo(i); } - - // if the document has been filtered out, set score to 0.0 - public float score() throws IOException { - return (bitset.get(scorer.doc())) ? scorer.score() : 0.0f; + + public boolean skipTo(int i) throws IOException { + if (! scorer.skipTo(i)) { + return false; + } + while (! bitset.get(scorer.doc())) { + int nextFiltered = bitset.nextSetBit(scorer.doc() + 1); + if (nextFiltered == -1) { + return false; + } else if (! scorer.skipTo(nextFiltered)) { + return false; + } + } + return true; } + + public float score() throws IOException { return scorer.score(); } // add an explanation about whether the document was filtered public Explanation explain (int i) throws IOException {