/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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; using Lucene.Net.Index; namespace Lucene.Net.Search { /// Expert: Common scoring functionality for different types of queries. /// ///

/// A Scorer iterates over documents matching a /// query in increasing order of doc Id. ///

///

/// Document scores are computed using a given Similarity /// implementation. ///

/// ///

NOTE: The values Float.Nan, /// Float.NEGATIVE_INFINITY and Float.POSITIVE_INFINITY are /// not valid scores. Certain collectors (eg ///) will not properly collect hits /// with these scores. ///

public abstract class Scorer:DocIdSetIterator { 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 Similarity { get { return this.similarity; } } /// Scores and collects all matching documents. /// The collector to which all matching documents are passed. /// public virtual void Score(Collector collector) { collector.SetScorer(this); int doc; while ((doc = NextDoc()) != NO_MORE_DOCS) { collector.Collect(doc); } } /// Expert: Collects matching documents in a range. Hook for optimization. /// Note, is added to ensure that /// was called before this method. /// /// /// The collector to which all matching documents are passed. /// /// Do not score documents past this. /// /// /// The first document ID (ensures is called before /// this method. /// /// true if more matching documents may remain. /// public /*protected internal*/ virtual bool Score(Collector collector, int max, int firstDocID) { collector.SetScorer(this); int doc = firstDocID; while (doc < max) { collector.Collect(doc); doc = NextDoc(); } return doc != NO_MORE_DOCS; } /// Returns the score of the current document matching the query. /// Initially invalid, until or /// is called the first time, or when called from within /// . /// public abstract float Score(); } }