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_Term_ 00008 #define _lucene_index_Term_ 00009 00010 00011 //#include "CLucene/util/Misc.h" 00012 //#include "CLucene/util/StringIntern.h" 00013 #include "CLucene/util/VoidMapSetDefinitions.h" 00014 # include <functional> 00015 00016 CL_NS_DEF(index) 00017 00018 00038 class Term:LUCENE_REFBASE { 00039 private: 00040 size_t cachedHashCode; 00041 const TCHAR* _field; 00042 //CLStringIntern::iterator fielditr; 00043 #ifdef LUCENE_TERM_TEXT_LENGTH 00044 TCHAR _text[LUCENE_TERM_TEXT_LENGTH+1]; 00045 #else 00046 TCHAR* _text; 00047 size_t textLenBuf; //a cache of text len, this allows for a preliminary comparison of text lengths 00048 //bool dupT; //Indicates if Term Text is duplicated (and therefore must be deleted). 00049 #endif 00050 size_t textLen; //a cache of text len, this allows for a preliminary comparison of text lengths 00051 bool internF; //Indicates if Term Field is interned(and therefore must be uninternd). 00052 public: 00053 00054 //uses the specified fieldTerm's field. this saves on intern'ing time. 00055 Term(const Term* fieldTerm, const TCHAR* txt); 00056 00058 Term(); 00059 00060 //todo: these need to be private, but a few other things need to be changed first... 00061 Term(const TCHAR* fld, const TCHAR* txt, bool internField); 00062 00069 Term(const TCHAR* fld, const TCHAR* txt); 00070 00072 ~Term(); 00073 00076 const TCHAR* field() const; 00077 00081 const TCHAR* text() const; 00082 00084 inline void set(const TCHAR* fld, const TCHAR* txt){ 00085 set(fld,txt,true); 00086 } 00087 00093 void set(const Term* term, const TCHAR* txt); 00094 00095 void set(const TCHAR* fld, const TCHAR* txt, const bool internField); 00096 00102 int32_t compareTo(const Term* other) const; 00103 00104 bool equals(const Term* other) const; 00105 00106 size_t textLength() const { return textLen; } 00107 00110 TCHAR* toString() const; 00111 00112 size_t hashCode(); 00113 }; 00114 00115 00116 class Term_Equals:public CL_NS_STD(binary_function)<const Term*,const Term*,bool> 00117 { 00118 public: 00119 bool operator()( const Term* val1, const Term* val2 ) const{ 00120 return val1->equals(val2); 00121 } 00122 }; 00123 00124 class Term_Compare:LUCENE_BASE, public CL_NS(util)::Compare::_base //<Term*> 00125 { 00126 public: 00127 bool operator()( Term* t1, Term* t2 ) const{ 00128 return ( t1->compareTo(t2) < 0 ); 00129 } 00130 size_t operator()( Term* t ) const{ 00131 return t->hashCode(); 00132 } 00133 }; 00134 00135 CL_NS_END 00136 #endif