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