Class Field
- All Implemented Interfaces:
IndexableField
- Direct Known Subclasses:
BinaryDocValuesField,BinaryPoint,DoubleField,DoublePoint,DoubleRange,FeatureField,FloatField,FloatPoint,FloatRange,InetAddressPoint,InetAddressRange,IntField,IntPoint,IntRange,KeywordField,KnnByteVectorField,KnnFloatVectorField,LatLonDocValuesField,LatLonPoint,LongField,LongPoint,LongRange,NumericDocValuesField,ShapeDocValuesField,ShapeField.Triangle,SortedDocValuesField,SortedNumericDocValuesField,SortedSetDocValuesField,StoredField,StringField,TextField,XYDocValuesField,XYPointField
TextField:ReaderorStringindexed for full-text searchStringField:Stringindexed verbatim as a single tokenIntField:intindexed for exact/range queries.LongField:longindexed for exact/range queries.FloatField:floatindexed for exact/range queries.DoubleField:doubleindexed for exact/range queries.SortedDocValuesField:byte[]indexed column-wise for sorting/facetingSortedSetDocValuesField:SortedSet<byte[]>indexed column-wise for sorting/facetingNumericDocValuesField:longindexed column-wise for sorting/facetingSortedNumericDocValuesField:SortedSet<long>indexed column-wise for sorting/facetingStoredField: Stored-only value for retrieving in summary results
A field is a section of a Document. Each field has three parts: name, type and value. Values may be text (String, Reader or pre-analyzed TokenStream), binary (byte[]), or numeric (a Number). Fields are optionally stored in the index, so that they may be returned with hits on the document.
NOTE: the field type is an IndexableFieldType. Making changes to the state of the
IndexableFieldType will impact any Field it is used in. It is strongly recommended that no
changes be made after Field instantiation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSpecifies whether and how a field should be stored. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ObjectField's valueprotected final StringField's nameprotected final IndexableFieldTypeField's type -
Constructor Summary
ConstructorsModifierConstructorDescriptionField(String name, byte[] value, int offset, int length, IndexableFieldType type) Create field with binary value.Field(String name, byte[] value, IndexableFieldType type) Create field with binary value.Field(String name, Reader reader, IndexableFieldType type) Create field with Reader value.Field(String name, CharSequence value, IndexableFieldType type) Create field with String value.Field(String name, TokenStream tokenStream, IndexableFieldType type) Create field with TokenStream value.protectedField(String name, IndexableFieldType type) Expert: creates a field with no initial value.Field(String name, BytesRef bytes, IndexableFieldType type) Create field with binary value. -
Method Summary
Modifier and TypeMethodDescriptionNon-null if this field has a binary valueReturns theFieldTypefor this field.Non-null if this field has a string valueDescribes how this field should be inverted.name()Field nameNon-null if this field has a numeric valueThe value of the field as a Reader, or null.voidsetBytesValue(byte[] value) Expert: change the value of this field.voidsetBytesValue(BytesRef value) Expert: change the value of this field.voidsetByteValue(byte value) Expert: change the value of this field.voidsetDoubleValue(double value) Expert: change the value of this field.voidsetFloatValue(float value) Expert: change the value of this field.voidsetIntValue(int value) Expert: change the value of this field.voidsetLongValue(long value) Expert: change the value of this field.voidsetReaderValue(Reader value) Expert: change the value of this field.voidsetShortValue(short value) Expert: change the value of this field.voidsetStringValue(String value) Expert: change the value of this field.voidsetTokenStream(TokenStream tokenStream) Expert: sets the token stream to be used for indexing.Stored value.The value of the field as a String, or null.tokenStream(Analyzer analyzer, TokenStream reuse) Creates the TokenStream used for indexing this field.The TokenStream for this field to be used when indexing, or null.toString()Prints a Field for human consumption.
-
Field Details
-
type
Field's type -
name
Field's name -
fieldsData
Field's value
-
-
Constructor Details
-
Field
Expert: creates a field with no initial value. This is intended to be used by customFieldsub-classes with pre-configuredIndexableFieldTypes.- Parameters:
name- field nametype- field type- Throws:
IllegalArgumentException- if either the name or type is null.
-
Field
Create field with Reader value.- Parameters:
name- field namereader- reader valuetype- 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.NullPointerException- if the reader is null
-
Field
Create field with TokenStream value.- Parameters:
name- field nametokenStream- TokenStream valuetype- 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
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 namevalue- 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
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 namevalue- byte array pointing to binary content (not copied)offset- starting position of the byte arraylength- valid length of the byte arraytype- field type- Throws:
IllegalArgumentException- if the field name, value or type is null, or the field's type is indexed().
-
Field
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 namebytes- 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
Create field with String value.- Parameters:
name- field namevalue- string valuetype- 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 Details
-
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:
stringValuein interfaceIndexableField
-
getCharSequenceValue
Description copied from interface:IndexableFieldNon-null if this field has a string value- Specified by:
getCharSequenceValuein interfaceIndexableField
-
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:
readerValuein interfaceIndexableField
-
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
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 singleDocumentinstance is re-used as well. This helps most on small documents.Each Field instance should only be used once within a single
Documentinstance. See ImproveIndexingSpeed for details. -
setReaderValue
Expert: change the value of this field. SeesetStringValue(String). -
setBytesValue
public void setBytesValue(byte[] value) Expert: change the value of this field. SeesetStringValue(String). -
setBytesValue
Expert: change the value of this field. SeesetStringValue(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. SeesetStringValue(String). -
setShortValue
public void setShortValue(short value) Expert: change the value of this field. SeesetStringValue(String). -
setIntValue
public void setIntValue(int value) Expert: change the value of this field. SeesetStringValue(String). -
setLongValue
public void setLongValue(long value) Expert: change the value of this field. SeesetStringValue(String). -
setFloatValue
public void setFloatValue(float value) Expert: change the value of this field. SeesetStringValue(String). -
setDoubleValue
public void setDoubleValue(double value) Expert: change the value of this field. SeesetStringValue(String). -
setTokenStream
Expert: sets the token stream to be used for indexing. -
name
Description copied from interface:IndexableFieldField name- Specified by:
namein interfaceIndexableField
-
numericValue
Description copied from interface:IndexableFieldNon-null if this field has a numeric value- Specified by:
numericValuein interfaceIndexableField
-
binaryValue
Description copied from interface:IndexableFieldNon-null if this field has a binary value- Specified by:
binaryValuein interfaceIndexableField
-
toString
Prints a Field for human consumption. -
fieldType
Returns theFieldTypefor this field.- Specified by:
fieldTypein interfaceIndexableField
-
invertableType
Description copied from interface:IndexableFieldDescribes how this field should be inverted. This must return a non-null value if the field indexes terms and postings.- Specified by:
invertableTypein interfaceIndexableField
-
tokenStream
Description copied from interface:IndexableFieldCreates the TokenStream used for indexing this field. If appropriate, implementations should use the given Analyzer to create the TokenStreams.- Specified by:
tokenStreamin interfaceIndexableField- Parameters:
analyzer- Analyzer that should be used to create the TokenStreams fromreuse- 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
Description copied from interface:IndexableFieldStored value. This method is called to populate stored fields and must return a non-null value if the field stored.- Specified by:
storedValuein interfaceIndexableField
-