From 5a1fdc2a72280ed01c1dea20a9ec0edf777f7f92 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Fri, 5 Oct 2007 01:53:29 +0000 Subject: [PATCH] more explicit javadocs about Scorer contract for iterating in doc id order git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@582054 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/search/BooleanQuery.java | 22 +++++-- src/java/org/apache/lucene/search/Scorer.java | 58 +++++++++++++++---- 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/java/org/apache/lucene/search/BooleanQuery.java b/src/java/org/apache/lucene/search/BooleanQuery.java index 6cb289a6688..8bb4361d3d4 100644 --- a/src/java/org/apache/lucene/search/BooleanQuery.java +++ b/src/java/org/apache/lucene/search/BooleanQuery.java @@ -313,15 +313,25 @@ public class BooleanQuery extends Query { private static boolean allowDocsOutOfOrder = false; /** - * Indicates whether hit docs may be collected out of docid - * order. In other words, with this setting, + * Expert: Indicates whether hit docs may be collected out of docid + * order. + * + *

+ * Background: llthough the contract of the Scorer class requires that + * documents be iterated in order of doc id this was not true in early + * versions of Lucene. Many pieces of functionality in the current + * Lucene code base have undefined behavior if this contract is not + * upheld, but in some specific simple cases may be faster. (For + * example: disjunction queries with less than 32 prohibited clauses; + * This setting has no effect for other queries.) + *

+ * + *

+ * Specifics: By setting this option to this true, calls to * {@link HitCollector#collect(int,float)} might be * invoked first for docid N and only later for docid N-1. * Being static, this setting is system wide. - * If collecting docs out of order is allowed, scoring might be faster - * for certain queries, for example disjunction queries with - * less than 32 prohibited clauses. - * This setting has no effect for other queries. + *

*/ public static void setAllowDocsOutOfOrder(boolean allow) { allowDocsOutOfOrder = allow; diff --git a/src/java/org/apache/lucene/search/Scorer.java b/src/java/org/apache/lucene/search/Scorer.java index 25e587c9e03..038771060bf 100644 --- a/src/java/org/apache/lucene/search/Scorer.java +++ b/src/java/org/apache/lucene/search/Scorer.java @@ -19,10 +19,19 @@ package org.apache.lucene.search; import java.io.IOException; -/** Expert: Common scoring functionality for different types of queries. - *
A Scorer either iterates over documents matching a query, - * or provides an explanation of the score for a query for a given document. - *
Document scores are computed using a given Similarity implementation. +/** + * Expert: Common scoring functionality for different types of queries. + * + *

+ * A Scorer either iterates over documents matching a + * query in increasing order of doc Id, or provides an explanation of + * the score for a query for a given document. + *

+ *

+ * Document scores are computed using a given Similarity + * implementation. + *

+ * @see BooleanQuery#setAllowDocsOutOfOrder */ public abstract class Scorer { private Similarity similarity; @@ -67,9 +76,19 @@ public abstract class Scorer { return true; } - /** Advances to the next document matching the query. + /** + * Advances to the document matching this Scorer with the lowest doc Id + * greater then the current value of {@link doc()} (or to the matching + * document with the lowest doc Id if next has never been called on + * this Scorer). + * + *

+ * When this method is used the {@link #explain(int)} method should not + * be used. + *

+ * * @return true iff there is another document matching the query. - *
When this method is used the {@link #explain(int)} method should not be used. + * @see BooleanQuery#setAllowDocsOutOfOrder */ public abstract boolean next() throws IOException; @@ -84,12 +103,16 @@ public abstract class Scorer { */ public abstract float score() throws IOException; - /** Skips to the first match beyond the current whose document number is + /** + * Skips to the document matching this Scorer with the lowest doc Id * greater than or equal to a given target. - *
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. - *

Behaves as if written:

+   *
+   * 

+ * The behavior of this method is undefined if the target specified is + * less then or equal to the current value of {@link #doc()} + *

+ * Behaves as if written: + *

    *   boolean skipTo(int target) {
    *     do {
    *       if (!next())
@@ -97,7 +120,18 @@ public abstract class Scorer {
    *     } while (target > doc());
    *     return true;
    *   }
-   * 
Most implementations are considerably more efficient than that. + *
+ * Most implementations are considerably more efficient than that. + *

+ * + *

+ * 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. + * @see BooleanQuery#setAllowDocsOutOfOrder */ public abstract boolean skipTo(int target) throws IOException;