88 NOT_ANALYZED_NO_NORMS,
133 WITH_POSITIONS_OFFSETS,
141 public override string StringValue
143 get {
return fieldsData is System.String ? (System.String) fieldsData : null; }
150 public override TextReader ReaderValue
152 get {
return fieldsData is System.IO.TextReader ? (System.IO.TextReader) fieldsData : null; }
160 get {
return tokenStream; }
176 public void SetValue(System.String value)
178 if (internalIsBinary)
180 throw new System.ArgumentException(
"cannot set a String value on a binary field");
186 public void SetValue(System.IO.TextReader value)
188 if (internalIsBinary)
190 throw new System.ArgumentException(
"cannot set a Reader value on a binary field");
192 if (internalIsStored)
194 throw new System.ArgumentException(
"cannot set a Reader value on a stored field");
200 public void SetValue(byte[] value)
202 if (!internalIsBinary)
204 throw new System.ArgumentException(
"cannot set a byte[] value on a non-binary field");
207 internalBinaryLength = value.Length;
208 internalbinaryOffset = 0;
212 public void SetValue(byte[] value,
int offset,
int length)
214 if (!internalIsBinary)
216 throw new System.ArgumentException(
"cannot set a byte[] value on a non-binary field");
219 internalBinaryLength = length;
220 internalbinaryOffset = offset;
228 this.internalIsIndexed =
true;
229 this.internalIsTokenized =
true;
230 this.tokenStream = tokenStream;
249 : this(name, value, store, index,
TermVector.NO)
276 : this(name, true, value, store, index, termVector)
307 throw new System.NullReferenceException(
"name cannot be null");
309 throw new System.NullReferenceException(
"value cannot be null");
310 if (name.Length == 0 && value.Length == 0)
311 throw new System.ArgumentException(
"name and value cannot both be empty");
313 throw new System.ArgumentException(
"it doesn't make sense to have a field that " +
"is neither indexed nor stored");
315 throw new System.ArgumentException(
"cannot store term vector information " +
"for a field that is not indexed");
321 this.internalName = name;
323 this.fieldsData = value;
325 this.internalIsStored = store.IsStored();
327 this.internalIsIndexed = index.IsIndexed();
328 this.internalIsTokenized = index.IsAnalyzed();
329 this.internalOmitNorms = index.OmitNorms();
331 if (index ==
Index.NO)
333 this.internalOmitTermFreqAndPositions =
false;
336 this.internalIsBinary =
false;
338 SetStoreTermVector(termVector);
352 public Field(System.String name, System.IO.TextReader reader):this(name, reader,
TermVector.NO)
372 throw new System.NullReferenceException(
"name cannot be null");
374 throw new System.NullReferenceException(
"reader cannot be null");
377 this.fieldsData = reader;
379 this.internalIsStored =
false;
381 this.internalIsIndexed =
true;
382 this.internalIsTokenized =
true;
384 this.internalIsBinary =
false;
386 SetStoreTermVector(termVector);
422 throw new System.NullReferenceException(
"name cannot be null");
423 if (tokenStream == null)
424 throw new System.NullReferenceException(
"tokenStream cannot be null");
427 this.fieldsData = null;
428 this.tokenStream = tokenStream;
430 this.internalIsStored =
false;
432 this.internalIsIndexed =
true;
433 this.internalIsTokenized =
true;
435 this.internalIsBinary =
false;
437 SetStoreTermVector(termVector);
451 public Field(System.String name, byte[] value_Renamed,
Store store):this(name, value_Renamed, 0, value_Renamed.Length, store)
469 public Field(System.String name, byte[] value_Renamed,
int offset,
int length,
Store store)
473 throw new System.ArgumentException(
"name cannot be null");
474 if (value_Renamed == null)
475 throw new System.ArgumentException(
"value cannot be null");
478 fieldsData = value_Renamed;
480 if (store ==
Store.NO)
481 throw new System.ArgumentException(
"binary values can't be unstored");
483 internalIsStored = store.IsStored();
484 internalIsIndexed =
false;
485 internalIsTokenized =
false;
486 internalOmitTermFreqAndPositions =
false;
487 internalOmitNorms =
true;
489 internalIsBinary =
true;
490 internalBinaryLength = length;
491 internalbinaryOffset = offset;
497 public static class FieldExtensions
499 public static bool IsStored(
this Field.Store store)
503 case Field.Store.YES:
508 throw new ArgumentOutOfRangeException(
"store",
"Invalid value for Field.Store");
512 public static bool IsIndexed(
this Field.Index index)
518 case Field.Index.ANALYZED:
519 case Field.Index.NOT_ANALYZED:
520 case Field.Index.NOT_ANALYZED_NO_NORMS:
521 case Field.Index.ANALYZED_NO_NORMS:
524 throw new ArgumentOutOfRangeException(
"index",
"Invalid value for Field.Index");
528 public static bool IsAnalyzed(
this Field.Index index)
533 case Field.Index.NOT_ANALYZED:
534 case Field.Index.NOT_ANALYZED_NO_NORMS:
536 case Field.Index.ANALYZED:
537 case Field.Index.ANALYZED_NO_NORMS:
540 throw new ArgumentOutOfRangeException(
"index",
"Invalid value for Field.Index");
544 public static bool OmitNorms(
this Field.Index index)
548 case Field.Index.ANALYZED:
549 case Field.Index.NOT_ANALYZED:
552 case Field.Index.NOT_ANALYZED_NO_NORMS:
553 case Field.Index.ANALYZED_NO_NORMS:
556 throw new ArgumentOutOfRangeException(
"index",
"Invalid value for Field.Index");
560 public static bool IsStored(
this Field.TermVector tv)
564 case Field.TermVector.NO:
566 case Field.TermVector.YES:
567 case Field.TermVector.WITH_OFFSETS:
568 case Field.TermVector.WITH_POSITIONS:
569 case Field.TermVector.WITH_POSITIONS_OFFSETS:
572 throw new ArgumentOutOfRangeException(
"tv",
"Invalid value for Field.TermVector");
576 public static bool WithPositions(
this Field.TermVector tv)
580 case Field.TermVector.NO:
581 case Field.TermVector.YES:
582 case Field.TermVector.WITH_OFFSETS:
584 case Field.TermVector.WITH_POSITIONS:
585 case Field.TermVector.WITH_POSITIONS_OFFSETS:
588 throw new ArgumentOutOfRangeException(
"tv",
"Invalid value for Field.TermVector");
592 public static bool WithOffsets(
this Field.TermVector tv)
596 case Field.TermVector.NO:
597 case Field.TermVector.YES:
598 case Field.TermVector.WITH_POSITIONS:
600 case Field.TermVector.WITH_OFFSETS:
601 case Field.TermVector.WITH_POSITIONS_OFFSETS:
604 throw new ArgumentOutOfRangeException(
"tv",
"Invalid value for Field.TermVector");
608 public static Field.Index ToIndex(
bool indexed,
bool analyed)
610 return ToIndex(indexed, analyed,
false);
613 public static Field.Index ToIndex(
bool indexed,
bool analyzed,
bool omitNorms)
619 return Field.Index.NO;
627 return Field.Index.ANALYZED;
629 return Field.Index.NOT_ANALYZED;
635 return Field.Index.ANALYZED_NO_NORMS;
637 return Field.Index.NOT_ANALYZED_NO_NORMS;
643 public static Field.TermVector ToTermVector(
bool stored,
bool withOffsets,
bool withPositions)
648 return Field.TermVector.NO;
655 return Field.TermVector.WITH_POSITIONS_OFFSETS;
657 return Field.TermVector.WITH_OFFSETS;
662 return Field.TermVector.WITH_POSITIONS;
664 return Field.TermVector.YES;