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_FieldInfos_ 00008 #define _lucene_index_FieldInfos_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "CLucene/store/Directory.h" 00015 #include "CLucene/document/Document.h" 00016 #include "CLucene/document/Field.h" 00017 #include "CLucene/util/VoidMap.h" 00018 #include "CLucene/util/VoidList.h" 00019 00020 CL_NS_DEF(index) 00021 00022 class FieldInfo :LUCENE_BASE{ 00023 public: 00024 //name of the field 00025 const TCHAR* name; 00026 00027 //Is field indexed? true = yes false = no 00028 bool isIndexed; 00029 00030 //field number 00031 const int32_t number; 00032 00033 // true if term vector for this field should be stored 00034 bool storeTermVector; 00035 bool storeOffsetWithTermVector; 00036 bool storePositionWithTermVector; 00037 00038 bool omitNorms; // omit norms associated with indexed fields 00039 00040 //Func - Constructor 00041 // Initialises FieldInfo. 00042 // na holds the name of the field 00043 // tk indicates whether this field is indexed or not 00044 // nu indicates its number 00045 //Pre - na != NULL and holds the name of the field 00046 // tk is true or false 00047 // number >= 0 00048 //Post - The FieldInfo instance has been created and initialized. 00049 // name holds the duplicated string of na 00050 // isIndexed = tk 00051 // number = nu 00052 FieldInfo(const TCHAR* fieldName, 00053 const bool isIndexed, 00054 const int32_t fieldNumber, 00055 const bool storeTermVector, 00056 const bool storeOffsetWithTermVector, 00057 const bool storePositionWithTermVector, 00058 const bool omitNorms); 00059 00060 //Func - Destructor 00061 //Pre - true 00062 //Post - The instance has been destroyed 00063 ~FieldInfo(); 00064 }; 00065 00072 class FieldInfos :LUCENE_BASE{ 00073 private: 00074 //we now use internd field names, so we can use the voidCompare 00075 //to directly compare the strings 00076 typedef CL_NS(util)::CLHashMap<const TCHAR*,FieldInfo*, 00077 CL_NS(util)::Compare::TChar,CL_NS(util)::Equals::TChar > defByName; 00078 defByName byName; 00079 00080 CL_NS(util)::CLArrayList<FieldInfo*,CL_NS(util)::Deletor::Object<FieldInfo> > byNumber; 00081 00082 public: 00083 enum{ 00084 IS_INDEXED = 0x1, 00085 STORE_TERMVECTOR = 0x2, 00086 STORE_POSITIONS_WITH_TERMVECTOR = 0x4, 00087 STORE_OFFSET_WITH_TERMVECTOR = 0x8, 00088 OMIT_NORMS = 0x10 00089 }; 00090 00091 FieldInfos(); 00092 ~FieldInfos(); 00093 00103 FieldInfos(CL_NS(store)::Directory* d, const char* name); 00104 00105 int32_t fieldNumber(const TCHAR* fieldName)const; 00106 00113 FieldInfo* fieldInfo(const TCHAR* fieldName) const; 00114 00122 const TCHAR* fieldName(const int32_t fieldNumber)const; 00123 00124 FieldInfo* fieldInfo(const int32_t fieldNumber) const; 00125 00126 int32_t size()const; 00127 00128 bool hasVectors() const; 00129 00130 // Adds field info for a Document. 00131 void add(const CL_NS(document)::Document* doc); 00132 00133 // Merges in information from another FieldInfos. 00134 void add(FieldInfos* other); 00135 00136 00148 void add(const TCHAR* name, const bool isIndexed, const bool storeTermVector=false, 00149 bool storePositionWithTermVector=false, bool storeOffsetWithTermVector=false, bool omitNorms=false); 00150 00159 void add(const TCHAR** names, const bool isIndexed, const bool storeTermVector=false, 00160 bool storePositionWithTermVector=false, bool storeOffsetWithTermVector=false, bool omitNorms=false); 00161 00162 void write(CL_NS(store)::Directory* d, const char* name) const; 00163 void write(CL_NS(store)::IndexOutput* output) const; 00164 00165 private: 00166 void read(CL_NS(store)::IndexInput* input); 00167 void addInternal( const TCHAR* name,const bool isIndexed, const bool storeTermVector, 00168 const bool storePositionWithTermVector, const bool storeOffsetWithTermVector, const bool omitNorms); 00169 00170 }; 00171 CL_NS_END 00172 #endif