/*
* 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;
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 {@link
/// TopScoreDocCollector}) 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 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.
///
/// use {@link #Score(Collector)} instead.
///
[Obsolete("use Score(Collector) instead.")]
public virtual void Score(HitCollector hc)
{
Score(new HitCollectorWrapper(hc));
}
/// Scores and collects all matching documents.
/// The collector to which all matching documents are passed.
///
When this method is used the {@link #Explain(int)} method should not be used.
///
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 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.
///
/// use {@link #Score(Collector, int, int)} instead.
///
[Obsolete("use Score(Collector, int, int) instead")]
protected internal virtual bool Score(HitCollector hc, int max)
{
return Score(new HitCollectorWrapper(hc), max, DocID());
}
/// Expert: Collects matching documents in a range. Hook for optimization.
/// Note, firstDocID
is added to ensure that {@link #NextDoc()}
/// 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 {@link #NextDoc()} 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 {@link #Next()} or {@link #SkipTo(int)}
/// is called the first time, or when called from within
/// {@link Collector#collect}.
///
public abstract float Score();
/// 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.
///
///
/// Please use {@link IndexSearcher#explain}
/// or {@link Weight#explain} instead.
///
public virtual Explanation Explain(int doc)
{
throw new System.NotSupportedException();
}
}
}