Lucene++ - a full-featured, c++ search engine
API Documentation


Loading...
Searching...
No Matches
SegmentReader.h
Go to the documentation of this file.
1
2// Copyright (c) 2009-2014 Alan Wright. All rights reserved.
3// Distributable under the terms of either the Apache License (Version 2.0)
4// or the GNU Lesser General Public License.
6
7#ifndef SEGMENTREADER_H
8#define SEGMENTREADER_H
9
10#include "IndexReader.h"
12
13namespace Lucene {
14
15class LPPAPI SegmentReader : public IndexReader {
16public:
18 virtual ~SegmentReader();
19
21
22protected:
24
25INTERNAL:
26 BitVectorPtr deletedDocs;
33
37
40 MapStringNorm _norms;
41
42private:
44 int32_t readBufferSize;
45 bool deletedDocsDirty;
46 bool normsDirty;
47 int32_t pendingDeleteCount;
48
49 bool rollbackHasChanges;
50 bool rollbackDeletedDocsDirty;
51 bool rollbackNormsDirty;
52 int32_t rollbackPendingDeleteCount;
53
54 // optionally used for the .nrm file shared by multiple norms
55 IndexInputPtr singleNormStream;
56 SegmentReaderRefPtr singleNormRef;
57
58public:
59 virtual void initialize();
60
61 using IndexReader::document;
62 using IndexReader::termPositions;
63
64 static SegmentReaderPtr get(bool readOnly, const SegmentInfoPtr& si, int32_t termInfosIndexDivisor);
65 static SegmentReaderPtr get(bool readOnly, const DirectoryPtr& dir, const SegmentInfoPtr& si, int32_t readBufferSize, bool doOpenStores, int32_t termInfosIndexDivisor);
66
68
70 virtual LuceneObjectPtr clone(bool openReadOnly, const LuceneObjectPtr& other = LuceneObjectPtr());
71 SegmentReaderPtr reopenSegment(const SegmentInfoPtr& si, bool doClone, bool openReadOnly);
72
73 static bool hasDeletions(const SegmentInfoPtr& si);
74
76 virtual bool hasDeletions();
77
78 static bool usesCompoundFile(const SegmentInfoPtr& si);
79 static bool hasSeparateNorms(const SegmentInfoPtr& si);
80
82
84 virtual TermEnumPtr terms();
85
87 virtual TermEnumPtr terms(const TermPtr& t);
88
90 virtual DocumentPtr document(int32_t n, const FieldSelectorPtr& fieldSelector);
91
93 virtual bool isDeleted(int32_t n);
94
96 virtual TermDocsPtr termDocs(const TermPtr& term);
97
100
103
105 virtual int32_t docFreq(const TermPtr& t);
106
108 virtual int32_t numDocs();
109
111 virtual int32_t maxDoc();
112
115
117 virtual bool hasNorms(const String& field);
118
120 virtual ByteArray norms(const String& field);
121
123 virtual void norms(const String& field, ByteArray norms, int32_t offset);
124
126
129 void loadTermsIndex(int32_t termsIndexDivisor);
130
131 bool normsClosed(); // for testing only
132 bool normsClosed(const String& field); // for testing only
133
137 virtual TermFreqVectorPtr getTermFreqVector(int32_t docNumber, const String& field);
138
141 virtual void getTermFreqVector(int32_t docNumber, const String& field, const TermVectorMapperPtr& mapper);
142
144 virtual void getTermFreqVector(int32_t docNumber, const TermVectorMapperPtr& mapper);
145
150
153
157
160
163
168
170 virtual int64_t getUniqueTermCount();
171
174
175 virtual int32_t getTermInfosIndexDivisor();
176
177protected:
180
184 virtual ByteArray cloneNormBytes(ByteArray bytes);
185
190
192 virtual void doCommit(MapStringString commitUserData);
193
194 virtual void commitChanges(MapStringString commitUserData);
195
197 virtual void doClose();
198
201 virtual void doDelete(int32_t docNum);
202
204 virtual void doUndeleteAll();
205
207 ByteArray getNorms(const String& field);
208
210 virtual void doSetNorm(int32_t doc, const String& field, uint8_t value);
211
212 void openNorms(const DirectoryPtr& cfsDir, int32_t readBufferSize);
213
214 friend class ReaderPool;
215 friend class IndexWriter;
216 friend class Norm;
217};
218
219}
220
221#endif
#define LUCENE_CLASS(Name)
Definition LuceneObject.h:24
General purpose thread-local map.
Definition CloseableThreadLocal.h:16
Utility template class to handle collections that can be safely copied and shared.
Definition Collection.h:17
Utility template class to handle hash set collections that can be safely copied and shared.
Definition HashSet.h:17
IndexReader is an abstract class, providing an interface for accessing an index. Search of an index i...
Definition IndexReader.h:39
FieldOption
Constants describing field properties, for example used for IndexReader#getFieldNames(FieldOption).
Definition IndexReader.h:48
An IndexWriter creates and maintains an index.
Definition IndexWriter.h:90
Definition SegmentReader.h:15
virtual void doUndeleteAll()
Implements actual undeleteAll() in subclass.
SegmentReaderRefPtr deletedDocsRef
Definition SegmentReader.h:27
void loadTermsIndex(int32_t termsIndexDivisor)
NOTE: only called from IndexWriter when a near real-time reader is opened, or applyDeletes is run,...
void openNorms(const DirectoryPtr &cfsDir, int32_t readBufferSize)
virtual ByteArray norms(const String &field)
Returns the byte-encoded normalization factor for the named field of every document.
bool readOnly
Definition SegmentReader.h:23
virtual void doSetNorm(int32_t doc, const String &field, uint8_t value)
Implements setNorm in subclass.
virtual void doCommit(MapStringString commitUserData)
Implements commit.
SegmentReaderPtr reopenSegment(const SegmentInfoPtr &si, bool doClone, bool openReadOnly)
virtual TermFreqVectorPtr getTermFreqVector(int32_t docNumber, const String &field)
Return a term frequency vector for the specified document and field. The vector returned contains ter...
static SegmentReaderPtr get(bool readOnly, const DirectoryPtr &dir, const SegmentInfoPtr &si, int32_t readBufferSize, bool doOpenStores, int32_t termInfosIndexDivisor)
static SegmentReaderPtr get(bool readOnly, const SegmentInfoPtr &si, int32_t termInfosIndexDivisor)
HashSet< String > files()
virtual ByteArray cloneNormBytes(ByteArray bytes)
Clones the norm bytes. May be overridden by subclasses.
SegmentInfoPtr getSegmentInfo()
Return the SegmentInfo of the segment this reader is reading.
String getSegmentName()
Return the name of the segment this reader is reading.
virtual DocumentPtr document(int32_t n, const FieldSelectorPtr &fieldSelector)
Get the Document at the n'th position.
virtual TermPositionsPtr termPositions()
Returns an unpositioned TermPositions enumerator.
FieldsReaderPtr getFieldsReader()
virtual void getTermFreqVector(int32_t docNumber, const TermVectorMapperPtr &mapper)
Map all the term vectors for all fields in a Document.
ByteArray getNorms(const String &field)
can return null if norms aren't stored
MapStringNorm _norms
Definition SegmentReader.h:40
FieldsReaderLocalPtr fieldsReaderLocal
Definition SegmentReader.h:29
static bool hasDeletions(const SegmentInfoPtr &si)
CloseableThreadLocal< TermVectorsReader > termVectorsLocal
Definition SegmentReader.h:31
virtual void commitChanges(MapStringString commitUserData)
virtual bool hasDeletions()
Returns true if any documents have been deleted.
virtual DirectoryPtr directory()
Returns the directory this index resides in.
virtual TermDocsPtr termDocs()
Returns an unpositioned TermDocs enumerator.
virtual BitVectorPtr cloneDeletedDocs(const BitVectorPtr &bv)
Clones the deleteDocs BitVector. May be overridden by subclasses.
virtual void initialize()
Called directly after instantiation to create objects that depend on this object being fully construc...
virtual LuceneObjectPtr clone(bool openReadOnly, const LuceneObjectPtr &other=LuceneObjectPtr())
Clones the IndexReader and optionally changes readOnly. A readOnly reader cannot open a writable read...
TermVectorsReaderPtr getTermVectorsReader()
Create a clone from the initial TermVectorsReader and store it in the ThreadLocal.
virtual TermEnumPtr terms()
Returns an enumeration of all the terms in the index.
static bool hasSeparateNorms(const SegmentInfoPtr &si)
static SegmentReaderPtr getOnlySegmentReader(const IndexReaderPtr &reader)
virtual HashSet< String > getFieldNames(FieldOption fieldOption)
Get a list of unique field names that exist in this index and have the specified field option informa...
virtual TermEnumPtr terms(const TermPtr &t)
Returns an enumeration of all terms starting at a given term.
virtual TermDocsPtr termDocs(const TermPtr &term)
Returns an enumeration of all the documents which contain term.
virtual void doClose()
Implements close.
virtual Collection< TermFreqVectorPtr > getTermFreqVectors(int32_t docNumber)
Return an array of term frequency vectors for the specified document. The array contains a vector for...
bool normsClosed(const String &field)
virtual int64_t getUniqueTermCount()
Returns the number of unique terms (across all fields) in this reader.
CoreReadersPtr core
Definition SegmentReader.h:28
virtual void getTermFreqVector(int32_t docNumber, const String &field, const TermVectorMapperPtr &mapper)
Load the Term Vector into a user-defined data structure instead of relying on the parallel arrays of ...
virtual int32_t maxDoc()
Returns one greater than the largest possible document number.
virtual bool isDeleted(int32_t n)
Returns true if document n has been deleted.
static bool usesCompoundFile(const SegmentInfoPtr &si)
virtual LuceneObjectPtr getDeletesCacheKey()
This returns null if the reader has no deletions.
virtual int32_t docFreq(const TermPtr &t)
Returns the number of documents containing the term t.
virtual int32_t getTermInfosIndexDivisor()
For IndexReader implementations that use TermInfosReader to read terms, this returns the current inde...
virtual int32_t numDocs()
Returns the number of documents in this index.
SegmentInfoPtr rollbackSegmentInfo
Definition SegmentReader.h:30
virtual LuceneObjectPtr getFieldCacheKey()
This is necessary so that cloned SegmentReaders (which share the underlying postings data) will map t...
FieldInfosPtr fieldInfos()
TermVectorsReaderPtr getTermVectorsReaderOrig()
virtual LuceneObjectPtr clone(const LuceneObjectPtr &other=LuceneObjectPtr())
Efficiently clones the IndexReader (sharing most internal state).
virtual bool hasNorms(const String &field)
Returns true if there are norms stored for this field.
void setSegmentInfo(const SegmentInfoPtr &info)
static SegmentReaderPtr getOnlySegmentReader(const DirectoryPtr &dir)
virtual void doDelete(int32_t docNum)
Implements deletion of the document numbered docNum. Applications should call deleteDocument(int) or ...
virtual void norms(const String &field, ByteArray norms, int32_t offset)
Read norms into a pre-allocated array.
Definition AbstractAllTermDocs.h:12
boost::shared_ptr< CoreReaders > CoreReadersPtr
Definition LuceneTypes.h:100
boost::shared_ptr< LuceneObject > LuceneObjectPtr
Definition LuceneTypes.h:539
boost::shared_ptr< TermPositions > TermPositionsPtr
Definition LuceneTypes.h:243
boost::shared_ptr< FieldInfos > FieldInfosPtr
Definition LuceneTypes.h:127
boost::shared_ptr< TermDocs > TermDocsPtr
Definition LuceneTypes.h:236
boost::shared_ptr< BitVector > BitVectorPtr
Definition LuceneTypes.h:523
boost::shared_ptr< SegmentInfo > SegmentInfoPtr
Definition LuceneTypes.h:208
boost::shared_ptr< FieldSelector > FieldSelectorPtr
Definition LuceneTypes.h:77
boost::shared_ptr< Term > TermPtr
Definition LuceneTypes.h:233
boost::shared_ptr< TermVectorsReader > TermVectorsReaderPtr
Definition LuceneTypes.h:256
boost::shared_ptr< TermVectorMapper > TermVectorMapperPtr
Definition LuceneTypes.h:254
boost::shared_ptr< IndexInput > IndexInputPtr
Definition LuceneTypes.h:493
boost::shared_ptr< Directory > DirectoryPtr
Definition LuceneTypes.h:489
boost::shared_ptr< FieldsReaderLocal > FieldsReaderLocalPtr
Definition LuceneTypes.h:132
boost::shared_ptr< TermEnum > TermEnumPtr
Definition LuceneTypes.h:235
boost::shared_ptr< IndexReader > IndexReaderPtr
Definition LuceneTypes.h:157
boost::shared_ptr< TermFreqVector > TermFreqVectorPtr
Definition LuceneTypes.h:237
boost::shared_ptr< FieldsReader > FieldsReaderPtr
Definition LuceneTypes.h:131
boost::shared_ptr< Document > DocumentPtr
Definition LuceneTypes.h:74
boost::shared_ptr< SegmentReader > SegmentReaderPtr
Definition LuceneTypes.h:215
boost::shared_ptr< SegmentReaderRef > SegmentReaderRefPtr
Definition LuceneTypes.h:216

clucene.sourceforge.net