1
/*------------------------------------------------------------------------------
2
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
4
* Distributable under the terms of either the Apache License (Version 2.0) or
5
* the GNU Lesser General Public License, as specified in the COPYING file.
6
------------------------------------------------------------------------------*/
7
#ifndef _lucene_index_SegmentInfos_
8
#define _lucene_index_SegmentInfos_
10
#if defined(_LUCENE_PRAGMA_ONCE)
14
#include "CLucene/util/VoidList.h"
15
#include "CLucene/store/Directory.h"
19
class SegmentInfo :LUCENE_BASE{
21
//Directory where the segment resides
22
CL_NS(store)::Directory* dir;
24
///Gets the Directory where the segment resides
25
CL_NS(store)::Directory* getDir() const{ return dir; }
27
//Unique name in directory dir
28
char name[CL_MAX_NAME];
29
//Number of docs in the segment
30
const int32_t docCount;
32
SegmentInfo(const char* Name, const int32_t DocCount, CL_NS(store)::Directory* Dir);
37
typedef CL_NS(util)::CLVector<SegmentInfo*,CL_NS(util)::Deletor::Object<SegmentInfo> > segmentInfosType;
38
//SegmentInfos manages a list of SegmentInfo instances
39
//Each SegmentInfo contains information about a segment in a directory.
41
//The active segments in the index are stored in the segment info file.
42
//An index only has a single file in this format, and it is named "segments".
43
//This lists each segment by name, and also contains the size of each segment.
44
//The format of the file segments is defined as follows:
47
//Segments --> SegCount, <SegName, SegSize>
49
//SegCount, SegSize --> UInt32
53
//SegName is the name of the segment, and is used as the file name prefix
54
//for all of the files that compose the segment's index.
56
//SegSize is the number of documents contained in the segment index.
59
//At http://jakarta.apache.org/lucene/docs/fileformats.html the definition
60
//of all file formats can be found. Note that java lucene currently
61
//defines Segments as follows:
63
//Segments --> Format, Version, SegCount, <SegName, SegSize>SegCount
65
//Format, SegCount, SegSize --> UInt32
67
//Format and Version have not been implemented yet
68
class SegmentInfos: LUCENE_BASE {
69
/** The file format version, a negative number. */
70
/* Works since counter, the old 1st entry, is always >= 0 */
71
LUCENE_STATIC_CONSTANT(int32_t,FORMAT=-1);
74
* counts how often the index has been changed by adding or deleting docs.
75
* starting with the current time in milliseconds forces to create unique version numbers.
79
segmentInfosType infos;
81
int32_t counter; // used to name new segments
82
friend class IndexWriter; //allow IndexWriter to use counter
84
SegmentInfos(bool deleteMembers=true);
88
//delete and clears objects 'from' from to 'to'
89
void clearto(size_t to);
91
//count of segment infos
94
void add(SegmentInfo* info);
95
//Returns a reference to the i-th SegmentInfo in the list.
96
SegmentInfo* info(int32_t i);
99
* version number when this SegmentInfos was generated.
101
int64_t getVersion() { return version; }
103
static int64_t readCurrentVersion(CL_NS(store)::Directory* directory);
105
//Reads segments file that resides in directory
106
void read(CL_NS(store)::Directory* directory);
108
//Writes a new segments file based upon the SegmentInfo instances it manages
109
void write(CL_NS(store)::Directory* directory);