CLucene - a full-featured, c++ search engine
API Documentation
00001 /*------------------------------------------------------------------------------ 00002 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00003 * 00004 * Distributable under the terms of either the Apache License (Version 2.0) or 00005 * the GNU Lesser General Public License, as specified in the COPYING file. 00006 ------------------------------------------------------------------------------*/ 00007 #ifndef _lucene_index_SegmentInfos_ 00008 #define _lucene_index_SegmentInfos_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "CLucene/util/VoidList.h" 00015 #include "CLucene/store/Directory.h" 00016 00017 CL_NS_DEF(index) 00018 00019 class SegmentInfo :LUCENE_BASE{ 00020 private: 00021 //Directory where the segment resides 00022 CL_NS(store)::Directory* dir; 00023 public: 00025 CL_NS(store)::Directory* getDir() const{ return dir; } 00026 00027 //Unique name in directory dir 00028 char name[CL_MAX_NAME]; 00029 //Number of docs in the segment 00030 const int32_t docCount; 00031 00032 SegmentInfo(const char* Name, const int32_t DocCount, CL_NS(store)::Directory* Dir); 00033 00034 ~SegmentInfo(); 00035 }; 00036 00037 typedef CL_NS(util)::CLVector<SegmentInfo*,CL_NS(util)::Deletor::Object<SegmentInfo> > segmentInfosType; 00038 //SegmentInfos manages a list of SegmentInfo instances 00039 //Each SegmentInfo contains information about a segment in a directory. 00040 // 00041 //The active segments in the index are stored in the segment info file. 00042 //An index only has a single file in this format, and it is named "segments". 00043 //This lists each segment by name, and also contains the size of each segment. 00044 //The format of the file segments is defined as follows: 00045 // 00046 // SegCount 00047 //Segments --> SegCount, <SegName, SegSize> 00048 // 00049 //SegCount, SegSize --> UInt32 00050 // 00051 //SegName --> String 00052 // 00053 //SegName is the name of the segment, and is used as the file name prefix 00054 //for all of the files that compose the segment's index. 00055 // 00056 //SegSize is the number of documents contained in the segment index. 00057 // 00058 //Note: 00059 //At http://jakarta.apache.org/lucene/docs/fileformats.html the definition 00060 //of all file formats can be found. Note that java lucene currently 00061 //defines Segments as follows: 00062 // 00063 //Segments --> Format, Version, SegCount, <SegName, SegSize>SegCount 00064 // 00065 //Format, SegCount, SegSize --> UInt32 00066 // 00067 //Format and Version have not been implemented yet 00068 class SegmentInfos: LUCENE_BASE { 00070 /* Works since counter, the old 1st entry, is always >= 0 */ 00071 LUCENE_STATIC_CONSTANT(int32_t,FORMAT=-1); 00072 00077 int64_t version; 00078 00079 segmentInfosType infos; 00080 00081 int32_t counter; // used to name new segments 00082 friend class IndexWriter; //allow IndexWriter to use counter 00083 public: 00084 SegmentInfos(bool deleteMembers=true); 00085 ~SegmentInfos(); 00086 00087 00088 //delete and clears objects 'from' from to 'to' 00089 void clearto(size_t to); 00090 00091 //count of segment infos 00092 int32_t size() const; 00093 //add a segment info 00094 void add(SegmentInfo* info); 00095 //Returns a reference to the i-th SegmentInfo in the list. 00096 SegmentInfo* info(int32_t i); 00097 00101 int64_t getVersion() { return version; } 00102 00103 static int64_t readCurrentVersion(CL_NS(store)::Directory* directory); 00104 00105 //Reads segments file that resides in directory 00106 void read(CL_NS(store)::Directory* directory); 00107 00108 //Writes a new segments file based upon the SegmentInfo instances it manages 00109 void write(CL_NS(store)::Directory* directory); 00110 }; 00111 CL_NS_END 00112 #endif