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_IndexReader_ 00008 #define _lucene_index_IndexReader_ 00009 00010 00011 CL_CLASS_DEF(store,Directory) 00012 //#include "CLucene/store/FSDirectory.h" 00013 CL_CLASS_DEF(store,LuceneLock) 00014 CL_CLASS_DEF(document,Document) 00015 #include "CLucene/util/Array.h" 00016 00017 //#include "CLucene/index/TermVector.h" 00018 //#include "SegmentInfos.h" 00019 //#include "Terms.h" 00020 CL_CLASS_DEF(index,TermFreqVector) 00021 CL_CLASS_DEF(index,TermEnum) 00022 CL_CLASS_DEF(index,Term) 00023 CL_CLASS_DEF(index,TermDocs) 00024 CL_CLASS_DEF(index,TermPositions) 00025 CL_CLASS_DEF(store,Directory) 00026 #include "CLucene/LuceneThreads.h" 00027 #include "CLucene/util/VoidMapSetDefinitions.h" 00028 00029 00030 CL_NS_DEF(index) 00031 00032 // Need this forward declaration as IndexReader and SegmentInfos depend on each other 00033 class SegmentInfos; 00034 00051 class CLUCENE_EXPORT IndexReader :LUCENE_BASE{ 00058 void aquireWriteLock(); 00059 protected: 00066 IndexReader(CL_NS(store)::Directory* dir); 00067 00076 IndexReader(CL_NS(store)::Directory* directory, SegmentInfos* segmentInfos, bool closeDirectory); 00077 00078 00080 virtual void doClose() = 0; 00081 00083 virtual void doSetNorm(int32_t doc, const TCHAR* field, uint8_t value) = 0; 00084 00086 virtual void doUndeleteAll() = 0; 00087 00088 00092 virtual void doDelete(const int32_t docNum) = 0; 00093 00094 public: 00095 //Callback for classes that need to know if IndexReader is closing. 00096 typedef void (*CloseCallback)(IndexReader*, void*); 00097 00099 virtual void doCommit() = 0; 00101 class Internal; 00103 Internal* internal; 00104 00105 00106 enum FieldOption { 00107 // all fields 00108 ALL = 1, 00109 // all indexed fields 00110 INDEXED = 2, 00111 // all fields which are not indexed 00112 UNINDEXED = 4, 00113 // all fields which are indexed with termvectors enables 00114 INDEXED_WITH_TERMVECTOR = 8, 00115 // all fields which are indexed but don't have termvectors enabled 00116 INDEXED_NO_TERMVECTOR = 16, 00117 // all fields where termvectors are enabled. Please note that only standard termvector fields are returned 00118 TERMVECTOR = 32, 00119 // all field with termvectors wiht positions enabled 00120 TERMVECTOR_WITH_POSITION = 64, 00121 // all fields where termvectors with offset position are set 00122 TERMVECTOR_WITH_OFFSET = 128, 00123 // all fields where termvectors with offset and position values set 00124 TERMVECTOR_WITH_POSITION_OFFSET = 256, 00125 // all fields that store payloads 00126 STORES_PAYLOADS = 512 00127 }; 00128 00129 00130 DEFINE_MUTEX(THIS_LOCK) 00131 00132 00133 virtual void commit(); 00134 00135 00137 void undeleteAll(); 00138 00146 virtual void getFieldNames(FieldOption fldOption, StringArrayWithDeletor& retarray) = 0; 00147 00148 _CL_DEPRECATED( getFieldNames(FieldOption, StringArrayWithDeletor&) ) virtual TCHAR** getFieldNames(); 00149 _CL_DEPRECATED( getFieldNames(FieldOption, StringArrayWithDeletor&) ) virtual TCHAR** getFieldNames(bool indexed); 00150 00158 virtual uint8_t* norms(const TCHAR* field) = 0; 00159 00160 00166 virtual void norms(const TCHAR* field, uint8_t* bytes) = 0; 00167 00174 void setNorm(int32_t doc, const TCHAR* field, float_t value); 00175 00185 void setNorm(int32_t doc, const TCHAR* field, uint8_t value); 00186 00188 virtual ~IndexReader(); 00189 00191 static IndexReader* open(const char* path); 00192 00194 static IndexReader* open( CL_NS(store)::Directory* directory, bool closeDirectory=false); 00195 00201 static uint64_t lastModified(const char* directory); 00202 00208 static uint64_t lastModified(const CL_NS(store)::Directory* directory); 00209 00210 00220 static int64_t getCurrentVersion(CL_NS(store)::Directory* directory); 00221 00231 static int64_t getCurrentVersion(const char* directory); 00232 00236 int64_t getVersion(); 00237 00245 bool isCurrent(); 00246 00247 00262 virtual bool getTermFreqVectors(int32_t docNumber, CL_NS(util)::Array<TermFreqVector*>& result) =0; 00263 00278 virtual TermFreqVector* getTermFreqVector(int32_t docNumber, const TCHAR* field) = 0; 00279 00286 static bool indexExists(const char* directory); 00287 00295 static bool indexExists(const CL_NS(store)::Directory* directory); 00296 00298 virtual int32_t numDocs() = 0; 00299 00304 virtual int32_t maxDoc() const = 0; 00305 00311 virtual bool document(int32_t n, CL_NS(document)::Document*) =0; 00312 00313 _CL_DEPRECATED( document(i, document) ) CL_NS(document)::Document* document(const int32_t n); 00314 00316 virtual bool isDeleted(const int32_t n) = 0; 00317 00319 virtual bool hasDeletions() const = 0; 00320 00322 virtual bool hasNorms(const TCHAR* field); 00323 00329 virtual TermEnum* terms() const =0; 00330 00336 virtual TermEnum* terms(const Term* t) const = 0; 00337 00339 virtual int32_t docFreq(const Term* t) const = 0; 00340 00341 /* Returns an unpositioned TermPositions enumerator. 00342 * @memory Caller must clean up 00343 */ 00344 virtual TermPositions* termPositions() const = 0; 00345 00363 TermPositions* termPositions(Term* term) const; 00364 00368 virtual TermDocs* termDocs() const = 0; 00369 00379 TermDocs* termDocs(Term* term) const; 00380 00388 void deleteDocument(const int32_t docNum); 00389 00391 _CL_DEPRECATED( deleteDocument ) void deleteDoc(const int32_t docNum){ deleteDocument(docNum); } 00392 00402 int32_t deleteDocuments(Term* term); 00403 00405 _CL_DEPRECATED( deleteDocuments ) int32_t deleteTerm(Term* term){ return deleteDocuments(term); } 00406 00411 void close(); 00412 00414 static bool isLocked(CL_NS(store)::Directory* directory); 00415 00417 static bool isLocked(const char* directory); 00418 00419 00424 static void unlock(CL_NS(store)::Directory* directory); 00425 static void unlock(const char* path); 00426 00428 CL_NS(store)::Directory* getDirectory(); 00429 00431 static bool isLuceneFile(const char* filename); 00432 00437 void addCloseCallback(CloseCallback callback, void* parameter); 00438 00439 }; 00440 00441 CL_NS_END 00442 #endif 00443 00444