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


 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
DirectoryReader.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 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 public:
23 
25  DirectoryReader(const IndexWriterPtr& writer, const SegmentInfosPtr& infos, int32_t termInfosIndexDivisor);
26 
28  DirectoryReader(const DirectoryPtr& directory, const SegmentInfosPtr& infos, Collection<SegmentReaderPtr> oldReaders,
29  Collection<int32_t> oldStarts, MapStringByteArray oldNormsCache, bool readOnly,
30  bool doClone, int32_t termInfosIndexDivisor);
31 
32  virtual ~DirectoryReader();
33 
35 
36 protected:
38  bool readOnly;
45  bool stale;
47 
49 
51  Collection<int32_t> starts; // 1st docno for each segment
52  MapStringByteArray normsCache;
53  int32_t _maxDoc;
54  int32_t _numDocs;
56 
57  // Max version in index as of when we opened; this can be > our current segmentInfos version
58  // in case we were opened on a past IndexCommit
59  int64_t maxIndexVersion;
60 
61 public:
63 
64  static IndexReaderPtr open(const DirectoryPtr& directory, const IndexDeletionPolicyPtr& deletionPolicy, const IndexCommitPtr& commit, bool readOnly, int32_t termInfosIndexDivisor);
65 
66  virtual LuceneObjectPtr clone(const LuceneObjectPtr& other = LuceneObjectPtr());
67  virtual LuceneObjectPtr clone(bool openReadOnly, const LuceneObjectPtr& other = LuceneObjectPtr());
68 
69  virtual IndexReaderPtr reopen();
70  virtual IndexReaderPtr reopen(bool openReadOnly);
72 
74  virtual int64_t getVersion();
75 
77  virtual Collection<TermFreqVectorPtr> getTermFreqVectors(int32_t docNumber);
78 
80  virtual TermFreqVectorPtr getTermFreqVector(int32_t docNumber, const String& field);
81 
83  virtual void getTermFreqVector(int32_t docNumber, const String& field, const TermVectorMapperPtr& mapper);
84 
86  virtual void getTermFreqVector(int32_t docNumber, const TermVectorMapperPtr& mapper);
87 
90  virtual bool isOptimized();
91 
93  virtual int32_t numDocs();
94 
96  virtual int32_t maxDoc();
97 
99  virtual DocumentPtr document(int32_t n, const FieldSelectorPtr& fieldSelector);
100 
102  virtual bool isDeleted(int32_t n);
103 
105  virtual bool hasDeletions();
106 
108  static int32_t readerIndex(int32_t n, Collection<int32_t> starts, int32_t numSubReaders);
109 
111  virtual bool hasNorms(const String& field);
112 
114  virtual ByteArray norms(const String& field);
115 
117  virtual void norms(const String& field, ByteArray norms, int32_t offset);
118 
120  virtual TermEnumPtr terms();
121 
123  virtual TermEnumPtr terms(const TermPtr& t);
124 
126  virtual int32_t docFreq(const TermPtr& t);
127 
129  virtual TermDocsPtr termDocs();
130 
133 
136  virtual void acquireWriteLock();
137 
138  void startCommit();
139  void rollbackCommit();
140 
142  virtual MapStringString getCommitUserData();
143 
145  virtual bool isCurrent();
146 
149  virtual HashSet<String> getFieldNames(FieldOption fieldOption);
150 
152 
155 
157  virtual DirectoryPtr directory();
158 
159  virtual int32_t getTermInfosIndexDivisor();
160 
162  virtual IndexCommitPtr getIndexCommit();
163 
166 
167 protected:
168  IndexReaderPtr doReopenFromWriter(bool openReadOnly, const IndexCommitPtr& commit);
169  IndexReaderPtr doReopen(bool openReadOnly, const IndexCommitPtr& commit);
170  IndexReaderPtr doReopenNoWriter(bool openReadOnly, const IndexCommitPtr& commit);
171  DirectoryReaderPtr doReopen(const SegmentInfosPtr& infos, bool doClone, bool openReadOnly);
172 
174  virtual void doDelete(int32_t docNum);
175 
177  virtual void doUndeleteAll();
178 
179  int32_t readerIndex(int32_t n);
180 
182  virtual void doSetNorm(int32_t doc, const String& field, uint8_t value);
183 
187  virtual void doCommit(MapStringString commitUserData);
188 
190  virtual void doClose();
191 
192  friend class FindSegmentsReopen;
193 };
194 
195 class MultiTermEnum : public TermEnum {
196 public:
197  MultiTermEnum(const IndexReaderPtr& topReader, Collection<IndexReaderPtr> readers, Collection<int32_t> starts, const TermPtr& t);
198  virtual ~MultiTermEnum();
199 
201 
202 protected:
205  int32_t _docFreq;
206 
207 public:
209  Collection<SegmentMergeInfoPtr> matchingSegments; // null terminated array of matching segments
210 
211 public:
213  virtual bool next();
214 
216  virtual TermPtr term();
217 
219  virtual int32_t docFreq();
220 
222  virtual void close();
223 };
224 
225 class MultiTermDocs : public TermPositions, public LuceneObject {
226 public:
228  virtual ~MultiTermDocs();
229 
231 
232 protected:
233  IndexReaderWeakPtr _topReader; // used for matching TermEnum to TermDocs
237 
238  int32_t base;
239  int32_t pointer;
240 
243  MultiTermEnumPtr tenum; // the term enum used for seeking
244  int32_t matchingSegmentPos; // position into the matching segments from tenum
245  SegmentMergeInfoPtr smi; // current segment mere info
246 
247 public:
249  virtual int32_t doc();
250 
252  virtual int32_t freq();
253 
255  virtual void seek(const TermPtr& term);
256 
258  virtual void seek(const TermEnumPtr& termEnum);
259 
261  virtual bool next();
262 
265  virtual int32_t read(Collection<int32_t> docs, Collection<int32_t> freqs);
266 
268  virtual bool skipTo(int32_t target);
269 
271  virtual void close();
272 
273 protected:
274  virtual TermDocsPtr termDocs(int32_t i);
275  virtual TermDocsPtr termDocs(const IndexReaderPtr& reader);
276 };
277 
279 public:
281  virtual ~MultiTermPositions();
282 
284 
285 public:
287  virtual int32_t nextPosition();
288 
290  virtual int32_t getPayloadLength();
291 
293  virtual ByteArray getPayload(ByteArray data, int32_t offset);
294 
296  virtual bool isPayloadAvailable();
297 
298 protected:
299  virtual TermDocsPtr termDocs(const IndexReaderPtr& reader);
300 };
301 
302 class ReaderCommit : public IndexCommit {
303 public:
304  ReaderCommit(const SegmentInfosPtr& infos, const DirectoryPtr& dir);
305  virtual ~ReaderCommit();
306 
308 
309 protected:
310  String segmentsFileName;
313  int64_t generation;
314  int64_t version;
316  MapStringString userData;
317 
318 public:
319  virtual String toString();
320 
322  virtual bool isOptimized();
323 
325  virtual String getSegmentsFileName();
326 
328  virtual HashSet<String> getFileNames();
329 
331  virtual DirectoryPtr getDirectory();
332 
334  virtual int64_t getVersion();
335 
337  virtual int64_t getGeneration();
338 
339  virtual bool isDeleted();
340 
342  virtual MapStringString getUserData();
343 
344  virtual void deleteCommit();
345 };
346 
347 }
348 
349 #endif

clucene.sourceforge.net