Class DocumentExtensions
LUCENENET specific extensions to the Document class.
Inheritance
Inherited Members
Namespace: Lucene.Net.Documents.Extensions
Assembly: Lucene.Net.dll
Syntax
public static class DocumentExtensions
Methods
| Improve this Doc View SourceAddBinaryDocValuesField(Document, String, BytesRef)
Adds a new BinaryDocValuesField.
Declaration
public static BinaryDocValuesField AddBinaryDocValuesField(this Document document, string name, BytesRef value)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
BytesRef | value | binary content |
Returns
Type | Description |
---|---|
BinaryDocValuesField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field name is null |
AddDoubleDocValuesField(Document, String, Double)
Adds a new DoubleDocValuesField field with the specified 64-bit double value
Declaration
public static DoubleDocValuesField AddDoubleDocValuesField(this Document document, string name, double value)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Double | value | 64-bit double value |
Returns
Type | Description |
---|---|
DoubleDocValuesField | The field that was added to this Document. |
Remarks
Syntactic sugar for encoding doubles as NumericDocValues via J2N.BitConversion.DoubleToRawInt64Bits(System.Double).
Per-document double values can be retrieved via GetDoubles(AtomicReader, String, Boolean).
NOTE: In most all cases this will be rather inefficient, requiring eight bytes per document. Consider encoding double values yourself with only as much precision as you require.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field name is |
AddDoubleField(Document, String, Double, Field.Store)
Adds a stored or un-stored DoubleField with the provided value
and default precisionStep
PRECISION_STEP_DEFAULT (4).
Declaration
public static DoubleField AddDoubleField(this Document document, string name, double value, Field.Store stored)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Double | value | 64-bit System.Double value |
Field.Store | stored | YES if the content should also be stored |
Returns
Type | Description |
---|---|
DoubleField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field name is |
AddDoubleField(Document, String, Double, FieldType)
Adds a stored or un-stored DoubleField with the provided value.
Expert: allows you to customize the FieldType.
Declaration
public static DoubleField AddDoubleField(this Document document, string name, double value, FieldType type)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Double | value | 64-bit double value |
FieldType | type | customized field type: must have NumericType of DOUBLE. |
Returns
Type | Description |
---|---|
DoubleField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field name or type is |
AddInt32Field(Document, String, Int32, Field.Store)
Adds a stored or un-stored Int32Field with the provided value
and default precisionStep
PRECISION_STEP_DEFAULT (4).
Declaration
public static Int32Field AddInt32Field(this Document document, string name, int value, Field.Store stored)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Int32 | value | 32-bit System.Int32 value |
Field.Store | stored | YES if the content should also be stored |
Returns
Type | Description |
---|---|
Int32Field | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddInt32Field(Document, String, Int32, FieldType)
Adds a stored or un-stored Int32Field with the provided value.
Expert: allows you to customize the FieldType.
Declaration
public static Int32Field AddInt32Field(this Document document, string name, int value, FieldType type)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Int32 | value | 32-bit System.Int32 value |
FieldType | type | customized field type: must have NumericType of INT32. |
Returns
Type | Description |
---|---|
Int32Field | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
System.ArgumentException | if the field type does not have a NumericType of INT32 |
AddInt64Field(Document, String, Int64, Field.Store)
Adds a stored or un-stored Int64Field with the provided value
and default precisionStep
PRECISION_STEP_DEFAULT (4).
Declaration
public static Int64Field AddInt64Field(this Document document, string name, long value, Field.Store stored)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Int64 | value | 64-bit System.Int64 value |
Field.Store | stored | YES if the content should also be stored |
Returns
Type | Description |
---|---|
Int64Field | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddInt64Field(Document, String, Int64, FieldType)
Adds a stored or un-stored Int64Field with the provided value.
Expert: allows you to customize the FieldType.
Declaration
public static Int64Field AddInt64Field(this Document document, string name, long value, FieldType type)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Int64 | value | 64-bit System.Int64 value |
FieldType | type | customized field type: must have NumericType of INT64. |
Returns
Type | Description |
---|---|
Int64Field | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
System.ArgumentException | if the field type does not have a NumericType of INT64 |
AddNumericDocValuesField(Document, String, Int64)
Adds a new NumericDocValuesField field with the specified 64-bit System.Int64 value
Declaration
public static NumericDocValuesField AddNumericDocValuesField(this Document document, string name, long value)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Int64 | value | 64-bit System.Int64 value |
Returns
Type | Description |
---|---|
NumericDocValuesField | The field that was added to this Document. |
Remarks
If you also need to store the value, you should add a separate StoredField instance.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddSingleDocValuesField(Document, String, Single)
Adds a new SingleDocValuesField field with the specified 32-bit System.Single value
Declaration
public static SingleDocValuesField AddSingleDocValuesField(this Document document, string name, float value)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Single | value | 32-bit System.Single value |
Returns
Type | Description |
---|---|
SingleDocValuesField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field name is |
AddSingleField(Document, String, Single, Field.Store)
Adds a stored or un-stored SingleField with the provided value
and default precisionStep
PRECISION_STEP_DEFAULT
(4).
Declaration
public static SingleField AddSingleField(this Document document, string name, float value, Field.Store stored)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Single | value | 32-bit System.Single value |
Field.Store | stored | YES if the content should also be stored |
Returns
Type | Description |
---|---|
SingleField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddSingleField(Document, String, Single, FieldType)
Adds a stored or un-stored SingleField with the provided value.
Expert: allows you to customize the FieldType.
Declaration
public static SingleField AddSingleField(this Document document, string name, float value, FieldType type)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Single | value | 32-bit System.Single value |
FieldType | type | customized field type: must have NumericType of SINGLE. |
Returns
Type | Description |
---|---|
SingleField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
System.ArgumentException | if the field type does not have a SINGLE NumericType |
AddSortedDocValuesField(Document, String, BytesRef)
Adds a new SortedDocValuesField field.
Declaration
public static SortedDocValuesField AddSortedDocValuesField(this Document document, string name, BytesRef bytes)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
BytesRef | bytes | binary content |
Returns
Type | Description |
---|---|
SortedDocValuesField | The field that was added to this Document. |
Remarks
If you also need to store the value, you should add a separate StoredField instance.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddSortedSetDocValuesField(Document, String, BytesRef)
Adds a new SortedSetDocValuesField field.
Declaration
public static SortedSetDocValuesField AddSortedSetDocValuesField(this Document document, string name, BytesRef bytes)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
BytesRef | bytes | binary content |
Returns
Type | Description |
---|---|
SortedSetDocValuesField | The field that was added to this Document. |
Remarks
If you also need to store the value, you should add a separate StoredField instance.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddStoredField(Document, String, BytesRef)
Adds a stored-only field with the given binary value.
NOTE: the provided BytesRef is not copied so be sure not to change it until you're done with this field.
Declaration
public static StoredField AddStoredField(this Document document, string name, BytesRef value)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
BytesRef | value | BytesRef pointing to binary content (not copied) |
Returns
Type | Description |
---|---|
StoredField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddStoredField(Document, String, Byte[])
Adds a stored-only field with the given binary value.
NOTE: the provided byte[] is not copied so be sure not to change it until you're done with this field.
Declaration
public static StoredField AddStoredField(this Document document, string name, byte[] value)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Byte[] | value | byte array pointing to binary content (not copied) |
Returns
Type | Description |
---|---|
StoredField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddStoredField(Document, String, Byte[], Int32, Int32)
Adds a stored-only field with the given binary value.
NOTE: the provided byte[] is not copied so be sure not to change it until you're done with this field.
Declaration
public static StoredField AddStoredField(this Document document, string name, byte[] value, int offset, int length)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Byte[] | value | System.Byte array pointing to binary content (not copied) |
System.Int32 | offset | starting position of the byte array |
System.Int32 | length | valid length of the byte array |
Returns
Type | Description |
---|---|
StoredField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddStoredField(Document, String, Double)
Adds a stored-only field with the given System.Double value.
Declaration
public static StoredField AddStoredField(this Document document, string name, double value)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Double | value | System.Double value |
Returns
Type | Description |
---|---|
StoredField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddStoredField(Document, String, Int32)
Adds a stored-only field with the given System.Int32 value.
Declaration
public static StoredField AddStoredField(this Document document, string name, int value)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Int32 | value | System.Int32 value |
Returns
Type | Description |
---|---|
StoredField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddStoredField(Document, String, Int64)
Adds a stored-only field with the given System.Int64 value.
Declaration
public static StoredField AddStoredField(this Document document, string name, long value)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Int64 | value | System.Int64 value |
Returns
Type | Description |
---|---|
StoredField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddStoredField(Document, String, Single)
Adds a stored-only field with the given System.Single value.
Declaration
public static StoredField AddStoredField(this Document document, string name, float value)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.Single | value | System.Single value |
Returns
Type | Description |
---|---|
StoredField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddStoredField(Document, String, String)
Adds a stored-only field with the given System.String value.
Declaration
public static StoredField AddStoredField(this Document document, string name, string value)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.String | value | System.String value |
Returns
Type | Description |
---|---|
StoredField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddStringField(Document, String, String, Field.Store)
Adds a new StringField (a field that is indexed but not tokenized)
Declaration
public static StringField AddStringField(this Document document, string name, string value, Field.Store stored)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.String | value | System.String value |
Field.Store | stored | YES if the content should also be stored |
Returns
Type | Description |
---|---|
StringField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddTextField(Document, String, TokenStream)
Adds a new un-stored TextField with TokenStream value.
Declaration
public static TextField AddTextField(this Document document, string name, TokenStream stream)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
TokenStream | stream | TokenStream value |
Returns
Type | Description |
---|---|
TextField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddTextField(Document, String, TextReader)
Adds a new un-stored TextField with System.IO.TextReader value.
Declaration
public static TextField AddTextField(this Document document, string name, TextReader reader)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.IO.TextReader | reader | System.IO.TextReader value |
Returns
Type | Description |
---|---|
TextField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
AddTextField(Document, String, String, Field.Store)
Adds a new TextField with System.String value.
Declaration
public static TextField AddTextField(this Document document, string name, string value, Field.Store stored)
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | field name |
System.String | value | System.String value |
Field.Store | stored | YES if the content should also be stored |
Returns
Type | Description |
---|---|
TextField | The field that was added to this Document. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if the field |
GetField<T>(Document, String)
Returns a field with the given name if any exist in this document cast to type T
, or
null
. If multiple fields exists with this name, this method returns the
first value added.
Declaration
public static T GetField<T>(this Document document, string name)
where T : IIndexableField
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | Field name |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
System.InvalidCastException | If the field type cannot be cast to |
GetFields<T>(Document, String)
Returns an array of IIndexableFields with the given name, cast to type T
.
This method returns an empty array when there are no
matching fields. It never returns null
.
Declaration
public static T[] GetFields<T>(this Document document, string name)
where T : IIndexableField
Parameters
Type | Name | Description |
---|---|---|
Document | document | This Document. |
System.String | name | the name of the field |
Returns
Type | Description |
---|---|
T[] | a IndexableField[] array |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
System.InvalidCastException | If the field type cannot be cast to |