CLucene - a full-featured, c++ search engine
API Documentation
00001 /*------------------------------------------------------------------------------ 00002 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00003 * 00004 * Distributable under the terms of either the Apache License (Version 2.0) or 00005 * the GNU Lesser General Public License, as specified in the COPYING file. 00006 ------------------------------------------------------------------------------*/ 00007 #ifndef _lucene_index_Terms_ 00008 #define _lucene_index_Terms_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "Term.h" 00015 CL_NS_DEF(index) 00016 00017 class TermEnum; //predefine 00018 class TermPositions; 00019 00028 class TermDocs: LUCENE_BASE { 00029 public: 00030 virtual ~TermDocs(){ 00031 } 00032 00033 // Sets this to the data for a term. 00034 // The enumeration is reset to the start of the data for this term. 00035 virtual void seek(Term* term)=0; 00036 00040 virtual void seek(TermEnum* termEnum)=0; 00041 00042 // Returns the current document number. <p> This is invalid until {@link 00043 // #next()} is called for the first time. 00044 virtual int32_t doc() const=0; 00045 00046 // Returns the frequency of the term within the current document. <p> This 00047 // is invalid until {@link #next()} is called for the first time. 00048 virtual int32_t freq() const=0; 00049 00050 // Moves to the next pair in the enumeration. <p> Returns true iff there is 00051 // such a next pair in the enumeration. 00052 virtual bool next() =0; 00053 00054 // Attempts to read multiple entries from the enumeration, up to length of 00055 // <i>docs</i>. Document numbers are stored in <i>docs</i>, and term 00056 // frequencies are stored in <i>freqs</i>. The <i>freqs</i> array must be as 00057 // int64_t as the <i>docs</i> array. 00058 // 00059 // <p>Returns the number of entries read. Zero is only returned when the 00060 // stream has been exhausted. 00061 virtual int32_t read(int32_t* docs, int32_t* freqs, int32_t length)=0; 00062 00063 // Skips entries to the first beyond the current whose document number is 00064 // greater than or equal to <i>target</i>. <p>Returns true iff there is such 00065 // an entry. <p>Behaves as if written: <pre> 00066 // bool skipTo(int32_t target) { 00067 // do { 00068 // if (!next()) 00069 // return false; 00070 // } while (target > doc()); 00071 // return true; 00072 // } 00073 // </pre> 00074 // Some implementations are considerably more efficient than that. 00075 virtual bool skipTo(const int32_t target)=0; 00076 00077 // Frees associated resources. 00078 virtual void close() = 0; 00079 00080 00084 virtual TermPositions* __asTermPositions()=0; 00085 }; 00086 00087 00088 // Abstract class for enumerating terms. 00089 // 00090 //<p>Term enumerations are always ordered by Term.compareTo(). Each term in 00091 //the enumeration is greater than all that precede it. 00092 class TermEnum: LUCENE_BASE { 00093 public: 00094 // Increments the enumeration to the next element. True if one exists. 00095 virtual bool next()=0; 00096 00097 // Returns a pointer to the current Term in the enumeration. 00098 virtual Term* term()=0; 00099 00100 // Returns the current Term in the enumeration. 00101 virtual Term* term(bool pointer){ 00102 Term* ret = term(); 00103 if ( !pointer ) 00104 ret->__cl_decref(); 00105 return ret; 00106 } 00107 00108 // Returns the docFreq of the current Term in the enumeration. 00109 virtual int32_t docFreq() const=0; 00110 00111 // Closes the enumeration to further activity, freeing resources. 00112 virtual void close() =0; 00113 00114 virtual ~TermEnum(){ 00115 } 00116 00117 // Term Vector support 00131 virtual bool skipTo(Term* target){ 00132 do { 00133 if (!next()) 00134 return false; 00135 } while (target->compareTo(term(false)) > 0); 00136 return true; 00137 } 00138 00142 virtual const char* getObjectName() = 0; 00143 }; 00144 00145 00146 00155 class TermPositions: public virtual TermDocs { 00156 public: 00157 // Returns next position in the current document. It is an error to call 00158 // this more than {@link #freq()} times 00159 // without calling {@link #next()}<p> This is 00160 // invalid until {@link #next()} is called for 00161 // the first time. 00162 virtual int32_t nextPosition() = 0; 00163 00164 virtual ~TermPositions(){ 00165 } 00166 00170 virtual TermDocs* __asTermDocs()=0; 00171 virtual TermPositions* __asTermPositions()=0; 00172 }; 00173 CL_NS_END 00174 #endif