Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class DocumentExtensions

    LUCENENET specific extensions to the Document class.

    Inheritance
    object
    DocumentExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Documents.Extensions
    Assembly: Lucene.Net.dll
    Syntax
    public static class DocumentExtensions

    Methods

    AddBinaryDocValuesField(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.

    string name

    field name

    BytesRef value

    binary content

    Returns
    Type Description
    BinaryDocValuesField

    The field that was added to this Document.

    Exceptions
    Type Condition
    ArgumentNullException

    if this document or 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.

    string name

    field name

    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 DoubleToRawInt64Bits(double).

    Per-document double values can be retrieved via GetDoubles(AtomicReader, string, bool).

    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
    ArgumentNullException

    if this document or the field name is null

    AddDoubleField(Document, string, double, Store)

    Adds a stored or un-stored DoubleField with the provided value and default precisionStepPRECISION_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.

    string name

    field name

    double value

    64-bit 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
    ArgumentNullException

    if this document or the field name is null.

    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.

    string name

    field name

    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
    ArgumentNullException

    if this document, the field name or type is null, or if the field type does not have a DOUBLENumericType

    AddInt32Field(Document, string, int, Store)

    Adds a stored or un-stored Int32Field with the provided value and default precisionStepPRECISION_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.

    string name

    field name

    int value

    32-bit int 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
    ArgumentNullException

    if this document or the field name is null.

    AddInt32Field(Document, string, int, 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.

    string name

    field name

    int value

    32-bit int 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
    ArgumentNullException

    if this document, the field name or type is null.

    ArgumentException

    if the field type does not have a NumericType of INT32

    AddInt64Field(Document, string, long, Store)

    Adds a stored or un-stored Int64Field with the provided value and default precisionStepPRECISION_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.

    string name

    field name

    long value

    64-bit long 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
    ArgumentNullException

    if this document or the field name is null.

    AddInt64Field(Document, string, long, 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.

    string name

    field name

    long value

    64-bit long 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
    ArgumentNullException

    if this document, the field name or type is null.

    ArgumentException

    if the field type does not have a NumericType of INT64

    AddNumericDocValuesField(Document, string, long)

    Adds a new NumericDocValuesField field with the specified 64-bit long value

    Declaration
    public static NumericDocValuesField AddNumericDocValuesField(this Document document, string name, long value)
    Parameters
    Type Name Description
    Document document

    This Document.

    string name

    field name

    long value

    64-bit long 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
    ArgumentNullException

    if this document, the field name is null.

    AddSingleDocValuesField(Document, string, float)

    Adds a new SingleDocValuesField field with the specified 32-bit float value

    Declaration
    public static SingleDocValuesField AddSingleDocValuesField(this Document document, string name, float value)
    Parameters
    Type Name Description
    Document document

    This Document.

    string name

    field name

    float value

    32-bit float value

    Returns
    Type Description
    SingleDocValuesField

    The field that was added to this Document.

    Exceptions
    Type Condition
    ArgumentNullException

    if this document or the field name is null

    AddSingleField(Document, string, float, Store)

    Adds a stored or un-stored SingleField with the provided value and default precisionStepPRECISION_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.

    string name

    field name

    float value

    32-bit float 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
    ArgumentNullException

    if this document or the field name is null.

    AddSingleField(Document, string, float, 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.

    string name

    field name

    float value

    32-bit float 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
    ArgumentNullException

    if this document, the field name or type is null.

    ArgumentException

    if the field type does not have a SINGLENumericType

    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.

    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
    ArgumentNullException

    if this document, the field name is null.

    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.

    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
    ArgumentNullException

    if this document, the field name is null.

    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.

    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
    ArgumentNullException

    if this document, the field name is null.

    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.

    string name

    field name

    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
    ArgumentNullException

    if this document, the field name is null.

    AddStoredField(Document, string, byte[], int, int)

    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.

    string name

    field name

    byte[] value

    byte array pointing to binary content (not copied)

    int offset

    starting position of the byte array

    int length

    valid length of the byte array

    Returns
    Type Description
    StoredField

    The field that was added to this Document.

    Exceptions
    Type Condition
    ArgumentNullException

    if this document, the field name is null.

    AddStoredField(Document, string, double)

    Adds a stored-only field with the given double value.

    Declaration
    public static StoredField AddStoredField(this Document document, string name, double value)
    Parameters
    Type Name Description
    Document document

    This Document.

    string name

    field name

    double value

    double value

    Returns
    Type Description
    StoredField

    The field that was added to this Document.

    Exceptions
    Type Condition
    ArgumentNullException

    if this document, the field name is null.

    AddStoredField(Document, string, int)

    Adds a stored-only field with the given int value.

    Declaration
    public static StoredField AddStoredField(this Document document, string name, int value)
    Parameters
    Type Name Description
    Document document

    This Document.

    string name

    field name

    int value

    int value

    Returns
    Type Description
    StoredField

    The field that was added to this Document.

    Exceptions
    Type Condition
    ArgumentNullException

    if this document, the field name is null.

    AddStoredField(Document, string, long)

    Adds a stored-only field with the given long value.

    Declaration
    public static StoredField AddStoredField(this Document document, string name, long value)
    Parameters
    Type Name Description
    Document document

    This Document.

    string name

    field name

    long value

    long value

    Returns
    Type Description
    StoredField

    The field that was added to this Document.

    Exceptions
    Type Condition
    ArgumentNullException

    if this document, the field name is null.

    AddStoredField(Document, string, float)

    Adds a stored-only field with the given float value.

    Declaration
    public static StoredField AddStoredField(this Document document, string name, float value)
    Parameters
    Type Name Description
    Document document

    This Document.

    string name

    field name

    float value

    float value

    Returns
    Type Description
    StoredField

    The field that was added to this Document.

    Exceptions
    Type Condition
    ArgumentNullException

    if this document, the field name is null.

    AddStoredField(Document, string, string)

    Adds a stored-only field with the given string value.

    Declaration
    public static StoredField AddStoredField(this Document document, string name, string value)
    Parameters
    Type Name Description
    Document document

    This Document.

    string name

    field name

    string value

    string value

    Returns
    Type Description
    StoredField

    The field that was added to this Document.

    Exceptions
    Type Condition
    ArgumentNullException

    if this document, the field name or value is null.

    AddStringField(Document, string, string, 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.

    string name

    field name

    string value

    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
    ArgumentNullException

    if this document, the field name or value is null.

    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.

    string name

    field name

    TokenStream stream

    TokenStream value

    Returns
    Type Description
    TextField

    The field that was added to this Document.

    Exceptions
    Type Condition
    ArgumentNullException

    if this document, the field name or stream is null.

    AddTextField(Document, string, TextReader)

    Adds a new un-stored TextField with TextReader value.

    Declaration
    public static TextField AddTextField(this Document document, string name, TextReader reader)
    Parameters
    Type Name Description
    Document document

    This Document.

    string name

    field name

    TextReader reader

    TextReader value

    Returns
    Type Description
    TextField

    The field that was added to this Document.

    Exceptions
    Type Condition
    ArgumentNullException

    if this document, the field name or reader is null.

    AddTextField(Document, string, string, Store)

    Adds a new TextField with 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.

    string name

    field name

    string value

    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
    ArgumentNullException

    if this document, the field name or value is null.

    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.

    string name

    Field name

    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T
    Exceptions
    Type Condition
    InvalidCastException

    If the field type cannot be cast to T.

    ArgumentNullException

    This document is null.

    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.

    string name

    the name of the field

    Returns
    Type Description
    T[]

    a IndexableField[] array

    Type Parameters
    Name Description
    T
    Exceptions
    Type Condition
    InvalidCastException

    If the field type cannot be cast to .

    ArgumentNullException

    This document is null.

    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.