public class Field extends Object implements IndexableField
IntField, LongField, FloatField, DoubleField, ByteDocValuesField, ShortDocValuesField, IntDocValuesField, LongDocValuesField, PackedLongDocValuesField,
FloatDocValuesField, DoubleDocValuesField, SortedBytesDocValuesField,
DerefBytesDocValuesField, StraightBytesDocValuesField, StringField, TextField, StoredField.
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.| Modifier and Type | Class and Description |
|---|---|
static class |
Field.Index
Deprecated.
This is here only to ease transition from
the pre-4.0 APIs.
|
static class |
Field.Store
Specifies whether a field's value should be stored.
|
static class |
Field.TermVector
Deprecated.
This is here only to ease transition from
the pre-4.0 APIs.
|
| Modifier and Type | Field and Description |
|---|---|
protected float |
boost |
protected Object |
fieldsData |
protected String |
name |
protected NumericTokenStream |
numericTokenStream |
protected TokenStream |
tokenStream |
protected FieldType |
type |
| Modifier | Constructor and Description |
|---|---|
|
Field(String name,
byte[] value)
Deprecated.
Use
StoredField instead. |
|
Field(String name,
byte[] value,
FieldType type)
Create field with binary value.
|
|
Field(String name,
byte[] value,
int offset,
int length)
Deprecated.
Use
StoredField instead. |
|
Field(String name,
byte[] value,
int offset,
int length,
FieldType type)
Create field with binary value.
|
|
Field(String name,
BytesRef bytes,
FieldType type)
Create field with binary value.
|
protected |
Field(String name,
FieldType type) |
|
Field(String name,
Reader reader)
Deprecated.
Use
TextField instead. |
|
Field(String name,
Reader reader,
Field.TermVector termVector)
Deprecated.
Use
TextField instead. |
|
Field(String name,
Reader reader,
FieldType type)
Create field with Reader value.
|
|
Field(String name,
String value,
Field.Store store,
Field.Index index)
Deprecated.
Use
StringField, TextField instead. |
|
Field(String name,
String value,
Field.Store store,
Field.Index index,
Field.TermVector termVector)
Deprecated.
Use
StringField, TextField instead. |
|
Field(String name,
String value,
FieldType type)
Create field with String value.
|
|
Field(String name,
TokenStream tokenStream)
Deprecated.
Use
TextField instead |
|
Field(String name,
TokenStream tokenStream,
Field.TermVector termVector)
Deprecated.
Use
TextField instead |
|
Field(String name,
TokenStream tokenStream,
FieldType type)
Create field with TokenStream value.
|
| Modifier and Type | Method and Description |
|---|---|
BytesRef |
binaryValue()
Non-null if this field has a binary value
|
float |
boost()
Field boost (you must pre-multiply in any doc boost).
|
FieldType |
fieldType()
Returns the
FieldType for this field. |
String |
name()
Field name
|
Number |
numericValue()
Non-null if this field has a numeric value
|
Reader |
readerValue()
The value of the field as a Reader, or null.
|
void |
setBoost(float boost)
Sets the boost factor hits on this field.
|
void |
setBytesValue(byte[] value)
Expert: change the value of this field.
|
void |
setBytesValue(BytesRef value)
Expert: change the value of this field.
|
void |
setByteValue(byte value) |
void |
setDoubleValue(double value) |
void |
setFloatValue(float value) |
void |
setIntValue(int value) |
void |
setLongValue(long value) |
void |
setReaderValue(Reader value)
Expert: change the value of this field.
|
void |
setShortValue(short value) |
void |
setStringValue(String value)
Expert: change the value of this field.
|
void |
setTokenStream(TokenStream tokenStream)
Expert: sets the token stream to be used for indexing and causes
isIndexed() and isTokenized() to return true.
|
String |
stringValue()
The value of the field as a String, or null.
|
TokenStream |
tokenStream(Analyzer analyzer)
Creates the TokenStream used for indexing this field.
|
TokenStream |
tokenStreamValue()
The TokesStream for this field to be used when indexing, or null.
|
String |
toString()
Prints a Field for human consumption.
|
static 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.
|
protected final FieldType type
protected final String name
protected Object fieldsData
protected TokenStream tokenStream
protected transient NumericTokenStream numericTokenStream
protected float boost
public Field(String name, TokenStream tokenStream, FieldType type)
public Field(String name, byte[] value, int offset, int length, FieldType type)
public Field(String name, BytesRef bytes, FieldType type)
NOTE: the provided BytesRef is not copied so be sure not to change it until you're done with this field.
@Deprecated public Field(String name, String value, Field.Store store, Field.Index index)
name - The name of the fieldvalue - The string to processstore - Whether value should be stored in the indexindex - Whether the field should be indexed, and if so, if it should
be tokenized before indexingNullPointerException - if name or value is nullIllegalArgumentException - if the field is neither stored nor indexed@Deprecated public Field(String name, String value, Field.Store store, Field.Index index, Field.TermVector termVector)
name - The name of the fieldvalue - The string to processstore - Whether value should 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 storedNullPointerException - if name or value is nullIllegalArgumentException - in any of the following situations:
TermVector.YES@Deprecated public Field(String name, Reader reader)
TextField instead.IndexWriter.addDocument(java.lang.Iterable<? extends org.apache.lucene.index.IndexableField>)
has been called.name - The name of the fieldreader - The reader with the contentNullPointerException - if name or reader is null@Deprecated public Field(String name, Reader reader, Field.TermVector termVector)
TextField instead.IndexWriter.addDocument(java.lang.Iterable<? extends org.apache.lucene.index.IndexableField>)
has been called.name - The name of the fieldreader - The reader with the contenttermVector - Whether term vector should be storedNullPointerException - if name or reader is null@Deprecated public Field(String name, TokenStream tokenStream)
TextField insteadIndexWriter.addDocument(java.lang.Iterable<? extends org.apache.lucene.index.IndexableField>)
has been called.name - The name of the fieldtokenStream - The TokenStream with the contentNullPointerException - if name or tokenStream is null@Deprecated public Field(String name, TokenStream tokenStream, Field.TermVector termVector)
TextField insteadIndexWriter.addDocument(java.lang.Iterable<? extends org.apache.lucene.index.IndexableField>)
has been called.name - The name of the fieldtokenStream - The TokenStream with the contenttermVector - Whether term vector should be storedNullPointerException - if name or tokenStream is null@Deprecated public Field(String name, byte[] value)
StoredField instead.name - The name of the fieldvalue - The binary value@Deprecated public Field(String name, byte[] value, int offset, int length)
StoredField instead.name - The name of the fieldvalue - The binary valueoffset - Starting offset in value where this Field's bytes arelength - Number of bytes to use for this Field, starting at offsetpublic String stringValue()
stringValue in interface IndexableFieldpublic Reader readerValue()
readerValue in interface IndexableFieldpublic TokenStream tokenStreamValue()
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.
public void setReaderValue(Reader value)
setStringValue(String).public void setBytesValue(byte[] value)
setStringValue(String).public void setBytesValue(BytesRef value)
setStringValue(String).
NOTE: the provided BytesRef is not copied so be sure not to change it until you're done with this field.
public void setByteValue(byte value)
public void setShortValue(short value)
public void setIntValue(int value)
public void setLongValue(long value)
public void setFloatValue(float value)
public void setDoubleValue(double value)
public void setTokenStream(TokenStream tokenStream)
public String name()
IndexableFieldname in interface IndexableFieldpublic float boost()
IndexableFieldboost in interface IndexableFieldpublic void setBoost(float boost)
The boost is used to compute the norm factor for the field. By
default, in the Similarity.computeNorm(FieldInvertState, Norm) method,
the boost value is multiplied by the length normalization factor and then
rounded by TFIDFSimilarity.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.
public Number numericValue()
IndexableFieldnumericValue in interface IndexableFieldpublic BytesRef binaryValue()
IndexableFieldbinaryValue in interface IndexableFieldpublic String toString()
public FieldType fieldType()
FieldType for this field.fieldType in interface IndexableFieldpublic TokenStream tokenStream(Analyzer analyzer) throws IOException
tokenStream in interface IndexableFieldanalyzer - Analyzer that should be used to create the TokenStreams fromIOException - Can be thrown while creating the TokenStream@Deprecated public static final FieldType translateFieldType(Field.Store store, Field.Index index, Field.TermVector termVector)
FieldType
approach.Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.