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

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
DirectoryReader.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2011 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 DIRECTORYREADER_H
8 #define DIRECTORYREADER_H
9
10 #include "IndexReader.h"
11 #include "TermEnum.h"
12 #include "TermPositions.h"
13 #include "IndexCommit.h"
14 #include "SegmentMergeQueue.h"
15
16 namespace Lucene
17 {
19 class DirectoryReader : public IndexReader
20 {
21 public:
23 DirectoryReader(DirectoryPtr directory, SegmentInfosPtr sis, IndexDeletionPolicyPtr deletionPolicy, bool readOnly, int32_t termInfosIndexDivisor);
24
26 DirectoryReader(IndexWriterPtr writer, SegmentInfosPtr infos, int32_t termInfosIndexDivisor);
27
29 DirectoryReader(DirectoryPtr directory, SegmentInfosPtr infos, Collection<SegmentReaderPtr> oldReaders,
30 Collection<int32_t> oldStarts, MapStringByteArray oldNormsCache, bool readOnly,
31 bool doClone, int32_t termInfosIndexDivisor);
32
33 virtual ~DirectoryReader();
34
35 LUCENE_CLASS(DirectoryReader);
36
37 protected:
38 DirectoryPtr _directory;
39 bool readOnly;
40 IndexWriterWeakPtr _writer;
41 IndexDeletionPolicyPtr deletionPolicy;
42 HashSet<String> synced;
43 LockPtr writeLock;
44 SegmentInfosPtr segmentInfos;
45 SegmentInfosPtr segmentInfosStart;
46 bool stale;
47 int32_t termInfosIndexDivisor;
48
49 bool rollbackHasChanges;
50
51 Collection<SegmentReaderPtr> subReaders;
52 Collection<int32_t> starts; // 1st docno for each segment
53 MapStringByteArray normsCache;
54 int32_t _maxDoc;
55 int32_t _numDocs;
56 bool _hasDeletions;
57
58 // Max version in index as of when we opened; this can be > our current segmentInfos version
59 // in case we were opened on a past IndexCommit
60 int64_t maxIndexVersion;
61
62 public:
63 void _initialize(Collection<SegmentReaderPtr> subReaders);
64
65 static IndexReaderPtr open(DirectoryPtr directory, IndexDeletionPolicyPtr deletionPolicy, IndexCommitPtr commit, bool readOnly, int32_t termInfosIndexDivisor);
66
67 virtual LuceneObjectPtr clone(LuceneObjectPtr other = LuceneObjectPtr());
68 virtual LuceneObjectPtr clone(bool openReadOnly, LuceneObjectPtr other = LuceneObjectPtr());
69
70 virtual IndexReaderPtr reopen();
71 virtual IndexReaderPtr reopen(bool openReadOnly);
72 virtual IndexReaderPtr reopen(IndexCommitPtr commit);
73
75 virtual int64_t getVersion();
76
78 virtual Collection<TermFreqVectorPtr> getTermFreqVectors(int32_t docNumber);
79
81 virtual TermFreqVectorPtr getTermFreqVector(int32_t docNumber, const String& field);
82
84 virtual void getTermFreqVector(int32_t docNumber, const String& field, TermVectorMapperPtr mapper);
85
87 virtual void getTermFreqVector(int32_t docNumber, TermVectorMapperPtr mapper);
88
91 virtual bool isOptimized();
92
94 virtual int32_t numDocs();
95
97 virtual int32_t maxDoc();
98
100 virtual DocumentPtr document(int32_t n, FieldSelectorPtr fieldSelector);
101
103 virtual bool isDeleted(int32_t n);
104
106 virtual bool hasDeletions();
107
109 static int32_t readerIndex(int32_t n, Collection<int32_t> starts, int32_t numSubReaders);
110
112 virtual bool hasNorms(const String& field);
113
115 virtual ByteArray norms(const String& field);
116
118 virtual void norms(const String& field, ByteArray norms, int32_t offset);
119
121 virtual TermEnumPtr terms();
122
124 virtual TermEnumPtr terms(TermPtr t);
125
127 virtual int32_t docFreq(TermPtr t);
128
130 virtual TermDocsPtr termDocs();
131
133 virtual TermPositionsPtr termPositions();
134
137 virtual void acquireWriteLock();
138
139 void startCommit();
140 void rollbackCommit();
141
143 virtual MapStringString getCommitUserData();
144
146 virtual bool isCurrent();
147
150 virtual HashSet<String> getFieldNames(FieldOption fieldOption);
151
152 static HashSet<String> getFieldNames(FieldOption fieldOption, Collection<IndexReaderPtr> subReaders);
153
155 virtual Collection<IndexReaderPtr> getSequentialSubReaders();
156
158 virtual DirectoryPtr directory();
159
160 virtual int32_t getTermInfosIndexDivisor();
161
163 virtual IndexCommitPtr getIndexCommit();
164
166 static Collection<IndexCommitPtr> listCommits(DirectoryPtr dir);
167
168 protected:
169 IndexReaderPtr doReopenFromWriter(bool openReadOnly, IndexCommitPtr commit);
170 IndexReaderPtr doReopen(bool openReadOnly, IndexCommitPtr commit);
171 IndexReaderPtr doReopenNoWriter(bool openReadOnly, IndexCommitPtr commit);
172 DirectoryReaderPtr doReopen(SegmentInfosPtr infos, bool doClone, bool openReadOnly);
173
175 virtual void doDelete(int32_t docNum);
176
178 virtual void doUndeleteAll();
179
180 int32_t readerIndex(int32_t n);
181
183 virtual void doSetNorm(int32_t doc, const String& field, uint8_t value);
184
188 virtual void doCommit(MapStringString commitUserData);
189
191 virtual void doClose();
192
193 friend class FindSegmentsReopen;
194 };
195
196 class MultiTermEnum : public TermEnum
197 {
198 public:
199 MultiTermEnum(IndexReaderPtr topReader, Collection<IndexReaderPtr> readers, Collection<int32_t> starts, TermPtr t);
200 virtual ~MultiTermEnum();
201
202 LUCENE_CLASS(MultiTermEnum);
203
204 protected:
205 SegmentMergeQueuePtr queue;
206 TermPtr _term;
207 int32_t _docFreq;
208
209 public:
210 IndexReaderWeakPtr _topReader;
211 Collection<SegmentMergeInfoPtr> matchingSegments; // null terminated array of matching segments
212
213 public:
215 virtual bool next();
216
218 virtual TermPtr term();
219
221 virtual int32_t docFreq();
222
224 virtual void close();
225 };
226
227 class MultiTermDocs : public TermPositions, public LuceneObject
228 {
229 public:
230 MultiTermDocs(IndexReaderPtr topReader, Collection<IndexReaderPtr> r, Collection<int32_t> s);
231 virtual ~MultiTermDocs();
232
233 LUCENE_CLASS(MultiTermDocs);
234
235 protected:
236 IndexReaderWeakPtr _topReader; // used for matching TermEnum to TermDocs
237 Collection<IndexReaderPtr> readers;
238 Collection<int32_t> starts;
239 TermPtr term;
240
241 int32_t base;
242 int32_t pointer;
243
244 Collection<TermDocsPtr> readerTermDocs;
245 TermDocsPtr current;
246 MultiTermEnumPtr tenum; // the term enum used for seeking
247 int32_t matchingSegmentPos; // position into the matching segments from tenum
248 SegmentMergeInfoPtr smi; // current segment mere info
249
250 public:
252 virtual int32_t doc();
253
255 virtual int32_t freq();
256
258 virtual void seek(TermPtr term);
259
261 virtual void seek(TermEnumPtr termEnum);
262
264 virtual bool next();
265
268 virtual int32_t read(Collection<int32_t> docs, Collection<int32_t> freqs);
269
271 virtual bool skipTo(int32_t target);
272
274 virtual void close();
275
276 protected:
277 virtual TermDocsPtr termDocs(int32_t i);
278 virtual TermDocsPtr termDocs(IndexReaderPtr reader);
279 };
280
281 class MultiTermPositions : public MultiTermDocs
282 {
283 public:
284 MultiTermPositions(IndexReaderPtr topReader, Collection<IndexReaderPtr> r, Collection<int32_t> s);
285 virtual ~MultiTermPositions();
286
287 LUCENE_CLASS(MultiTermPositions);
288
289 public:
291 virtual int32_t nextPosition();
292
294 virtual int32_t getPayloadLength();
295
297 virtual ByteArray getPayload(ByteArray data, int32_t offset);
298
300 virtual bool isPayloadAvailable();
301
302 protected:
303 virtual TermDocsPtr termDocs(IndexReaderPtr reader);
304 };
305
306 class ReaderCommit : public IndexCommit
307 {
308 public:
309 ReaderCommit(SegmentInfosPtr infos, DirectoryPtr dir);
310 virtual ~ReaderCommit();
311
312 LUCENE_CLASS(ReaderCommit);
313
314 protected:
315 String segmentsFileName;
316 HashSet<String> files;
317 DirectoryPtr dir;
318 int64_t generation;
319 int64_t version;
320 bool _isOptimized;
321 MapStringString userData;
322
323 public:
324 virtual String toString();
325
327 virtual bool isOptimized();
328
330 virtual String getSegmentsFileName();
331
333 virtual HashSet<String> getFileNames();
334
336 virtual DirectoryPtr getDirectory();
337
339 virtual int64_t getVersion();
340
342 virtual int64_t getGeneration();
343
344 virtual bool isDeleted();
345
347 virtual MapStringString getUserData();
348
349 virtual void deleteCommit();
350 };
351 }
352
353 #endif

clucene.sourceforge.net