Show / Hide Table of Contents

    Class Field

    Expert: directly create a field for a document. Most users should use one of the sugar subclasses: Int32Field, Int64Field, SingleField, DoubleField, BinaryDocValuesField, NumericDocValuesField, SortedDocValuesField, StringField, TextField, StoredField.

    A field is a section of a Document. Each field has three parts: name, type and value. Values may be text (, or pre-analyzed TokenStream), binary (byte[]), or numeric (, , , or ). Fields are optionally stored in the index, so that they may be returned with hits on the document.

    NOTE: the field type is an IIndexableFieldType. Making changes to the state of the IIndexableFieldType will impact any Field it is used in. It is strongly recommended that no changes be made after Field instantiation.

    Inheritance
    System.Object
    Field
    BinaryDocValuesField
    DoubleField
    Int32Field
    Int64Field
    NumericDocValuesField
    SingleField
    SortedDocValuesField
    SortedSetDocValuesField
    StoredField
    StringField
    TextField
    Implements
    IIndexableField
    Namespace: Lucene.Net.Documents
    Assembly: Lucene.Net.dll
    Syntax
    public class Field : object, IIndexableField

    Constructors

    | Improve this Doc View Source

    Field(String, TokenStream)

    Create a tokenized and indexed field that is not stored. Term vectors will not be stored. This is useful for pre-analyzed fields. The TokenStream is read only when the Document is added to the index, i.e. you may not close the TokenStream until has been called.

    Declaration
    public Field(string name, TokenStream tokenStream)
    Parameters
    Type Name Description
    System.String name

    The name of the field

    TokenStream tokenStream

    The TokenStream with the content

    | Improve this Doc View Source

    Field(String, TokenStream, Field.TermVector)

    Create a tokenized and indexed field that is not stored, optionally with storing term vectors. This is useful for pre-analyzed fields. The TokenStream is read only when the Document is added to the index, i.e. you may not close the TokenStream until has been called.

    Declaration
    public Field(string name, TokenStream tokenStream, Field.TermVector termVector)
    Parameters
    Type Name Description
    System.String name

    The name of the field

    TokenStream tokenStream

    The TokenStream with the content

    Field.TermVector termVector

    Whether term vector should be stored

    | Improve this Doc View Source

    Field(String, TokenStream, FieldType)

    Create field with TokenStream value.

    Declaration
    public Field(string name, TokenStream tokenStream, FieldType type)
    Parameters
    Type Name Description
    System.String name

    field name

    TokenStream tokenStream

    TokenStream value

    FieldType type

    field type

    | Improve this Doc View Source

    Field(String, FieldType)

    Expert: creates a field with no initial value. Intended only for custom Field subclasses.

    Declaration
    protected Field(string name, FieldType type)
    Parameters
    Type Name Description
    System.String name

    field name

    FieldType type

    field type

    | Improve this Doc View Source

    Field(String, BytesRef, FieldType)

    Create field with 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 Field(string name, BytesRef bytes, FieldType type)
    Parameters
    Type Name Description
    System.String name

    field name

    BytesRef bytes

    BytesRef pointing to binary content (not copied)

    FieldType type

    field type

    | Improve this Doc View Source

    Field(String, Byte[])

    Create a stored field with binary value. Optionally the value may be compressed.

    Declaration
    public Field(string name, byte[] value)
    Parameters
    Type Name Description
    System.String name

    The name of the field

    System.Byte[] value

    The binary value

    | Improve this Doc View Source

    Field(String, Byte[], FieldType)

    Create field with 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 Field(string name, byte[] value, FieldType type)
    Parameters
    Type Name Description
    System.String name

    field name

    System.Byte[] value

    byte array pointing to binary content (not copied)

    FieldType type

    field type

    | Improve this Doc View Source

    Field(String, Byte[], Int32, Int32)

    Create a stored field with binary value. Optionally the value may be compressed.

    Declaration
    public Field(string name, byte[] value, int offset, int length)
    Parameters
    Type Name Description
    System.String name

    The name of the field

    System.Byte[] value

    The binary value

    System.Int32 offset

    Starting offset in value where this Field's bytes are

    System.Int32 length

    Number of bytes to use for this Field, starting at offset

    | Improve this Doc View Source

    Field(String, Byte[], Int32, Int32, FieldType)

    Create field with 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 Field(string name, byte[] value, int offset, int length, FieldType type)
    Parameters
    Type Name Description
    System.String name

    field name

    System.Byte[] value

    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

    FieldType type

    field type

    | Improve this Doc View Source

    Field(String, String, Field.Store, Field.Index)

    Create a field by specifying its name, value and how it will be saved in the index. Term vectors will not be stored in the index.

    Declaration
    public Field(string name, string value, Field.Store store, Field.Index index)
    Parameters
    Type Name Description
    System.String name

    The name of the field

    System.String value

    The string to process

    Field.Store store

    Whether value should be stored in the index

    Field.Index index

    Whether the field should be indexed, and if so, if it should be tokenized before indexing

    | Improve this Doc View Source

    Field(String, String, Field.Store, Field.Index, Field.TermVector)

    Create a field by specifying its name, value and how it will be saved in the index.

    Declaration
    public Field(string name, string value, Field.Store store, Field.Index index, Field.TermVector termVector)
    Parameters
    Type Name Description
    System.String name

    The name of the field

    System.String value

    The string to process

    Field.Store store

    Whether value should be stored in the index

    Field.Index index

    Whether the field should be indexed, and if so, if it should be tokenized before indexing

    Field.TermVector termVector

    Whether term vector should be stored

    | Improve this Doc View Source

    Field(String, String, FieldType)

    Create field with value.

    Declaration
    public Field(string name, string value, FieldType type)
    Parameters
    Type Name Description
    System.String name

    field name

    System.String value

    string value

    FieldType type

    field type

    | Improve this Doc View Source

    Field(String, TextReader)

    Create a tokenized and indexed field that is not stored. Term vectors will not be stored. The is read only when the Document is added to the index, i.e. you may not close the until has been called.

    Declaration
    public Field(string name, TextReader reader)
    Parameters
    Type Name Description
    System.String name

    The name of the field

    TextReader reader

    The reader with the content

    | Improve this Doc View Source

    Field(String, TextReader, Field.TermVector)

    Create a tokenized and indexed field that is not stored, optionally with storing term vectors. The is read only when the Document is added to the index, i.e. you may not close the until has been called.

    Declaration
    public Field(string name, TextReader reader, Field.TermVector termVector)
    Parameters
    Type Name Description
    System.String name

    The name of the field

    TextReader reader

    The reader with the content

    Field.TermVector termVector

    Whether term vector should be stored

    | Improve this Doc View Source

    Field(String, TextReader, FieldType)

    Create field with value.

    Declaration
    public Field(string name, TextReader reader, FieldType type)
    Parameters
    Type Name Description
    System.String name

    field name

    TextReader reader

    reader value

    FieldType type

    field type

    Fields

    | Improve this Doc View Source

    m_boost

    Field's boost

    Declaration
    protected float m_boost
    Field Value
    Type Description
    System.Single
    See Also
    Boost
    | Improve this Doc View Source

    m_name

    Field's name

    Declaration
    protected readonly string m_name
    Field Value
    Type Description
    System.String
    | Improve this Doc View Source

    m_tokenStream

    Pre-analyzed TokenStream for indexed fields; this is separate from FieldsData because you are allowed to have both; eg maybe field has a value but you customize how it's tokenized

    Declaration
    protected TokenStream m_tokenStream
    Field Value
    Type Description
    TokenStream
    | Improve this Doc View Source

    m_type

    Field's type

    Declaration
    protected readonly FieldType m_type
    Field Value
    Type Description
    FieldType

    Properties

    | Improve this Doc View Source

    Boost

    Gets or sets the boost factor on this field.

    Declaration
    public virtual float Boost { get; set; }
    Property Value
    Type Description
    System.Single
    Remarks

    The default value is 1.0f (no boost).

    | Improve this Doc View Source

    FieldsData

    Field's value

    Setting this property will automatically set the backing field for the NumericType property.

    Declaration
    protected object FieldsData { get; set; }
    Property Value
    Type Description
    System.Object
    | Improve this Doc View Source

    FieldType

    Returns the FieldType for this field as type FieldType.

    Declaration
    public virtual FieldType FieldType { get; }
    Property Value
    Type Description
    FieldType
    | Improve this Doc View Source

    IndexableFieldType

    Returns the FieldType for this field as type IIndexableFieldType.

    Declaration
    public virtual IIndexableFieldType IndexableFieldType { get; }
    Property Value
    Type Description
    IIndexableFieldType
    | Improve this Doc View Source

    Name

    The field's name

    Declaration
    public virtual string Name { get; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    NumericType

    Gets the NumericFieldType of the underlying value, or NONE if the value is not set or non-numeric.

    Expert: The difference between this property and NumericType is this is represents the current state of the field (whether being written or read) and the FieldType property represents instructions on how the field will be written, but does not re-populate when reading back from an index (it is write-only).

    In Java, the numeric type was determined by checking the type of
    GetNumericValue(). However, since there are no reference number types in .NET, using GetNumericValue() so will cause boxing/unboxing. It is therefore recommended to use this property to check the underlying type and the corresponding Get*Value() method to retrieve the value.

    NOTE: Since Lucene codecs do not support BYTE or INT16, fields created with these types will always be INT32 when read back from the index.

    Declaration
    public virtual NumericFieldType NumericType { get; }
    Property Value
    Type Description
    NumericFieldType

    Methods

    | Improve this Doc View Source

    GetBinaryValue()

    Non-null if this field has a binary value.

    Declaration
    public virtual BytesRef GetBinaryValue()
    Returns
    Type Description
    BytesRef
    | Improve this Doc View Source

    GetByteValue()

    Returns the field value as or null if the type is non-numeric.

    Declaration
    public virtual byte? GetByteValue()
    Returns
    Type Description
    System.Nullable<System.Byte>

    The field value or null if the type is non-numeric.

    | Improve this Doc View Source

    GetDoubleValue()

    Returns the field value as or null if the type is non-numeric.

    Declaration
    public virtual double? GetDoubleValue()
    Returns
    Type Description
    System.Nullable<System.Double>

    The field value or null if the type is non-numeric.

    | Improve this Doc View Source

    GetInt16Value()

    Returns the field value as or null if the type is non-numeric.

    Declaration
    public virtual short? GetInt16Value()
    Returns
    Type Description
    System.Nullable<System.Int16>

    The field value or null if the type is non-numeric.

    | Improve this Doc View Source

    GetInt32Value()

    Returns the field value as or null if the type is non-numeric.

    Declaration
    public virtual int? GetInt32Value()
    Returns
    Type Description
    System.Nullable<System.Int32>

    The field value or null if the type is non-numeric.

    | Improve this Doc View Source

    GetInt64Value()

    Returns the field value as or null if the type is non-numeric.

    Declaration
    public virtual long? GetInt64Value()
    Returns
    Type Description
    System.Nullable<System.Int64>

    The field value or null if the type is non-numeric.

    | Improve this Doc View Source

    GetNumericValue()

    Declaration
    public virtual object GetNumericValue()
    Returns
    Type Description
    System.Object
    | Improve this Doc View Source

    GetReaderValue()

    The value of the field as a , or null. If null, the value or binary value is used. Exactly one of GetStringValue(), GetReaderValue(), and GetBinaryValue() must be set.

    Declaration
    public virtual TextReader GetReaderValue()
    Returns
    Type Description
    TextReader
    | Improve this Doc View Source

    GetSingleValue()

    Returns the field value as or null if the type is non-numeric.

    Declaration
    public virtual float? GetSingleValue()
    Returns
    Type Description
    System.Nullable<System.Single>

    The field value or null if the type is non-numeric.

    | Improve this Doc View Source

    GetStringValue()

    The value of the field as a , or null. If null, the value or binary value is used. Exactly one of GetStringValue(), GetReaderValue(), and GetBinaryValue() must be set.

    Declaration
    public virtual string GetStringValue()
    Returns
    Type Description
    System.String

    The string representation of the value if it is either a or numeric type.

    | Improve this Doc View Source

    GetStringValue(IFormatProvider)

    The value of the field as a , or null. If null, the value or binary value is used. Exactly one of GetStringValue(), GetReaderValue(), and GetBinaryValue() must be set.

    Declaration
    public virtual string GetStringValue(IFormatProvider provider)
    Parameters
    Type Name Description
    IFormatProvider provider

    An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.

    Returns
    Type Description
    System.String

    The string representation of the value if it is either a or numeric type.

    | Improve this Doc View Source

    GetStringValue(String)

    The value of the field as a , or null. If null, the value or binary value is used. Exactly one of GetStringValue(), GetReaderValue(), and GetBinaryValue() must be set.

    Declaration
    public virtual string GetStringValue(string format)
    Parameters
    Type Name Description
    System.String format

    A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.

    Returns
    Type Description
    System.String

    The string representation of the value if it is either a or numeric type.

    | Improve this Doc View Source

    GetStringValue(String, IFormatProvider)

    The value of the field as a , or null. If null, the value or binary value is used. Exactly one of GetStringValue(), GetReaderValue(), and GetBinaryValue() must be set.

    Declaration
    public virtual string GetStringValue(string format, IFormatProvider provider)
    Parameters
    Type Name Description
    System.String format

    A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.

    IFormatProvider provider

    An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.

    Returns
    Type Description
    System.String

    The string representation of the value if it is either a or numeric type.

    | Improve this Doc View Source

    GetTokenStream(Analyzer)

    Declaration
    public virtual TokenStream GetTokenStream(Analyzer analyzer)
    Parameters
    Type Name Description
    Analyzer analyzer
    Returns
    Type Description
    TokenStream
    | Improve this Doc View Source

    GetTokenStreamValue()

    The TokenStream for this field to be used when indexing, or null. If null, the value or value is analyzed to produce the indexed tokens.

    Declaration
    public virtual TokenStream GetTokenStreamValue()
    Returns
    Type Description
    TokenStream
    | Improve this Doc View Source

    SetBytesValue(BytesRef)

    Expert: change the value of this field. See SetStringValue(String).

    NOTE: the provided BytesRef is not copied so be sure not to change it until you're done with this field.

    Declaration
    public virtual void SetBytesValue(BytesRef value)
    Parameters
    Type Name Description
    BytesRef value
    | Improve this Doc View Source

    SetBytesValue(Byte[])

    Expert: change the value of this field. See SetStringValue(String).

    Declaration
    public virtual void SetBytesValue(byte[] value)
    Parameters
    Type Name Description
    System.Byte[] value
    | Improve this Doc View Source

    SetByteValue(Byte)

    Expert: change the value of this field. See SetStringValue(String).

    Declaration
    public virtual void SetByteValue(byte value)
    Parameters
    Type Name Description
    System.Byte value
    | Improve this Doc View Source

    SetDoubleValue(Double)

    Expert: change the value of this field. See SetStringValue(String).

    Declaration
    public virtual void SetDoubleValue(double value)
    Parameters
    Type Name Description
    System.Double value
    | Improve this Doc View Source

    SetInt16Value(Int16)

    Expert: change the value of this field. See SetStringValue(String).

    Declaration
    public virtual void SetInt16Value(short value)
    Parameters
    Type Name Description
    System.Int16 value
    | Improve this Doc View Source

    SetInt32Value(Int32)

    Expert: change the value of this field. See SetStringValue(String).

    Declaration
    public virtual void SetInt32Value(int value)
    Parameters
    Type Name Description
    System.Int32 value
    | Improve this Doc View Source

    SetInt64Value(Int64)

    Expert: change the value of this field. See SetStringValue(String).

    Declaration
    public virtual void SetInt64Value(long value)
    Parameters
    Type Name Description
    System.Int64 value
    | Improve this Doc View Source

    SetReaderValue(TextReader)

    Expert: change the value of this field. See SetStringValue(String).

    Declaration
    public virtual void SetReaderValue(TextReader value)
    Parameters
    Type Name Description
    TextReader value
    | Improve this Doc View Source

    SetSingleValue(Single)

    Expert: change the value of this field. See SetStringValue(String).

    Declaration
    public virtual void SetSingleValue(float value)
    Parameters
    Type Name Description
    System.Single value
    | Improve this Doc View Source

    SetStringValue(String)

    Expert: change the value of this field. This can be used during indexing to re-use a single Field instance to improve indexing speed by avoiding GC cost of new'ing and reclaiming Field instances. Typically a single Document instance is re-used as well. This helps most on small documents.

    Each Field instance should only be used once within a single Document instance. See ImproveIndexingSpeed for details.

    Declaration
    public virtual void SetStringValue(string value)
    Parameters
    Type Name Description
    System.String value
    | Improve this Doc View Source

    SetTokenStream(TokenStream)

    Expert: sets the token stream to be used for indexing and causes IsIndexed and IsTokenized to return true. May be combined with stored values from GetStringValue() or GetBinaryValue()

    Declaration
    public virtual void SetTokenStream(TokenStream tokenStream)
    Parameters
    Type Name Description
    TokenStream tokenStream
    | Improve this Doc View Source

    ToString()

    Prints a Field for human consumption.

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String
    | Improve this Doc View Source

    TranslateFieldType(Field.Store, Field.Index, Field.TermVector)

    Translates the pre-4.0 enums for specifying how a field should be indexed into the 4.0 FieldType approach.

    Declaration
    public static FieldType TranslateFieldType(Field.Store store, Field.Index index, Field.TermVector termVector)
    Parameters
    Type Name Description
    Field.Store store
    Field.Index index
    Field.TermVector termVector
    Returns
    Type Description
    FieldType

    Implements

    IIndexableField
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)