#include "CLucene/StdHeader.h" #ifndef _lucene_index_SegmentsReader #define _lucene_index_SegmentsReader #include "SegmentHeader.h" #include "SegmentInfo.h" #include "IndexReader.h" #include "CLucene/document/Document.h" #include "Terms.h" #include "SegmentMergeQueue.h" namespace lucene{ namespace index{ class SegmentsTermDocs:public virtual TermDocs { private: SegmentTermDocs** segTermDocs; protected: SegmentReader** readers; int_t readersLength; const int_t* starts; Term* term; int_t base; int_t pointer; SegmentTermDocs* current; // == segTermDocs[pointer] public: SegmentsTermDocs(SegmentReader** r, int_t rLen, const int_t* s); ~SegmentsTermDocs(); int_t Doc() const; int_t Freq() const; void seek(Term* tterm); bool next(); // Optimized implementation. int_t read(int_t docs[], int_t freqs[]); // As yet unoptimized implementation. bool skipTo(const int_t target); void close(); protected: SegmentTermDocs* termDocs(const SegmentReader& reader) const; private: SegmentTermDocs* termDocs(const int_t i) const; }; class SegmentsTermEnum:public virtual TermEnum { private: SegmentMergeQueue& queue; Term* term; int_t docFreq; public: SegmentsTermEnum(SegmentReader** readers, const int_t readersLength, const int_t starts[], const Term* t); ~SegmentsTermEnum(); bool next(); Term* getTerm(const bool pointer = true); int_t DocFreq() const; void close(); }; class SegmentsTermPositions:public SegmentsTermDocs,public virtual TermPositions { public: SegmentsTermPositions(SegmentReader** r, const int_t rLen, const int_t* s); ~SegmentsTermPositions(){ } int_t nextPosition(); //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); bool next(); void close(); protected: SegmentTermDocs& termDocs(SegmentReader& reader); }; class SegmentsReader:public IndexReader{ protected: SegmentReader** readers; int_t readersLength; int_t* starts; // 1st docno for each segment private: lucene::util::VoidMap normsCache; int_t maxDoc; int_t numDocs; public: SegmentsReader(Directory& directory, SegmentReader** r, int_t rLen); ~SegmentsReader(); DEFINE_MUTEX(NumDocs_LOCK); // synchronized int_t NumDocs(); int_t MaxDoc() const; lucene::document::Document& document(const int_t n); bool isDeleted(const int_t n); DEFINE_MUTEX(getNorms_LOCK); // synchronized l_byte_t* getNorms(const char_t* field); TermEnum& getTerms() const; TermEnum& getTerms(const Term* term) const; int_t docFreq(const Term& t) const; TermDocs& termDocs() const; TermPositions& termPositions() const; private: DEFINE_MUTEX(doDelete_LOCK); // synchronized void doDelete(const int_t n); int_t readerIndex(const int_t n) const; DEFINE_MUTEX(doClose_LOCK); // synchronized void doClose(); }; }} #endif