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_FieldInfos_
8
#define _lucene_index_FieldInfos_
10
#include "CLucene/store/Directory.h"
12
CL_CLASS_DEF(document,Document)
13
CL_CLASS_DEF(document,Field)
17
class FieldInfo :LUCENE_BASE{
22
//Is field indexed? true = yes false = no
28
// true if term vector for this field should be stored
30
bool storeOffsetWithTermVector;
31
bool storePositionWithTermVector;
33
bool omitNorms; // omit norms associated with indexed fields
35
bool storePayloads; // whether this field stores payloads together with term positions
38
// Initialises FieldInfo.
39
// na holds the name of the field
40
// tk indicates whether this field is indexed or not
41
// nu indicates its number
42
//Pre - na != NULL and holds the name of the field
43
// tk is true or false
45
//Post - The FieldInfo instance has been created and initialized.
46
// name holds the duplicated string of na
49
FieldInfo(const TCHAR* fieldName,
51
const int32_t fieldNumber,
52
const bool storeTermVector,
53
const bool storeOffsetWithTermVector,
54
const bool storePositionWithTermVector,
56
const bool storePayloads);
60
//Post - The instance has been destroyed
64
* @memory - caller is responsible for deleting the returned object
69
/** Access to the Field Info file that describes document fields and whether or
70
* not they are indexed. Each segment has a separate Field Info file. Objects
71
* of this class are thread-safe for multiple readers, but only one thread can
72
* be adding documents at a time, with no other reader or writer threads
73
* accessing this object.
75
class CLUCENE_EXPORT FieldInfos :LUCENE_BASE{
76
//we now use internd field names, so we can use the voidCompare
77
//to directly compare the strings
78
typedef CL_NS(util)::CLHashMap<const TCHAR*,FieldInfo*,
79
CL_NS(util)::Compare::TChar,CL_NS(util)::Equals::TChar > defByName;
82
CL_NS(util)::CLArrayList<FieldInfo*,CL_NS(util)::Deletor::Object<FieldInfo> > byNumber;
86
STORE_TERMVECTOR = 0x2,
87
STORE_POSITIONS_WITH_TERMVECTOR = 0x4,
88
STORE_OFFSET_WITH_TERMVECTOR = 0x8,
97
* Construct a FieldInfos object using the directory and the name of the file
99
* @param d The directory to open the IndexInput from
100
* @param name The name of the file to open the IndexInput from in the Directory
101
* @throws IOException
103
FieldInfos(CL_NS(store)::Directory* d, const char* name);
106
* Returns a deep clone of this FieldInfos instance.
107
* @memory caller is responisble for deleting returned object
111
/** Adds field info for a Document. */
112
void add(const CL_NS(document)::Document* doc);
115
* Add fields that are indexed. Whether they have termvectors has to be specified.
117
* @param names The names of the fields. An array of TCHARs, last item has to be NULL
118
* @param storeTermVectors Whether the fields store term vectors or not
119
* @param storePositionWithTermVector treu if positions should be stored.
120
* @param storeOffsetWithTermVector true if offsets should be stored
122
void addIndexed(const TCHAR** names, const bool storeTermVectors, const bool storePositionWithTermVector, const bool storeOffsetWithTermVector);
125
* Assumes the fields are not storing term vectors.
127
* @param names The names of the fields
128
* @param isIndexed Whether the fields are indexed or not
130
* @see #add(TCHAR*, bool)
132
void add(const TCHAR** names, const bool isIndexed, const bool storeTermVector=false,
133
const bool storePositionWithTermVector=false, const bool storeOffsetWithTermVector=false,
134
const bool omitNorms=false, const bool storePayloads=false);
136
// Merges in information from another FieldInfos.
137
void add(FieldInfos* other);
139
/** If the field is not yet known, adds it. If it is known, checks to make
140
* sure that the isIndexed flag is the same as was given previously for this
141
* field. If not - marks it as being indexed. Same goes for the TermVector
144
* @param name The name of the field
145
* @param isIndexed true if the field is indexed
146
* @param storeTermVector true if the term vector should be stored
147
* @param storePositionWithTermVector true if the term vector with positions should be stored
148
* @param storeOffsetWithTermVector true if the term vector with offsets should be stored
149
* @param omitNorms true if the norms for the indexed field should be omitted
150
* @param storePayloads true if payloads should be stored for this field
152
FieldInfo* add(const TCHAR* name, const bool isIndexed, const bool storeTermVector=false,
153
const bool storePositionWithTermVector=false, const bool storeOffsetWithTermVector=false, const bool omitNorms=false, const bool storePayloads=false);
156
FieldInfo* addInternal( const TCHAR* name,const bool isIndexed, const bool storeTermVector,
157
const bool storePositionWithTermVector, const bool storeOffsetWithTermVector, const bool omitNorms, const bool storePayloads);
159
int32_t fieldNumber(const TCHAR* fieldName)const;
162
* Return the fieldinfo object referenced by the fieldNumber.
164
* @return the FieldInfo object or null when the given fieldNumber
167
FieldInfo* fieldInfo(const TCHAR* fieldName) const;
170
* Return the fieldName identified by its number.
173
* @return the fieldName or an empty string when the field
174
* with the given number doesn't exist.
176
const TCHAR* fieldName(const int32_t fieldNumber)const;
179
* Return the fieldinfo object referenced by the fieldNumber.
181
* @return the FieldInfo object or null when the given fieldNumber
184
FieldInfo* fieldInfo(const int32_t fieldNumber) const;
187
bool hasVectors() const;
190
void write(CL_NS(store)::Directory* d, const char* name) const;
191
void write(CL_NS(store)::IndexOutput* output) const;
194
void read(CL_NS(store)::IndexInput* input);