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

SegmentReader.h
Go to the documentation of this file.
1 // 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"
11 #include "CloseableThreadLocal.h"
12
13 namespace Lucene {
14
15 class LPPAPI SegmentReader : public IndexReader {
16 public:
17 SegmentReader();
18 virtual ~SegmentReader();
19
20 LUCENE_CLASS(SegmentReader);
21
22 protected:
23 bool readOnly;
24
25 INTERNAL:
26 BitVectorPtr deletedDocs;
27 SegmentReaderRefPtr deletedDocsRef;
28 CoreReadersPtr core;
29 FieldsReaderLocalPtr fieldsReaderLocal;
30 SegmentInfoPtr rollbackSegmentInfo;
31 CloseableThreadLocal<TermVectorsReader> termVectorsLocal;
32 FieldInfosPtr fieldInfos();
33
36 TermVectorsReaderPtr getTermVectorsReader();
37
38 TermVectorsReaderPtr getTermVectorsReaderOrig();
39 FieldsReaderPtr getFieldsReader();
40 MapStringNorm _norms;
41
42 private:
43 SegmentInfoPtr si;
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
58 public:
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
67 void openDocStores();
68
69 virtual LuceneObjectPtr clone(const LuceneObjectPtr& other = LuceneObjectPtr());
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
81 HashSet<String> files();
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
99 virtual TermDocsPtr termDocs();
100
102 virtual TermPositionsPtr termPositions();
103
105 virtual int32_t docFreq(const TermPtr& t);
106
108 virtual int32_t numDocs();
109
111 virtual int32_t maxDoc();
112
114 virtual HashSet<String> getFieldNames(FieldOption fieldOption);
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
125 bool termsIndexLoaded();
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
149 virtual Collection<TermFreqVectorPtr> getTermFreqVectors(int32_t docNumber);
150
152 String getSegmentName();
153
155 SegmentInfoPtr getSegmentInfo();
156 void setSegmentInfo(const SegmentInfoPtr& info);
157
158 void startCommit();
159 void rollbackCommit();
160
162 virtual DirectoryPtr directory();
163
166 virtual LuceneObjectPtr getFieldCacheKey();
167 virtual LuceneObjectPtr getDeletesCacheKey();
168
170 virtual int64_t getUniqueTermCount();
171
172 static SegmentReaderPtr getOnlySegmentReader(const DirectoryPtr& dir);
173 static SegmentReaderPtr getOnlySegmentReader(const IndexReaderPtr& reader);
174
175 virtual int32_t getTermInfosIndexDivisor();
176
177 protected:
178 bool checkDeletedCounts();
179 void loadDeletedDocs();
180
184 virtual ByteArray cloneNormBytes(ByteArray bytes);
185
189 virtual BitVectorPtr cloneDeletedDocs(const BitVectorPtr& bv);
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
Lucene::IndexWriter
An IndexWriter creates and maintains an index.
Definition: IndexWriter.h:90
Lucene::IndexReader::termPositions
virtual TermPositionsPtr termPositions()=0
Returns an unpositioned TermPositions enumerator.
Lucene::TermPtr
boost::shared_ptr< Term > TermPtr
Definition: LuceneTypes.h:233
Lucene::LuceneObjectPtr
boost::shared_ptr< LuceneObject > LuceneObjectPtr
Definition: LuceneTypes.h:539
Lucene::SegmentReader::_norms
MapStringNorm _norms
Definition: SegmentReader.h:40
Lucene::SegmentReaderRefPtr
boost::shared_ptr< SegmentReaderRef > SegmentReaderRefPtr
Definition: LuceneTypes.h:216
Lucene::TermDocsPtr
boost::shared_ptr< TermDocs > TermDocsPtr
Definition: LuceneTypes.h:236
Lucene::TermEnumPtr
boost::shared_ptr< TermEnum > TermEnumPtr
Definition: LuceneTypes.h:235
Lucene::FieldSelectorPtr
boost::shared_ptr< FieldSelector > FieldSelectorPtr
Definition: LuceneTypes.h:77
CloseableThreadLocal.h
Lucene::SegmentReader::deletedDocsRef
SegmentReaderRefPtr deletedDocsRef
Definition: SegmentReader.h:27
Lucene::SegmentInfoPtr
boost::shared_ptr< SegmentInfo > SegmentInfoPtr
Definition: LuceneTypes.h:208
Lucene::BitVectorPtr
boost::shared_ptr< BitVector > BitVectorPtr
Definition: LuceneTypes.h:523
Lucene::CoreReadersPtr
boost::shared_ptr< CoreReaders > CoreReadersPtr
Definition: LuceneTypes.h:100
IndexReader.h
Lucene::DocumentPtr
boost::shared_ptr< Document > DocumentPtr
Definition: LuceneTypes.h:74
Lucene::HashSet< String >
Lucene::IndexReader::FieldOption
FieldOption
Constants describing field properties, for example used for IndexReader#getFieldNames(FieldOption).
Definition: IndexReader.h:48
Lucene::IndexReaderPtr
boost::shared_ptr< IndexReader > IndexReaderPtr
Definition: LuceneTypes.h:157
Lucene::DirectoryPtr
boost::shared_ptr< Directory > DirectoryPtr
Definition: LuceneTypes.h:489
Lucene::TermVectorMapperPtr
boost::shared_ptr< TermVectorMapper > TermVectorMapperPtr
Definition: LuceneTypes.h:254
Lucene::TermPositionsPtr
boost::shared_ptr< TermPositions > TermPositionsPtr
Definition: LuceneTypes.h:243
Lucene::IndexInputPtr
boost::shared_ptr< IndexInput > IndexInputPtr
Definition: LuceneTypes.h:493
LUCENE_CLASS
#define LUCENE_CLASS(Name)
Definition: LuceneObject.h:24
Lucene
Definition: AbstractAllTermDocs.h:12
Lucene::SegmentReaderPtr
boost::shared_ptr< SegmentReader > SegmentReaderPtr
Definition: LuceneTypes.h:215
Lucene::SegmentReader::termVectorsLocal
CloseableThreadLocal< TermVectorsReader > termVectorsLocal
Definition: SegmentReader.h:31
Lucene::TermVectorsReaderPtr
boost::shared_ptr< TermVectorsReader > TermVectorsReaderPtr
Definition: LuceneTypes.h:256
Lucene::Collection
Utility template class to handle collections that can be safely copied and shared.
Definition: Collection.h:17
Lucene::FieldsReaderLocalPtr
boost::shared_ptr< FieldsReaderLocal > FieldsReaderLocalPtr
Definition: LuceneTypes.h:132
Lucene::SegmentReader::rollbackSegmentInfo
SegmentInfoPtr rollbackSegmentInfo
Definition: SegmentReader.h:30
Lucene::CloseableThreadLocal
General purpose thread-local map.
Definition: CloseableThreadLocal.h:16
Lucene::IndexReader::document
virtual DocumentPtr document(int32_t n)
Returns the stored fields of the n&#39;th Document in this index.
Lucene::IndexReader
IndexReader is an abstract class, providing an interface for accessing an index. Search of an index i...
Definition: IndexReader.h:39
Lucene::FieldsReaderPtr
boost::shared_ptr< FieldsReader > FieldsReaderPtr
Definition: LuceneTypes.h:131
Lucene::SegmentReader::core
CoreReadersPtr core
Definition: SegmentReader.h:28
Lucene::SegmentReader::fieldsReaderLocal
FieldsReaderLocalPtr fieldsReaderLocal
Definition: SegmentReader.h:29
Lucene::SegmentReader
Definition: SegmentReader.h:15
Lucene::TermFreqVectorPtr
boost::shared_ptr< TermFreqVector > TermFreqVectorPtr
Definition: LuceneTypes.h:237
Lucene::FieldInfosPtr
boost::shared_ptr< FieldInfos > FieldInfosPtr
Definition: LuceneTypes.h:127

clucene.sourceforge.net