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_SearchHeader_
8
#define _lucene_search_SearchHeader_
11
//#include "CLucene/index/IndexReader.h"
12
CL_CLASS_DEF(index,Term)
13
CL_CLASS_DEF(index,IndexReader)
15
CL_CLASS_DEF(document,Document)
16
CL_CLASS_DEF(util,Comparable)
18
//#include "CLucene/util/VoidList.h"
19
//#include "Explanation.h"
20
//#include "Similarity.h"
32
/** Expert: Returned by low-level search implementations.
34
struct CLUCENE_EXPORT ScoreDoc {
35
/** Expert: A hit document's number.
36
* @see Searcher#doc(int32_t)
40
/** Expert: The score of this document for the query. */
44
/** Expert: Returned by low-level search implementations.
45
* @see Searcher#search(Query,Filter,int32_t) */
46
class CLUCENE_EXPORT TopDocs:LUCENE_BASE {
48
/** Expert: The total number of hits for the query.
53
/** Expert: The top hits for the query. */
55
int32_t scoreDocsLength;
57
/** Expert: Constructs a TopDocs. TopDocs takes ownership of the ScoreDoc array*/
58
TopDocs(const int32_t th, ScoreDoc* sds, int32_t scoreDocsLength);
62
/** Expert: Stores the maximum score value encountered, needed for normalizing. */
66
/** Lower-level search API.
67
* <br>HitCollectors are primarily meant to be used to implement queries,
68
* sorting and filtering.
69
* @see Searcher#search(Query,HitCollector)
71
class CLUCENE_EXPORT HitCollector: LUCENE_BASE {
73
/** Called once for every non-zero scoring document, with the document number
76
* <P>If, for example, an application wished to collect all of the hits for a
77
* query in a BitSet, then it might:<pre>
78
* Searcher searcher = new IndexSearcher(indexReader);
79
* final BitSet bits = new BitSet(indexReader.maxDoc());
80
* searcher.search(query, new HitCollector() {
81
* public void collect(int32_t doc, float score) {
87
* <p>Note: This is called in an inner search loop. For good search
88
* performance, implementations of this method should not call
89
* {@link Searcher#doc(int32_t)} or
90
* {@link IndexReader#document(int32_t)} on every
91
* document number encountered. Doing so can slow searches by an order
92
* of magnitude or more.
93
* <p>Note: The <code>score</code> passed to this method is a raw score.
94
* In other words, the score will not necessarily be a float whose value is
97
virtual void collect(const int32_t doc, const float_t score) = 0;
98
virtual ~HitCollector(){}
101
/** Expert: Calculate query weights and build query scorers.
103
* <p>A Weight is constructed by a query, given a Searcher ({@link
104
* Query#_createWeight(Searcher)}). The {@link #sumOfSquaredWeights()} method
105
* is then called on the top-level query to compute the query normalization
106
* factor (@link Similarity#queryNorm(float_t)}). This factor is then passed to
107
* {@link #normalize(float_t)}. At this point the weighting is complete and a
108
* scorer may be constructed by calling {@link #scorer(IndexReader)}.
110
class CLUCENE_EXPORT Weight
115
/** The query that this concerns. */
116
virtual Query* getQuery() = 0;
118
/** The weight for this query. */
119
virtual float_t getValue() = 0;
121
/** The sum of squared weights of contained query clauses. */
122
virtual float_t sumOfSquaredWeights() = 0;
124
/** Assigns the query normalization factor to this. */
125
virtual void normalize(float_t norm) = 0;
127
/** Constructs a scorer for this. */
128
virtual Scorer* scorer(CL_NS(index)::IndexReader* reader) = 0;
130
/** An explanation of the score computation for the named document. */
131
virtual Explanation* explain(CL_NS(index)::IndexReader* reader, int32_t doc) = 0;
133
virtual TCHAR* toString();
136
class CLUCENE_EXPORT HitDoc
141
CL_NS(document)::Document* doc;
143
HitDoc* next; // in doubly-linked cache
144
HitDoc* prev; // in doubly-linked cache
146
HitDoc(const float_t s, const int32_t i);