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


 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SegmentInfo.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 SEGMENTINFO_H
8 #define SEGMENTINFO_H
9 
10 #include "LuceneObject.h"
11 
12 namespace Lucene
13 {
16  class LPPAPI SegmentInfo : public LuceneObject
17  {
18  public:
19  SegmentInfo(const String& name, int32_t docCount, DirectoryPtr dir);
20 
21  SegmentInfo(const String& name, int32_t docCount, DirectoryPtr dir, bool isCompoundFile, bool hasSingleNormFile);
22 
23  SegmentInfo(const String& name, int32_t docCount, DirectoryPtr dir, bool isCompoundFile,
24  bool hasSingleNormFile, int32_t docStoreOffset, const String& docStoreSegment,
25  bool docStoreIsCompoundFile, bool hasProx);
26 
31  SegmentInfo(DirectoryPtr dir, int32_t format, IndexInputPtr input);
32 
33  virtual ~SegmentInfo();
34 
36 
37  public:
38  static const int32_t NO; // no norms; no deletes;
39  static const int32_t YES; // have norms; have deletes;
40  static const int32_t CHECK_DIR; // must check dir to see if there are norms/deletions
41  static const int32_t WITHOUT_GEN; // a file name that has no GEN in it.
42 
43  protected:
44  // true if this is a segments file written before lock-less commits (2.1)
46 
47  // current generation of del file; NO if there are no deletes; CHECK_DIR if it's a pre-2.1 segment
48  // (and we must check filesystem); YES or higher if there are deletes at generation N
49  int64_t delGen;
50 
51  // current generation of each field's norm file. If this array is null, for lockLess this means no
52  // separate norms. For preLockLess this means we must check filesystem. If this array is not null,
53  // its values mean: NO says this field has no separate norms; CHECK_DIR says it is a preLockLess
54  // segment and filesystem must be checked; >= YES says this field has separate norms with the
55  // specified generation
57 
58  // NO if it is not; YES if it is; CHECK_DIR if it's pre-2.1 (ie, must check file system to see if
59  // <name>.cfs and <name>.nrm exist)
60  uint8_t isCompoundFile;
61 
62  // true if this segment maintains norms in a single file; false otherwise this is currently false for
63  // segments populated by DocumentWriter and true for newly created merged segments (both compound and
64  // non compound).
66 
67  // cached list of files that this segment uses in the Directory
69 
70  // total byte size of all of our files (computed on demand)
71  int64_t _sizeInBytes;
72 
73  // if this segment shares stored fields & vectors, this offset is where in that file this segment's
74  // docs begin
75  int32_t docStoreOffset;
76 
77  // name used to derive fields/vectors file we share with other segments
79 
80  // whether doc store files are stored in compound file (*.cfx)
82 
83  // How many deleted docs in this segment, or -1 if not yet known (if it's an older index)
84  int32_t delCount;
85 
86  // True if this segment has any fields with omitTermFreqAndPositions == false
87  bool hasProx;
88 
89  MapStringString diagnostics;
90 
91  public:
92  String name; // unique name in dir
93  int32_t docCount; // number of docs in seg
94  DirectoryPtr dir; // where segment resides
95 
96  public:
98  void reset(SegmentInfoPtr src);
99 
100  void setDiagnostics(MapStringString diagnostics);
101  MapStringString getDiagnostics();
102 
103  void setNumFields(int32_t numFields);
104 
106  int64_t sizeInBytes();
107 
108  bool hasDeletions();
109  void advanceDelGen();
110  void clearDelGen();
111 
112  virtual LuceneObjectPtr clone(LuceneObjectPtr other = LuceneObjectPtr());
113 
114  String getDelFileName();
115 
118  bool hasSeparateNorms(int32_t fieldNumber);
119 
121  bool hasSeparateNorms();
122 
125  void advanceNormGen(int32_t fieldIndex);
126 
129  String getNormFileName(int32_t number);
130 
133  void setUseCompoundFile(bool isCompoundFile);
134 
136  bool getUseCompoundFile();
137 
138  int32_t getDelCount();
139  void setDelCount(int32_t delCount);
140  int32_t getDocStoreOffset();
141  bool getDocStoreIsCompoundFile();
142  void setDocStoreIsCompoundFile(bool v);
143  String getDocStoreSegment();
144  void setDocStoreOffset(int32_t offset);
145  void setDocStore(int32_t offset, const String& segment, bool isCompoundFile);
146 
148  void write(IndexOutputPtr output);
149 
150  void setHasProx(bool hasProx);
151  bool getHasProx();
152 
155  HashSet<String> files();
156 
158  String segString(DirectoryPtr dir);
159 
161  virtual bool equals(LuceneObjectPtr other);
162 
163  virtual int32_t hashCode();
164 
165  protected:
166  void addIfExists(HashSet<String> files, const String& fileName);
167 
169  void clearFiles();
170  };
171 }
172 
173 #endif

clucene.sourceforge.net