1
/*------------------------------------------------------------------------------
2
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
4
* Distributable under the terms of either the Apache License (Version 2.0) or
5
* the GNU Lesser General Public License, as specified in the COPYING file.
6
------------------------------------------------------------------------------*/
7
#ifndef _lucene_search_Scorer_
8
#define _lucene_search_Scorer_
10
CL_CLASS_DEF(search,Similarity)
11
CL_CLASS_DEF(search,HitCollector)
12
CL_CLASS_DEF(search,Explanation)
17
* Expert: Common scoring functionality for different types of queries.
20
* A <code>Scorer</code> either iterates over documents matching a
21
* query in increasing order of doc Id, or provides an explanation of
22
* the score for a query for a given document.
25
* Document scores are computed using a given <code>Similarity</code>
28
* @see BooleanQuery#setAllowDocsOutOfOrder
30
class CLUCENE_EXPORT Scorer {
32
Similarity* similarity;
34
/** Constructs a Scorer.
35
* @param similarity The <code>Similarity</code> implementation used by this scorer.
37
Scorer(Similarity* _similarity);
42
/** Returns the Similarity implementation used by this scorer. */
43
Similarity* getSimilarity() const;
45
/** Scores and collects all matching documents.
46
* @param 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
virtual void score(HitCollector* hc) ;
52
/** Expert: Collects matching documents in a range. Hook for optimization.
53
* Note that {@link #next()} must be called once before this method is called
55
* @param hc The collector to which all matching documents are passed through
56
* {@link HitCollector#collect(int, float)}.
57
* @param max Do not score documents past this.
58
* @return true if more matching documents may remain.
60
virtual bool score( HitCollector* results, const int32_t maxDoc );
63
* Advances to the document matching this Scorer with the lowest doc Id
64
* greater than the current value of {@link #doc()} (or to the matching
65
* document with the lowest doc Id if next has never been called on
69
* When this method is used the {@link #explain(int)} method should not
73
* @return true iff there is another document matching the query.
74
* @see BooleanQuery#setAllowDocsOutOfOrder
76
virtual bool next() = 0;
78
/** Returns the current document number matching the query.
79
* Initially invalid, until {@link #next()} is called the first time.
81
virtual int32_t doc() const = 0;
83
/** Returns the score of the current document matching the query.
84
* Initially invalid, until {@link #next()} or {@link #skipTo(int)}
85
* is called the first time.
87
virtual float_t score() = 0;
90
* Skips to the document matching this Scorer with the lowest doc Id
91
* greater than or equal to a given target.
94
* The behavior of this method is undefined if the target specified is
95
* less than or equal to the current value of {@link #doc()}.
97
* Behaves as if written:
99
* boolean skipTo(int target) {
103
* } while (target > doc());
107
* Most implementations are considerably more efficient than that.
111
* When this method is used the {@link #explain(int)} method should not
115
* @param target The target document number.
116
* @return true iff there is such a match.
117
* @see BooleanQuery#setAllowDocsOutOfOrder
119
virtual bool skipTo(int32_t target) = 0;
121
/** Returns an explanation of the score for a document.
122
* <br>When this method is used, the {@link #next()}, {@link #skipTo(int)} and
123
* {@link #score(HitCollector)} methods should not be used.
124
* @param doc The document number for the explanation.
126
virtual Explanation* explain(int32_t doc) = 0;
128
/** Returns a string which explains the object */
129
virtual TCHAR* toString() = 0;
131
static bool sort(const Scorer* elem1, const Scorer* elem2);