|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.lucene.document.Field
public class Field
Expert: directly create a field for a document. Most
users should use one of the sugar subclasses: IntField
, LongField
, FloatField
, DoubleField
, BinaryDocValuesField
, NumericDocValuesField
, SortedDocValuesField
, StringField
, TextField
, StoredField
.
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 | |
---|---|
static class |
Field.Index
Deprecated. This is here only to ease transition from the pre-4.0 APIs. |
static class |
Field.Store
Specifies whether and how a field should be stored. |
static class |
Field.TermVector
Deprecated. This is here only to ease transition from the pre-4.0 APIs. |
Field Summary | |
---|---|
protected float |
boost
Field's boost |
protected Object |
fieldsData
Field's value |
protected String |
name
Field's name |
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 |
protected FieldType |
type
Field's type |
Constructor Summary | |
---|---|
|
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)
Expert: creates a field with no initial value. |
|
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. |
Method Summary | |
---|---|
BytesRef |
binaryValue()
Non-null if this field has a binary value |
float |
boost()
Returns the field's index-time 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 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)
Expert: change the value of this field. |
void |
setDoubleValue(double value)
Expert: change the value of this field. |
void |
setFloatValue(float value)
Expert: change the value of this field. |
void |
setIntValue(int value)
Expert: change the value of this field. |
void |
setLongValue(long value)
Expert: change the value of this field. |
void |
setReaderValue(Reader value)
Expert: change the value of this field. |
void |
setShortValue(short value)
Expert: change the value of this field. |
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 TokenStream 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected final FieldType type
protected final String name
protected Object fieldsData
protected TokenStream tokenStream
protected float boost
boost()
Constructor Detail |
---|
protected Field(String name, FieldType type)
name
- field nametype
- field type
IllegalArgumentException
- if either the name or type
is null.public Field(String name, Reader reader, FieldType type)
name
- field namereader
- reader valuetype
- field type
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 nullpublic Field(String name, TokenStream tokenStream, FieldType type)
name
- field nametokenStream
- TokenStream valuetype
- field type
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 nullpublic Field(String name, byte[] value, FieldType type)
NOTE: the provided byte[] is not copied so be sure not to change it until you're done with this field.
name
- field namevalue
- byte array pointing to binary content (not copied)type
- field type
IllegalArgumentException
- if the field name is null,
or the field's type is indexed()
NullPointerException
- if the type is nullpublic Field(String name, byte[] value, int offset, int length, FieldType type)
NOTE: the provided byte[] is not copied so be sure not to change it until you're done with this field.
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
IllegalArgumentException
- if the field name is null,
or the field's type is indexed()
NullPointerException
- if the type is nullpublic 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.
name
- field namebytes
- BytesRef pointing to binary content (not copied)type
- field type
IllegalArgumentException
- if the field name is null,
or the field's type is indexed()
NullPointerException
- if the type is nullpublic Field(String name, String value, FieldType type)
name
- field namevalue
- string valuetype
- field type
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.
NullPointerException
- if the type is null@Deprecated public Field(String name, String value, Field.Store store, Field.Index index)
StringField
, TextField
instead.
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 indexing
NullPointerException
- if name or value is null
IllegalArgumentException
- if the field is neither stored nor indexed@Deprecated public Field(String name, String value, Field.Store store, Field.Index index, Field.TermVector termVector)
StringField
, TextField
instead.
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 stored
NullPointerException
- if name or value is null
IllegalArgumentException
- 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 content
NullPointerException
- 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 stored
NullPointerException
- if name or reader is null
@Deprecated public Field(String name, TokenStream tokenStream)
TextField
instead
IndexWriter.addDocument(java.lang.Iterable extends org.apache.lucene.index.IndexableField>)
has been called.
name
- The name of the fieldtokenStream
- The TokenStream with the content
NullPointerException
- if name or tokenStream is null
@Deprecated public Field(String name, TokenStream tokenStream, Field.TermVector termVector)
TextField
instead
IndexWriter.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 stored
NullPointerException
- 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 offsetMethod Detail |
---|
public String stringValue()
stringValue
in interface IndexableField
public Reader readerValue()
readerValue
in interface IndexableField
public 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)
setStringValue(String)
.
public void setShortValue(short value)
setStringValue(String)
.
public void setIntValue(int value)
setStringValue(String)
.
public void setLongValue(long value)
setStringValue(String)
.
public void setFloatValue(float value)
setStringValue(String)
.
public void setDoubleValue(double value)
setStringValue(String)
.
public void setTokenStream(TokenStream tokenStream)
public String name()
IndexableField
name
in interface IndexableField
public float 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 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.
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).
boost
in interface IndexableField
setBoost(float)
public void setBoost(float boost)
IllegalArgumentException
- if this field is not indexed,
or if it omits norms.boost()
public Number numericValue()
IndexableField
numericValue
in interface IndexableField
public BytesRef binaryValue()
IndexableField
binaryValue
in interface IndexableField
public String toString()
toString
in class Object
public FieldType fieldType()
FieldType
for this field.
fieldType
in interface IndexableField
public TokenStream tokenStream(Analyzer analyzer) throws IOException
IndexableField
tokenStream
in interface IndexableField
analyzer
- Analyzer that should be used to create the TokenStreams from
IOException
- Can be thrown while creating the TokenStream@Deprecated public static final FieldType translateFieldType(Field.Store store, Field.Index index, Field.TermVector termVector)
FieldType
approach.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |