Hmmm, JIRA is down. > What am I missing?
Invalid test code. System.out.println(hits.id(0)); System.out.println(hits.id(1)); assertEquals(0, hits.length()); If hits.length()==0, then don't try to access any of them. -Yonik On 3/5/06, Erik Hatcher (JIRA) <[EMAIL PROTECTED]> wrote: > [ > http://issues.apache.org/jira/browse/LUCENE-330?page=comments#action_12368948 > ] > > Erik Hatcher commented on LUCENE-330: > ------------------------------------- > > I manually applied that patch (prior to my first comment actually) as > automatically applying didn't work. I just committed another test to > TestFilteredQuery, which fails with this patch with this error: > > java.lang.IndexOutOfBoundsException: Not a valid hit number: 0 > at org.apache.lucene.search.Hits.hitDoc(Hits.java:134) > at org.apache.lucene.search.Hits.id(Hits.java:116) > at > org.apache.lucene.search.TestFilteredQuery.testBoolean(TestFilteredQuery.java:139) > > I'm fairly confident I applied the patch correctly, though I suppose its > possible I missed something. > > Here's an inlined version of the diff I have locally of FilteredQuery: > > $ svn diff FilteredQuery.java > Index: FilteredQuery.java > =================================================================== > --- FilteredQuery.java (revision 383339) > +++ FilteredQuery.java (working copy) > @@ -34,6 +34,7 @@ > * <p>Created: Apr 20, 2004 8:58:29 AM > * > * @author Tim Jones > + * @author Paul Elschot > * @since 1.4 > * @version $Id$ > * @see CachingWrapperFilter > @@ -75,22 +76,42 @@ > // 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. > - public Scorer scorer (IndexReader indexReader) throws IOException { > + // 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 (similarity) { > > - // 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 { > > What am I missing? > > > [PATCH] Use filter bits for next() and skipTo() in FilteredQuery > > ---------------------------------------------------------------- > > > > Key: LUCENE-330 > > URL: http://issues.apache.org/jira/browse/LUCENE-330 > > Project: Lucene - Java > > Type: Improvement > > Components: Search > > Versions: CVS Nightly - Specify date in submission > > Environment: Operating System: other > > Platform: Other > > Reporter: paul.elschot > > Assignee: Lucene Developers > > Priority: Minor > > Attachments: FilteredQuery.java, FilteredQuery.java, FilteredQuery.java, > > FilteredQuery.java, FilteredQueryPatch1.txt, IndexSearcherPatch2.txt, > > SkipFilter.java, SkipFilter.java > > > > This improves performance of FilteredQuery by not calling score() > > on documents that do not pass the filter. > > This passes the current tests for FilteredQuery, but these tests > > have not been adapted/extended. > > -- > This message is automatically generated by JIRA. > - > If you think it was sent incorrectly contact one of the administrators: > http://issues.apache.org/jira/secure/Administrators.jspa > - > For more information on JIRA, see: > http://www.atlassian.com/software/jira > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]