/* * Copyright 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; namespace Lucene.Net.Search { /// 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. ///
public abstract class Scorer { private Similarity similarity; /// Constructs a Scorer. /// The Similarity implementation used by this scorer. /// protected internal Scorer(Similarity similarity) { this.similarity = similarity; } /// Returns the Similarity implementation used by this scorer. public virtual Similarity GetSimilarity() { return this.similarity; } /// Scores and collects all matching documents. /// The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. ///
When this method is used the {@link #Explain(int)} method should not be used. /// public virtual void Score(HitCollector hc) { while (Next()) { hc.Collect(Doc(), Score()); } } /// Expert: Collects matching documents in a range. Hook for optimization. /// Note that {@link #next()} must be called once before this method is called /// for the first time. /// /// The collector to which all matching documents are passed through /// {@link HitCollector#Collect(int, float)}. /// /// Do not score documents past this. /// /// true if more matching documents may remain. /// protected internal virtual bool Score(HitCollector hc, int max) { while (Doc() < max) { hc.Collect(Doc(), Score()); if (!Next()) return false; } return true; } /// Advances to the next document matching the query. /// true iff there is another document matching the query. ///
When this method is used the {@link #Explain(int)} method should not be used. ///
public abstract bool Next(); /// 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(); /// Skips to the first match beyond the current whose document number is /// greater than or equal to a given target. ///
When this method is used the {@link #Explain(int)} method should not be used. ///
/// The target document number. /// /// true iff there is such a match. ///

Behaves as if written:

        /// boolean skipTo(int target) {
        /// do {
        /// if (!next())
        /// return false;
        /// } while (target > doc());
        /// return true;
        /// }
        /// 
Most implementations are considerably more efficient than that. ///
public abstract bool SkipTo(int target); /// Returns an explanation of the score for a document. ///
When this method is used, the {@link #next()}, {@link #skipTo(int)} and /// {@link #Score(HitCollector)} methods should not be used. ///
/// The document number for the explanation. /// public abstract Explanation Explain(int doc); } }