org.apache.lucene.document
Class Field
- java.lang.Object
-
- org.apache.lucene.document.AbstractField
-
- org.apache.lucene.document.Field
-
- All Implemented Interfaces:
- java.io.Serializable, Fieldable
public final class Field extends AbstractField implements Fieldable, java.io.Serializable
A field is a section of a Document. Each field has two parts, a name and a value. Values may be free text, provided as a String or as a Reader, or they may be atomic keywords, which are not further processed. Such keywords may be used to represent dates, urls, etc. Fields are optionally stored in the index, so that they may be returned with hits on the document.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classField.IndexSpecifies whether and how a field should be indexed.static classField.StoreSpecifies whether and how a field should be stored.static classField.TermVectorSpecifies whether and how a field should have term vectors.
-
Constructor Summary
Constructors Constructor and Description Field(java.lang.String name, byte[] value, Field.Store store)Create a stored field with binary value.Field(java.lang.String name, java.io.Reader reader)Create a tokenized and indexed field that is not stored.Field(java.lang.String name, java.io.Reader reader, Field.TermVector termVector)Create a tokenized and indexed field that is not stored, optionally with storing term vectors.Field(java.lang.String name, java.lang.String value, Field.Store store, Field.Index index)Create a field by specifying its name, value and how it will be saved in the index.Field(java.lang.String name, java.lang.String value, Field.Store store, Field.Index index, Field.TermVector termVector)Create a field by specifying its name, value and how it will be saved in the index.Field(java.lang.String name, TokenStream tokenStream)Create a tokenized and indexed field that is not stored.Field(java.lang.String name, TokenStream tokenStream, Field.TermVector termVector)Create a tokenized and indexed field that is not stored, optionally with storing term vectors.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description byte[]binaryValue()The value of the field in Binary, or null.java.io.ReaderreaderValue()The value of the field as a Reader, or null.voidsetValue(byte[] value)Expert: change the value of this field.voidsetValue(java.io.Reader value)Expert: change the value of this field.voidsetValue(java.lang.String value)Expert: change the value of this field.voidsetValue(TokenStream value)Expert: change the value of this field.java.lang.StringstringValue()The value of the field as a String, or null.TokenStreamtokenStreamValue()The value of the field as a TokesStream, or null.-
Methods inherited from class org.apache.lucene.document.AbstractField
getBoost, getOmitNorms, isBinary, isCompressed, isIndexed, isLazy, isStored, isStoreOffsetWithTermVector, isStorePositionWithTermVector, isTermVectorStored, isTokenized, name, setBoost, setOmitNorms, toString
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.lucene.document.Fieldable
getBoost, getOmitNorms, isBinary, isCompressed, isIndexed, isLazy, isStored, isStoreOffsetWithTermVector, isStorePositionWithTermVector, isTermVectorStored, isTokenized, name, setBoost, setOmitNorms
-
-
-
-
Constructor Detail
-
Field
public Field(java.lang.String name, java.lang.String value, Field.Store store, Field.Index 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.- Parameters:
name- The name of the fieldvalue- The string to processstore- Whethervalueshould be stored in the indexindex- Whether the field should be indexed, and if so, if it should be tokenized before indexing- Throws:
java.lang.NullPointerException- if name or value isnulljava.lang.IllegalArgumentException- if the field is neither stored nor indexed
-
Field
public Field(java.lang.String name, java.lang.String value, Field.Store store, Field.Index index, Field.TermVector termVector)Create a field by specifying its name, value and how it will be saved in the index.- Parameters:
name- The name of the fieldvalue- The string to processstore- Whethervalueshould be stored in the indexindex- Whether the field should be indexed, and if so, if it should be tokenized before indexingtermVector- Whether term vector should be stored- Throws:
java.lang.NullPointerException- if name or value isnulljava.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
public Field(java.lang.String name, java.io.Reader reader)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 untilIndexWriter.addDocument(Document)has been called.- Parameters:
name- The name of the fieldreader- The reader with the content- Throws:
java.lang.NullPointerException- if name or reader isnull
-
Field
public Field(java.lang.String name, java.io.Reader reader, Field.TermVector termVector)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 untilIndexWriter.addDocument(Document)has been called.- Parameters:
name- The name of the fieldreader- The reader with the contenttermVector- Whether term vector should be stored- Throws:
java.lang.NullPointerException- if name or reader isnull
-
Field
public Field(java.lang.String name, TokenStream 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 untilIndexWriter.addDocument(Document)has been called.- Parameters:
name- The name of the fieldtokenStream- The TokenStream with the content- Throws:
java.lang.NullPointerException- if name or tokenStream isnull
-
Field
public Field(java.lang.String name, TokenStream tokenStream, Field.TermVector 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 untilIndexWriter.addDocument(Document)has been called.- Parameters:
name- The name of the fieldtokenStream- The TokenStream with the contenttermVector- Whether term vector should be stored- Throws:
java.lang.NullPointerException- if name or tokenStream isnull
-
Field
public Field(java.lang.String name, byte[] value, Field.Store store)Create a stored field with binary value. Optionally the value may be compressed.- Parameters:
name- The name of the fieldvalue- The binary valuestore- Howvalueshould be stored (compressed or not)- Throws:
java.lang.IllegalArgumentException- if store isStore.NO
-
-
Method Detail
-
stringValue
public java.lang.String stringValue()
The value of the field as a String, or null. If null, the Reader value, binary value, or TokenStream value is used. Exactly one of stringValue(), readerValue(), binaryValue(), and tokenStreamValue() must be set.- Specified by:
stringValuein interfaceFieldable
-
readerValue
public java.io.Reader readerValue()
The value of the field as a Reader, or null. If null, the String value, binary value, or TokenStream value is used. Exactly one of stringValue(), readerValue(), binaryValue(), and tokenStreamValue() must be set.- Specified by:
readerValuein interfaceFieldable
-
binaryValue
public byte[] binaryValue()
The value of the field in Binary, or null. If null, the Reader value, String value, or TokenStream value is used. Exactly one of stringValue(), readerValue(), binaryValue(), and tokenStreamValue() must be set.- Specified by:
binaryValuein interfaceFieldable
-
tokenStreamValue
public TokenStream tokenStreamValue()
The value of the field as a TokesStream, or null. If null, the Reader value, String value, or binary value is used. Exactly one of stringValue(), readerValue(), binaryValue(), and tokenStreamValue() must be set.- Specified by:
tokenStreamValuein interfaceFieldable
-
setValue
public void setValue(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
Documentinstance is re-used as well. This helps most on small documents.Note that you should only use this method after the Field has been consumed (ie, the
Documentcontaining this Field has been added to the index). Also, each Field instance should only be used once within a singleDocumentinstance. See ImproveIndexingSpeed for details.
-
setValue
public void setValue(java.io.Reader value)
Expert: change the value of this field. See setValue(String).
-
setValue
public void setValue(byte[] value)
Expert: change the value of this field. See setValue(String).
-
setValue
public void setValue(TokenStream value)
Expert: change the value of this field. See setValue(String).
-
-
DataMelt 3.0 © DataMelt by jWork.ORG