Class Field

    • Constructor Detail

      • Field

        public Field​(java.lang.String name,
                     java.io.Reader reader,
                     FieldType type)
        Create field with Reader value.
        Parameters:
        name - field name
        reader - reader value
        type - field type
        Throws:
        java.lang.IllegalArgumentException - if either the name or type is null, or if the field's type is stored(), or if tokenized() is false.
        java.lang.NullPointerException - if the reader is null
      • Field

        public Field​(java.lang.String name,
                     TokenStream tokenStream,
                     FieldType type)
        Create field with TokenStream value.
        Parameters:
        name - field name
        tokenStream - TokenStream value
        type - field type
        Throws:
        java.lang.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.
        java.lang.NullPointerException - if the tokenStream is null
      • Field

        public Field​(java.lang.String name,
                     byte[] value,
                     FieldType 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:
        java.lang.IllegalArgumentException - if the field name is null, or the field's type is indexed()
        java.lang.NullPointerException - if the type is null
      • Field

        public Field​(java.lang.String name,
                     byte[] value,
                     int offset,
                     int length,
                     FieldType 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:
        java.lang.IllegalArgumentException - if the field name is null, or the field's type is indexed()
        java.lang.NullPointerException - if the type is null
      • Field

        public Field​(java.lang.String name,
                     BytesRef bytes,
                     FieldType 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:
        java.lang.IllegalArgumentException - if the field name is null, or the field's type is indexed()
        java.lang.NullPointerException - if the type is null
      • Field

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

        @Deprecated
        public Field​(java.lang.String name,
                     java.lang.String value,
                     Field.Store store,
                     Field.Index index)
        Deprecated.
        Use StringField, TextField instead.
        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.
        Parameters:
        name - The name of the field
        value - The string to process
        store - Whether value should be stored in the index
        index - Whether the field should be indexed, and if so, if it should be tokenized before indexing
        Throws:
        java.lang.NullPointerException - if name or value is null
        java.lang.IllegalArgumentException - if the field is neither stored nor indexed
      • Field

        @Deprecated
        public Field​(java.lang.String name,
                     java.lang.String value,
                     Field.Store store,
                     Field.Index index,
                     Field.TermVector termVector)
        Deprecated.
        Use StringField, TextField instead.
        Create a field by specifying its name, value and how it will be saved in the index.
        Parameters:
        name - The name of the field
        value - The string to process
        store - Whether value should be stored in the index
        index - Whether the field should be indexed, and if so, if it should be tokenized before indexing
        termVector - Whether term vector should be stored
        Throws:
        java.lang.NullPointerException - if name or value is null
        java.lang.IllegalArgumentException - in any of the following situations:
        • the field is neither stored nor indexed
        • the field is not indexed but termVector is TermVector.YES
      • Field

        @Deprecated
        public Field​(java.lang.String name,
                     java.io.Reader reader)
        Deprecated.
        Use TextField instead.
        Create a tokenized and indexed field that is not stored. Term vectors will not be stored. The Reader is read only when the Document is added to the index, i.e. you may not close the Reader until IndexWriter.addDocument(java.lang.Iterable<? extends org.apache.lucene.index.IndexableField>) has been called.
        Parameters:
        name - The name of the field
        reader - The reader with the content
        Throws:
        java.lang.NullPointerException - if name or reader is null
      • Field

        @Deprecated
        public Field​(java.lang.String name,
                     java.io.Reader reader,
                     Field.TermVector termVector)
        Deprecated.
        Use TextField instead.
        Create a tokenized and indexed field that is not stored, optionally with storing term vectors. The Reader is read only when the Document is added to the index, i.e. you may not close the Reader until IndexWriter.addDocument(java.lang.Iterable<? extends org.apache.lucene.index.IndexableField>) has been called.
        Parameters:
        name - The name of the field
        reader - The reader with the content
        termVector - Whether term vector should be stored
        Throws:
        java.lang.NullPointerException - if name or reader is null
      • Field

        @Deprecated
        public Field​(java.lang.String name,
                     TokenStream tokenStream)
        Deprecated.
        Use TextField instead
        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 IndexWriter.addDocument(java.lang.Iterable<? extends org.apache.lucene.index.IndexableField>) has been called.
        Parameters:
        name - The name of the field
        tokenStream - The TokenStream with the content
        Throws:
        java.lang.NullPointerException - if name or tokenStream is null
      • Field

        @Deprecated
        public Field​(java.lang.String name,
                     TokenStream tokenStream,
                     Field.TermVector termVector)
        Deprecated.
        Use TextField instead
        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 IndexWriter.addDocument(java.lang.Iterable<? extends org.apache.lucene.index.IndexableField>) has been called.
        Parameters:
        name - The name of the field
        tokenStream - The TokenStream with the content
        termVector - Whether term vector should be stored
        Throws:
        java.lang.NullPointerException - if name or tokenStream is null
      • Field

        @Deprecated
        public Field​(java.lang.String name,
                     byte[] value)
        Deprecated.
        Use StoredField instead.
        Create a stored field with binary value. Optionally the value may be compressed.
        Parameters:
        name - The name of the field
        value - The binary value
      • Field

        @Deprecated
        public Field​(java.lang.String name,
                     byte[] value,
                     int offset,
                     int length)
        Deprecated.
        Use StoredField instead.
        Create a stored field with binary value. Optionally the value may be compressed.
        Parameters:
        name - The name of the field
        value - The binary value
        offset - Starting offset in value where this Field's bytes are
        length - Number of bytes to use for this Field, starting at offset
    • Method Detail

      • stringValue

        public java.lang.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 getBinaryValue() must be set.
        Specified by:
        stringValue in interface IndexableField
      • readerValue

        public java.io.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 getBinaryValue() 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​(java.lang.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.

      • setReaderValue

        public void setReaderValue​(java.io.Reader value)
        Expert: change the value of this field. See setStringValue(String).
      • 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 getBinaryValue()
      • boost

        public float boost()
        Returns the field's index-time boost.

        Only fields can have an index-time boost, if you want to simulate a "document boost", then you must pre-multiply it across all the relevant fields yourself.

        The boost is used to compute the norm factor for the field. By default, in the Similarity.computeNorm(FieldInvertState) method, the boost value is multiplied by the length normalization factor and then rounded by DefaultSimilarity.encodeNormValue(float) before it is stored in the index. One should attempt to ensure that this product does not overflow the range of that encoding.

        It is illegal to return a boost other than 1.0f for a field that is not indexed (IndexableFieldType.indexed() is false) or omits normalization values (IndexableFieldType.omitNorms() returns true).

        The default value is 1.0f (no boost).

        Specified by:
        boost in interface IndexableField
        See Also:
        setBoost(float)
      • setBoost

        public void setBoost​(float boost)
        Sets the boost factor on this field.
        Throws:
        java.lang.IllegalArgumentException - if this field is not indexed, or if it omits norms.
        See Also:
        boost()
      • numericValue

        public java.lang.Number numericValue()
        Description copied from interface: IndexableField
        Non-null if this field has a numeric value
        Specified by:
        numericValue in interface IndexableField
      • toString

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

        public TokenStream tokenStream​(Analyzer analyzer)
                                throws java.io.IOException
        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
        Returns:
        TokenStream value for indexing the document. Should always return a non-null value if the field is to be indexed
        Throws:
        java.io.IOException - Can be thrown while creating the TokenStream
      • translateFieldType

        @Deprecated
        public static final FieldType translateFieldType​(Field.Store store,
                                                         Field.Index index,
                                                         Field.TermVector termVector)
        Deprecated.
        This is here only to ease transition from the pre-4.0 APIs.
        Translates the pre-4.0 enums for specifying how a field should be indexed into the 4.0 FieldType approach.