19 using Lucene.Net.Documents;
20 using Lucene.Net.Support;
27 namespace Lucene.Net.Index
40 public const int FORMAT_PRE = - 1;
43 public const int FORMAT_START = - 2;
45 internal static readonly
int CURRENT_FORMAT = FORMAT_START;
47 internal const byte IS_INDEXED = (0x1);
48 internal const byte STORE_TERMVECTOR = (0x2);
49 internal const byte STORE_POSITIONS_WITH_TERMVECTOR =(0x4);
50 internal const byte STORE_OFFSET_WITH_TERMVECTOR = (0x8);
51 internal const byte OMIT_NORMS = (0x10);
52 internal const byte STORE_PAYLOADS = (0x20);
53 internal const byte OMIT_TERM_FREQ_AND_POSITIONS = (0x40);
55 private readonly System.Collections.Generic.List<
FieldInfo> byNumber =
new System.Collections.Generic.List<
FieldInfo>();
56 private readonly HashMap<string, FieldInfo> byName =
new HashMap<string, FieldInfo>();
80 catch (System.IO.IOException)
82 if (format == FORMAT_PRE)
88 input.SetModifiedUTF8StringsMode();
123 public Object Clone()
128 int numField = byNumber.Count;
129 for (
int i = 0; i < numField; i++)
132 fis.byNumber.Add(fi);
133 fis.byName[fi.name] = fi;
155 internal bool HasProx()
157 int numFields = byNumber.Count;
158 for (
int i = 0; i < numFields; i++)
161 if (fi.isIndexed && !fi.omitTermFreqAndPositions)
180 public void AddIndexed(System.Collections.Generic.ICollection<
string> names,
bool storeTermVectors,
bool storePositionWithTermVector,
bool storeOffsetWithTermVector)
184 foreach(
string name
in names)
186 Add(name,
true, storeTermVectors, storePositionWithTermVector, storeOffsetWithTermVector);
201 public void Add(System.Collections.Generic.ICollection<
string> names,
bool isIndexed)
205 foreach(
string name
in names)
207 Add(name, isIndexed);
221 public void Add(String name,
bool isIndexed)
225 Add(name, isIndexed,
false,
false,
false,
false);
238 public void Add(System.String name,
bool isIndexed,
bool storeTermVector)
242 Add(name, isIndexed, storeTermVector,
false,
false,
false);
262 public void Add(System.String name,
bool isIndexed,
bool storeTermVector,
bool storePositionWithTermVector,
bool storeOffsetWithTermVector)
267 Add(name, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector,
false);
289 public void Add(System.String name,
bool isIndexed,
bool storeTermVector,
bool storePositionWithTermVector,
bool storeOffsetWithTermVector,
bool omitNorms)
293 Add(name, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms,
false,
false);
319 public FieldInfo Add(System.String name,
bool isIndexed,
bool storeTermVector,
bool storePositionWithTermVector,
bool storeOffsetWithTermVector,
bool omitNorms,
bool storePayloads,
bool omitTermFreqAndPositions)
326 return AddInternal(name, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
330 fi.Update(isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
336 private FieldInfo AddInternal(String name,
bool isIndexed,
bool storeTermVector,
bool storePositionWithTermVector,
bool storeOffsetWithTermVector,
bool omitNorms,
bool storePayloads,
bool omitTermFreqAndPositions)
339 var fi =
new FieldInfo(name, isIndexed, byNumber.Count, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
345 public int FieldNumber(System.String fieldName)
348 return (fi != null)?fi.number:- 1;
353 return byName[fieldName];
364 public System.String FieldName(
int fieldNumber)
367 return (fi != null) ? fi.name :
"";
378 return (fieldNumber >= 0) ? byNumber[fieldNumber] : null;
383 return byNumber.Count;
386 public bool HasVectors()
388 bool hasVectors =
false;
389 for (
int i = 0; i < Size(); i++)
415 output.WriteVInt(CURRENT_FORMAT);
416 output.WriteVInt(Size());
417 for (
int i = 0; i < Size(); i++)
420 var bits = (byte) (0x0);
423 if (fi.storeTermVector)
424 bits |= STORE_TERMVECTOR;
425 if (fi.storePositionWithTermVector)
426 bits |= STORE_POSITIONS_WITH_TERMVECTOR;
427 if (fi.storeOffsetWithTermVector)
428 bits |= STORE_OFFSET_WITH_TERMVECTOR;
431 if (fi.storePayloads)
432 bits |= STORE_PAYLOADS;
433 if (fi.omitTermFreqAndPositions)
434 bits |= OMIT_TERM_FREQ_AND_POSITIONS;
436 output.WriteString(fi.name);
437 output.WriteByte(bits);
441 private void Read(
IndexInput input, String fileName)
443 int firstInt = input.ReadVInt();
455 if (format != FORMAT_PRE & format != FORMAT_START)
461 if (format == FORMAT_PRE)
467 size = input.ReadVInt();
470 for (
int i = 0; i < size; i++)
473 byte bits = input.ReadByte();
474 bool isIndexed = (bits & IS_INDEXED) != 0;
475 bool storeTermVector = (bits & STORE_TERMVECTOR) != 0;
476 bool storePositionsWithTermVector = (bits & STORE_POSITIONS_WITH_TERMVECTOR) != 0;
477 bool storeOffsetWithTermVector = (bits & STORE_OFFSET_WITH_TERMVECTOR) != 0;
478 bool omitNorms = (bits & OMIT_NORMS) != 0;
479 bool storePayloads = (bits & STORE_PAYLOADS) != 0;
480 bool omitTermFreqAndPositions = (bits & OMIT_TERM_FREQ_AND_POSITIONS) != 0;
482 AddInternal(name, isIndexed, storeTermVector, storePositionsWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
485 if (input.FilePointer != input.Length())
487 throw new CorruptIndexException(
"did not read all bytes from file \"" + fileName +
"\": read " + input.FilePointer +
" vs size " + input.Length());