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_TermInfosReader_ 00008 #define _lucene_index_TermInfosReader_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "Terms.h" 00015 #include "SegmentTermEnum.h" 00016 #include "CLucene/store/Directory.h" 00017 #include "CLucene/util/ThreadLocal.h" 00018 #include "FieldInfos.h" 00019 #include "TermInfo.h" 00020 #include "TermInfosWriter.h" 00021 00022 CL_NS_DEF(index) 00029 class TermInfosReader :LUCENE_BASE{ 00030 private: 00031 CL_NS(store)::Directory* directory; 00032 const char* segment; 00033 FieldInfos* fieldInfos; 00034 00035 CL_NS(util)::ThreadLocal<SegmentTermEnum*, 00036 CL_NS(util)::Deletor::Object<SegmentTermEnum> > enumerators; 00037 00038 SegmentTermEnum* getEnum(); 00039 SegmentTermEnum* origEnum; 00040 SegmentTermEnum* indexEnum; 00041 int64_t _size; 00042 00043 Term* indexTerms; 00044 int32_t indexTermsLength; 00045 TermInfo* indexInfos; 00046 int64_t* indexPointers; 00047 00048 DEFINE_MUTEX(THIS_LOCK) 00049 00050 public: 00051 //Constructor. 00052 //Reads the TermInfos file (.tis) and eventually the Term Info Index file (.tii) 00053 TermInfosReader(CL_NS(store)::Directory* dir, const char* segment, FieldInfos* fis); 00054 //Destructor 00055 ~TermInfosReader(); 00056 //Close the enumeration of TermInfos 00057 void close(); 00058 00059 //Return the size of the enumeration of TermInfos 00060 int64_t size() const; 00061 00062 int32_t getSkipInterval() { return origEnum->skipInterval; } 00063 00064 // Returns an enumeration of terms starting at or after the named term. 00065 // If no term is specified, an enumeration of all the Terms 00066 // and TermInfos in the set is returned. 00067 SegmentTermEnum* terms(const Term* term=NULL); 00068 00069 // Returns the TermInfo for a Term in the set 00070 // synchronized 00071 TermInfo* get(const Term* term); 00072 private: 00073 //Reads the term info index file or .tti file. 00074 void ensureIndexIsRead(); 00075 00076 // Returns the offset of the greatest index entry which is less than term. 00077 int32_t getIndexOffset(const Term* term); 00078 00079 //Reposition the current Term and TermInfo to indexOffset 00080 void seekEnum(const int32_t indexOffset); 00081 00082 //Scans the Enumeration of terms for term and returns the corresponding TermInfo instance if found. 00083 //The search is started from the current term. 00084 TermInfo* scanEnum(const Term* term); 00085 00086 //Scans the enumeration to the requested position and returns the 00087 //Term located at that position 00088 Term* scanEnum(const int32_t position); 00089 00090 // Returns the position of a Term in the set 00091 // synchronized 00092 int64_t getPosition(const Term* term); 00093 00094 // Returns the nth term in the set. 00095 // synchronized 00096 Term* get(const int32_t position); 00097 00098 }; 00099 CL_NS_END 00100 #endif