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_index_Terms_
8
#define _lucene_index_Terms_
10
#if defined(_LUCENE_PRAGMA_ONCE)
17
class TermEnum; //predefine
20
/** TermDocs provides an interface for enumerating <document, frequency>
21
pairs for a term. <p> The document portion names each document containing
22
the term. Documents are indicated by number. The frequency portion gives
23
the number of times the term occurred in each document. <p> The pairs are
24
ordered by document number.
26
@see IndexReader#termDocs()
28
class TermDocs: LUCENE_BASE {
33
// Sets this to the data for a term.
34
// The enumeration is reset to the start of the data for this term.
35
virtual void seek(Term* term)=0;
37
/** Sets this to the data for the current term in a {@link TermEnum}.
38
* This may be optimized in some implementations.
40
virtual void seek(TermEnum* termEnum)=0;
42
// Returns the current document number. <p> This is invalid until {@link
43
// #next()} is called for the first time.
44
virtual int32_t doc() const=0;
46
// Returns the frequency of the term within the current document. <p> This
47
// is invalid until {@link #next()} is called for the first time.
48
virtual int32_t freq() const=0;
50
// Moves to the next pair in the enumeration. <p> Returns true iff there is
51
// such a next pair in the enumeration.
52
virtual bool next() =0;
54
// Attempts to read multiple entries from the enumeration, up to length of
55
// <i>docs</i>. Document numbers are stored in <i>docs</i>, and term
56
// frequencies are stored in <i>freqs</i>. The <i>freqs</i> array must be as
57
// int64_t as the <i>docs</i> array.
59
// <p>Returns the number of entries read. Zero is only returned when the
60
// stream has been exhausted.
61
virtual int32_t read(int32_t* docs, int32_t* freqs, int32_t length)=0;
63
// Skips entries to the first beyond the current whose document number is
64
// greater than or equal to <i>target</i>. <p>Returns true iff there is such
65
// an entry. <p>Behaves as if written: <pre>
66
// bool skipTo(int32_t target) {
70
// } while (target > doc());
74
// Some implementations are considerably more efficient than that.
75
virtual bool skipTo(const int32_t target)=0;
77
// Frees associated resources.
78
virtual void close() = 0;
81
/** Solve the diamond inheritence problem by providing a reinterpret function.
82
* No dynamic casting is required and no RTTI data is needed to do this
84
virtual TermPositions* __asTermPositions()=0;
88
// Abstract class for enumerating terms.
90
//<p>Term enumerations are always ordered by Term.compareTo(). Each term in
91
//the enumeration is greater than all that precede it.
92
class TermEnum: LUCENE_BASE {
94
// Increments the enumeration to the next element. True if one exists.
95
virtual bool next()=0;
97
// Returns a pointer to the current Term in the enumeration.
98
virtual Term* term()=0;
100
// Returns the current Term in the enumeration.
101
virtual Term* term(bool pointer){
108
// Returns the docFreq of the current Term in the enumeration.
109
virtual int32_t docFreq() const=0;
111
// Closes the enumeration to further activity, freeing resources.
112
virtual void close() =0;
117
// Term Vector support
118
/** Skips terms to the first beyond the current whose value is
119
* greater or equal to <i>target</i>. <p>Returns true iff there is such
120
* an entry. <p>Behaves as if written: <pre>
121
* public boolean skipTo(Term target) {
125
* } while (target > term());
129
* Some implementations are considerably more efficient than that.
131
virtual bool skipTo(Term* target){
135
} while (target->compareTo(term(false)) > 0);
140
* Because we need to know how to cast the object, we need the objects name.
142
virtual const char* getObjectName() = 0;
148
* TermPositions provides an interface for enumerating the <document,
149
* frequency, <position>* > tuples for a term. <p> The document and
150
* frequency are the same as for a TermDocs. The positions portion lists the ordinal
151
* positions of each occurrence of a term in a document.
153
* @see IndexReader#termPositions()
155
class TermPositions: public virtual TermDocs {
157
// Returns next position in the current document. It is an error to call
158
// this more than {@link #freq()} times
159
// without calling {@link #next()}<p> This is
160
// invalid until {@link #next()} is called for
162
virtual int32_t nextPosition() = 0;
164
virtual ~TermPositions(){
167
/** Solve the diamond inheritence problem by providing a reinterpret function.
168
* No dynamic casting is required and no RTTI data is needed to do this
170
virtual TermDocs* __asTermDocs()=0;
171
virtual TermPositions* __asTermPositions()=0;