01 package gate.creole.annic.apache.lucene.search;
02
03 /**
04 * Copyright 2004 The Apache Software Foundation
05 *
06 * Licensed under the Apache License, Version 2.0 (the "License");
07 * you may not use this file except in compliance with the License.
08 * You may obtain a copy of the License at
09 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 import java.io.IOException;
20
21 /** Expert: Implements scoring for a class of queries. */
22 public abstract class Scorer {
23 private Similarity similarity;
24
25 protected Searcher searcher;
26
27 /** Constructs a Scorer. */
28 protected Scorer(Similarity similarity) {
29 this.similarity = similarity;
30 }
31
32 /** Returns the Similarity implementation used by this scorer. */
33 public Similarity getSimilarity() {
34 return this.similarity;
35 }
36
37 /** Scores all documents and passes them to a collector. */
38 public void score(HitCollector hc, Searcher searcher) throws IOException {
39 this.searcher = searcher;
40
41 while (next(this.searcher)) {
42 hc.collect(doc(), score(searcher));
43 }
44 }
45
46
47 /** Advance to the next document matching the query. Returns true iff there
48 * is another match. */
49 public abstract boolean next(Searcher searcher) throws IOException;
50
51 /** Returns the current document number. Initially invalid, until {@link
52 * #next()} is called the first time. */
53 public abstract int doc();
54
55 /** Returns the score of the current document. Initially invalid, until
56 * {@link #next()} is called the first time. */
57 public abstract float score(Searcher searcher) throws IOException;
58
59 /** Skips to the first match beyond the current whose document number is
60 * greater than or equal to <i>target</i>. <p>Returns true iff there is such
61 * a match. <p>Behaves as if written: <pre>
62 * boolean skipTo(int target) {
63 * do {
64 * if (!next())
65 * return false;
66 * } while (target > doc());
67 * return true;
68 * }
69 * </pre>
70 * Most implementations are considerably more efficient than that.
71 */
72 public abstract boolean skipTo(int target) throws IOException;
73
74 /** Returns an explanation of the score for <code>doc</code>. */
75 public abstract Explanation explain(int doc) throws IOException;
76
77 }
|