Class Field

    • Field Detail

      • name

        protected final String name
        Field's name
      • fieldsData

        protected Object fieldsData
        Field's value
      • tokenStream

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

      • Field

        protected Field​(String name,
                        IndexableFieldType type)
        Expert: creates a field with no initial value. Intended only for custom Field subclasses.
        Parameters:
        name - field name
        type - field type
        Throws:
        IllegalArgumentException - if either the name or type is null.
      • Field

        public Field​(String name,
                     TokenStream tokenStream,
                     IndexableFieldType type)
        Create field with TokenStream value.
        Parameters:
        name - field name
        tokenStream - TokenStream value
        type - field type
        Throws:
        IllegalArgumentException - if either the name or type is null, or if the field's type is stored(), or if tokenized() is false, or if indexed() is false.
        NullPointerException - if the tokenStream is null
      • Field

        public Field​(String name,
                     byte[] value,
                     IndexableFieldType type)
        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.

        Parameters:
        name - field name
        value - byte array pointing to binary content (not copied)
        type - field type
        Throws:
        IllegalArgumentException - if the field name, value or type is null, or the field's type is indexed().
      • Field

        public Field​(String name,
                     byte[] value,
                     int offset,
                     int length,
                     IndexableFieldType type)
        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.

        Parameters:
        name - field name
        value - byte array pointing to binary content (not copied)
        offset - starting position of the byte array
        length - valid length of the byte array
        type - field type
        Throws:
        IllegalArgumentException - if the field name, value or type is null, or the field's type is indexed().
      • Field

        public Field​(String name,
                     BytesRef bytes,
                     IndexableFieldType type)
        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.

        Parameters:
        name - field name
        bytes - BytesRef pointing to binary content (not copied)
        type - field type
        Throws:
        IllegalArgumentException - if the field name, bytes or type is null, or the field's type is indexed().
      • Field

        public Field​(String name,
                     CharSequence value,
                     IndexableFieldType type)
        Create field with String value.
        Parameters:
        name - field name
        value - string value
        type - field type
        Throws:
        IllegalArgumentException - if either the name, value or type is null, or if the field's type is neither indexed() nor stored(), or if indexed() is false but storeTermVectors() is true.
    • Method Detail

      • stringValue

        public String stringValue()
        The value of the field as a String, or null. If null, the Reader value or binary value is used. Exactly one of stringValue(), readerValue(), and binaryValue() must be set.
        Specified by:
        stringValue in interface IndexableField
      • readerValue

        public Reader readerValue()
        The value of the field as a Reader, or null. If null, the String value or binary value is used. Exactly one of stringValue(), readerValue(), and binaryValue() must be set.
        Specified by:
        readerValue in interface IndexableField
      • tokenStreamValue

        public TokenStream tokenStreamValue()
        The TokenStream for this field to be used when indexing, or null. If null, the Reader value or String value is analyzed to produce the indexed tokens.
      • setStringValue

        public void setStringValue​(String value)
        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.

      • setBytesValue

        public void setBytesValue​(byte[] value)
        Expert: change the value of this field. See setStringValue(String).
      • setBytesValue

        public void setBytesValue​(BytesRef value)
        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.

      • setByteValue

        public void setByteValue​(byte value)
        Expert: change the value of this field. See setStringValue(String).
      • setShortValue

        public void setShortValue​(short value)
        Expert: change the value of this field. See setStringValue(String).
      • setIntValue

        public void setIntValue​(int value)
        Expert: change the value of this field. See setStringValue(String).
      • setLongValue

        public void setLongValue​(long value)
        Expert: change the value of this field. See setStringValue(String).
      • setFloatValue

        public void setFloatValue​(float value)
        Expert: change the value of this field. See setStringValue(String).
      • setDoubleValue

        public void setDoubleValue​(double value)
        Expert: change the value of this field. See setStringValue(String).
      • setTokenStream

        public void setTokenStream​(TokenStream 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 stringValue() or binaryValue()
      • toString

        public String toString()
        Prints a Field for human consumption.
        Overrides:
        toString in class Object
      • invertableType

        public InvertableType invertableType()
        Description copied from interface: IndexableField
        Describes how this field should be inverted. This must return a non-null value if the field indexes terms and postings.
        Specified by:
        invertableType in interface IndexableField
      • tokenStream

        public TokenStream tokenStream​(Analyzer analyzer,
                                       TokenStream reuse)
        Description copied from interface: IndexableField
        Creates the TokenStream used for indexing this field. If appropriate, implementations should use the given Analyzer to create the TokenStreams.
        Specified by:
        tokenStream in interface IndexableField
        Parameters:
        analyzer - Analyzer that should be used to create the TokenStreams from
        reuse - TokenStream for a previous instance of this field name. This allows custom field types (like StringField and NumericField) that do not use the analyzer to still have good performance. Note: the passed-in type may be inappropriate, for example if you mix up different types of Fields for the same field name. So it's the responsibility of the implementation to check.
        Returns:
        TokenStream value for indexing the document. Should always return a non-null value if the field is to be indexed
      • storedValue

        public StoredValue storedValue()
        Description copied from interface: IndexableField
        Stored value. This method is called to populate stored fields and must return a non-null value if the field stored.
        Specified by:
        storedValue in interface IndexableField