#include "CLucene/StdHeader.h" #ifndef _lucene_index_SegmentHeader_ #define _lucene_index_SegmentHeader_ #include "SegmentInfo.h" #include "CLucene/util/BitVector.h" #include "CLucene/util/VoidMap.h" #include "Term.h" #include "FieldInfos.h" #include "FieldsReader.h" #include "IndexReader.h" #include "TermInfosReader.h" namespace lucene{ namespace index{ class SegmentTermDocs:public TermDocs { protected: // SegmentReader parent const void* parent; private: InputStream* freqStream; int_t freqCount; lucene::util::BitVector* deletedDocs; public: int_t doc; int_t freq; //Parent is a segment reader SegmentTermDocs( void* Parent); virtual ~SegmentTermDocs(); void seek(Term* term); void seek(const TermInfo* ti); void close(); int_t Doc()const; int_t Freq()const; bool next(); // Optimized implementation. int_t read(int_t docs[], int_t freqs[]); // As yet unoptimized implementation. bool skipTo(const int_t target); protected: void skippingDoc(); }; class SegmentTermPositions: public SegmentTermDocs,public virtual TermPositions { private: InputStream* proxStream; int_t proxCount; int_t position; public: //parent is a segment reader SegmentTermPositions(void* Parent); ~SegmentTermPositions(); void seek(TermInfo* ti); void close(); int_t nextPosition(); bool next(); int_t read(const int_t docs[], const int_t freqs[]); //TODO: The virtual members required in TermPositions are defined in the subclass SegmentTermDocs, //but why is there a compiler error because of this. void seek(Term* term); int_t Doc() const; int_t Freq() const; int_t read(int_t docs[], int_t freqs[]); bool skipTo(const int_t target); protected: void skippingDoc(); }; class Norm { public: InputStream& in; l_byte_t* bytes; Norm(InputStream& instrm); ~Norm(); }; class SegmentReader: public IndexReader{ private: bool closeDirectory; const char_t* segment; bool deletedDocsDirty; DEFINE_MUTEX(norms_mutex); lucene::util::VoidMap norms; public: FieldsReader* fieldsReader; lucene::util::BitVector* deletedDocs; InputStream* freqStream; TermInfosReader* tis; InputStream* proxStream; FieldInfos* fieldInfos; SegmentReader(SegmentInfo& si, const bool closeDir=false); virtual ~SegmentReader(); DEFINE_MUTEX(doClose_LOCK); //syncronized void doClose(); static bool hasDeletions(const SegmentInfo& si); DEFINE_MUTEX(doDelete_LOCK); //syncronized void doDelete(const int_t docNum); StringArrayConst& files(); TermEnum& getTerms() const; TermEnum& getTerms(const Term* t) const; DEFINE_MUTEX(document_LOCK); //syncronized //todo: make const func lucene::document::Document& document(const int_t n); DEFINE_MUTEX(isDeleted_LOCK); //syncronized //todo: make const func bool isDeleted(const int_t n); TermDocs& termDocs() const; TermPositions& termPositions() const; int_t docFreq(const Term& t) const; int_t NumDocs(); int_t MaxDoc() const; l_byte_t* getNorms(const char_t* field); void getNorms(const char_t* field, l_byte_t* bytes, const int_t offset); InputStream* normStream(const char_t* field); static void segmentname(char_t* buffer, const char_t* segment, const char_t* ext, const int_t x=-1); void segmentname(char_t* buffer,const char_t* ext, const int_t x=-1 ); //essentially samee as above, but copies return char_t* segmentname(const char_t* ext, const int_t x=-1); private: void openNorms(); void closeNorms(); }; class SegmentReaderLockWith:public LuceneLockWith{ public: SegmentReader* reader; void* doBody(); SegmentReaderLockWith(LuceneLock* lock, SegmentReader* rdr){ this->lock = lock; this->reader = rdr; } }; }} #endif