lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yonik Seeley" <yo...@apache.org>
Subject Scorer.skipTo() valid before next()?
Date Tue, 24 Oct 2006 03:28:34 GMT
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


Mime
View raw message