You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Yonik Seeley <yo...@apache.org> on 2006/10/24 05:28:34 UTC
Scorer.skipTo() valid before next()?
I got a bit of a surprise trying to re-implement the ConjunctionScorer.
It turns out that skipTo(0) does not always return the same thing as
next() on a newly created scorer. Some scorers give invalid results
if skipTo() is called before next().
The javddoc is unclear on the subject, but the javadoc for both
score() and skipTo() suggest that calling skipTo() first is valid, and
that seems to make more sense.
Thoughts?
/** Returns the current document number matching the query.
* Initially invalid, until {@link #next()} is called the first time.
*/
public abstract int doc();
/** Returns the score of the current document matching the query.
* Initially invalid, until {@link #next()} or {@link #skipTo(int)}
* is called the first time.
*/
public abstract float score() throws IOException;
/** Skips to the first match beyond the current whose document number is
* greater than or equal to a given target.
* <br>When this method is used the {@link #explain(int)} method
should not be used.
* @param target The target document number.
* @return true iff there is such a match.
* <p>Behaves as if written: <pre>
* boolean skipTo(int target) {
* do {
* if (!next())
* return false;
* } while (target > doc());
* return true;
* }
* </pre>Most implementations are considerably more efficient than that.
*/
public abstract boolean skipTo(int target) throws IOException;
-Yonik
http://incubator.apache.org/solr Solr, the open-source Lucene search server
---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org
Re: Scorer.skipTo() valid before next()?
Posted by Chris Hostetter <ho...@fucit.org>.
: I got a bit of a surprise trying to re-implement the ConjunctionScorer.
: It turns out that skipTo(0) does not always return the same thing as
: next() on a newly created scorer. Some scorers give invalid results
: if skipTo() is called before next().
that sounds like a bug to me...
: The javddoc is unclear on the subject, but the javadoc for both
: score() and skipTo() suggest that calling skipTo() first is valid, and
: that seems to make more sense.
i don't see why you would say the javadoc is unclear, the javadoc for
skipTo seems very clear on the subject. skipTo(0) should be functionaly
equivilent to...
do {
if (!next())
return false;
} while (0 > doc());
return true;
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org