2 * Copyright 2004 The Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Lucene
.Net
.Search
22 /// <summary>Expert: Common scoring functionality for different types of queries.
23 /// <br>A <code>Scorer</code> either iterates over documents matching a query,
24 /// or provides an explanation of the score for a query for a given document.
25 /// <br>Document scores are computed using a given <code>Similarity</code> implementation.
27 public abstract class Scorer
29 private Similarity similarity
;
31 /// <summary>Constructs a Scorer.</summary>
32 /// <param name="similarity">The <code>Similarity</code> implementation used by this scorer.
34 protected internal Scorer(Similarity similarity
)
36 this.similarity
= similarity
;
39 /// <summary>Returns the Similarity implementation used by this scorer. </summary>
40 public virtual Similarity
GetSimilarity()
42 return this.similarity
;
45 /// <summary>Scores and collects all matching documents.</summary>
46 /// <param name="hc">The collector to which all matching documents are passed through
47 /// {@link HitCollector#Collect(int, float)}.
48 /// <br>When this method is used the {@link #Explain(int)} method should not be used.
50 public virtual void Score(HitCollector hc
)
54 hc
.Collect(Doc(), Score());
58 /// <summary>Expert: Collects matching documents in a range. Hook for optimization.
59 /// Note that {@link #Next()} must be called once before this method is called
60 /// for the first time.
62 /// <param name="hc">The collector to which all matching documents are passed through
63 /// {@link HitCollector#Collect(int, float)}.
65 /// <param name="max">Do not score documents past this.
67 /// <returns> true if more matching documents may remain.
69 protected internal virtual bool Score(HitCollector hc
, int max
)
73 hc
.Collect(Doc(), Score());
80 /// <summary>Advances to the next document matching the query.</summary>
81 /// <returns> true iff there is another document matching the query.
82 /// <br>When this method is used the {@link #Explain(int)} method should not be used.
84 public abstract bool Next();
86 /// <summary>Returns the current document number matching the query.
87 /// Initially invalid, until {@link #Next()} is called the first time.
89 public abstract int Doc();
91 /// <summary>Returns the score of the current document matching the query.
92 /// Initially invalid, until {@link #Next()} or {@link #SkipTo(int)}
93 /// is called the first time.
95 public abstract float Score();
97 /// <summary>Skips to the first match beyond the current whose document number is
98 /// greater than or equal to a given target.
99 /// <br>When this method is used the {@link #Explain(int)} method should not be used.
101 /// <param name="target">The target document number.
103 /// <returns> true iff there is such a match.
104 /// <p>Behaves as if written: <pre>
105 /// boolean skipTo(int target) {
109 /// } while (target > doc());
112 /// </pre>Most implementations are considerably more efficient than that.
114 public abstract bool SkipTo(int target
);
116 /// <summary>Returns an explanation of the score for a document.
117 /// <br>When this method is used, the {@link #Next()}, {@link #SkipTo(int)} and
118 /// {@link #Score(HitCollector)} methods should not be used.
120 /// <param name="doc">The document number for the explanation.
122 public abstract Explanation
Explain(int doc
);