Fieldpublic final class Field extends Object implements SerializableA 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. |
Fields Summary |
---|
private String | name | private Object | fieldsData | private boolean | storeTermVector | private boolean | storeOffsetWithTermVector | private boolean | storePositionWithTermVector | private boolean | omitNorms | private boolean | isStored | private boolean | isIndexed | private boolean | isTokenized | private boolean | isBinary | private boolean | isCompressed | private float | boost |
Constructors Summary |
---|
public Field(String name, String value, Store store, 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.
this(name, value, store, index, TermVector.NO);
| public Field(String name, String value, Store store, Index index, TermVector termVector)Create a field by specifying its name, value and how it will
be saved in the index.
if (name == null)
throw new NullPointerException("name cannot be null");
if (value == null)
throw new NullPointerException("value cannot be null");
if (index == Index.NO && store == Store.NO)
throw new IllegalArgumentException("it doesn't make sense to have a field that "
+ "is neither indexed nor stored");
if (index == Index.NO && termVector != TermVector.NO)
throw new IllegalArgumentException("cannot store term vector information "
+ "for a field that is not indexed");
this.name = name.intern(); // field names are interned
this.fieldsData = value;
if (store == Store.YES){
this.isStored = true;
this.isCompressed = false;
}
else if (store == Store.COMPRESS) {
this.isStored = true;
this.isCompressed = true;
}
else if (store == Store.NO){
this.isStored = false;
this.isCompressed = false;
}
else
throw new IllegalArgumentException("unknown store parameter " + store);
if (index == Index.NO) {
this.isIndexed = false;
this.isTokenized = false;
} else if (index == Index.TOKENIZED) {
this.isIndexed = true;
this.isTokenized = true;
} else if (index == Index.UN_TOKENIZED) {
this.isIndexed = true;
this.isTokenized = false;
} else if (index == Index.NO_NORMS) {
this.isIndexed = true;
this.isTokenized = false;
this.omitNorms = true;
} else {
throw new IllegalArgumentException("unknown index parameter " + index);
}
this.isBinary = false;
setStoreTermVector(termVector);
| public Field(String name, Reader reader)Create a tokenized and indexed field that is not stored. Term vectors will
not be stored.
this(name, reader, TermVector.NO);
| public Field(String name, Reader reader, TermVector termVector)Create a tokenized and indexed field that is not stored, optionally with
storing term vectors.
if (name == null)
throw new NullPointerException("name cannot be null");
if (reader == null)
throw new NullPointerException("reader cannot be null");
this.name = name.intern(); // field names are interned
this.fieldsData = reader;
this.isStored = false;
this.isCompressed = false;
this.isIndexed = true;
this.isTokenized = true;
this.isBinary = false;
setStoreTermVector(termVector);
| public Field(String name, String string, boolean store, boolean index, boolean token)Create a field by specifying all parameters except for storeTermVector ,
which is set to false .
this(name, string, store, index, token, false);
| public Field(String name, byte[] value, Store store)Create a stored field with binary value. Optionally the value may be compressed.
if (name == null)
throw new IllegalArgumentException("name cannot be null");
if (value == null)
throw new IllegalArgumentException("value cannot be null");
this.name = name.intern();
this.fieldsData = value;
if (store == Store.YES){
this.isStored = true;
this.isCompressed = false;
}
else if (store == Store.COMPRESS) {
this.isStored = true;
this.isCompressed = true;
}
else if (store == Store.NO)
throw new IllegalArgumentException("binary values can't be unstored");
else
throw new IllegalArgumentException("unknown store parameter " + store);
this.isIndexed = false;
this.isTokenized = false;
this.isBinary = true;
setStoreTermVector(TermVector.NO);
| public Field(String name, String string, boolean store, boolean index, boolean token, boolean storeTermVector)
if (name == null)
throw new NullPointerException("name cannot be null");
if (string == null)
throw new NullPointerException("value cannot be null");
if (!index && storeTermVector)
throw new IllegalArgumentException("cannot store a term vector for fields that are not indexed");
this.name = name.intern(); // field names are interned
this.fieldsData = string;
this.isStored = store;
this.isIndexed = index;
this.isTokenized = token;
this.storeTermVector = storeTermVector;
|
Methods Summary |
---|
public static final org.apache.lucene.document.Field | Keyword(java.lang.String name, java.lang.String value)Constructs a String-valued Field that is not tokenized, but is indexed
and stored. Useful for non-text fields, e.g. date or url.
return new Field(name, value, true, true, false);
| public static final org.apache.lucene.document.Field | Keyword(java.lang.String name, java.util.Date value)Constructs a Date-valued Field that is not tokenized and is indexed,
and stored in the index, for return with hits.
return new Field(name, DateField.dateToString(value), true, true, false);
| public static final org.apache.lucene.document.Field | Text(java.lang.String name, java.io.Reader value)Constructs a Reader-valued Field that is tokenized and indexed, but is
not stored in the index verbatim. Useful for longer text fields, like
"body". Term vector will not be stored for this field.
return Text(name, value, false);
| public static final org.apache.lucene.document.Field | Text(java.lang.String name, java.io.Reader value, boolean storeTermVector)Constructs a Reader-valued Field that is tokenized and indexed, but is
not stored in the index verbatim. Useful for longer text fields, like
"body".
Field f = new Field(name, value);
f.storeTermVector = storeTermVector;
return f;
| public static final org.apache.lucene.document.Field | Text(java.lang.String name, java.lang.String value)Constructs a String-valued Field that is tokenized and indexed,
and is stored in the index, for return with hits. Useful for short text
fields, like "title" or "subject". Term vector will not be stored for this field.
return Text(name, value, false);
| public static final org.apache.lucene.document.Field | Text(java.lang.String name, java.lang.String value, boolean storeTermVector)Constructs a String-valued Field that is tokenized and indexed,
and is stored in the index, for return with hits. Useful for short text
fields, like "title" or "subject".
return new Field(name, value, true, true, true, storeTermVector);
| public static final org.apache.lucene.document.Field | UnIndexed(java.lang.String name, java.lang.String value)Constructs a String-valued Field that is not tokenized nor indexed,
but is stored in the index, for return with hits.
return new Field(name, value, true, false, false);
| public static final org.apache.lucene.document.Field | UnStored(java.lang.String name, java.lang.String value)Constructs a String-valued Field that is tokenized and indexed,
but that is not stored in the index. Term vector will not be stored for this field.
return UnStored(name, value, false);
| public static final org.apache.lucene.document.Field | UnStored(java.lang.String name, java.lang.String value, boolean storeTermVector)Constructs a String-valued Field that is tokenized and indexed,
but that is not stored in the index.
return new Field(name, value, false, true, true, storeTermVector);
| public byte[] | binaryValue()The value of the field in Binary, or null. If null, the Reader or
String value is used. Exactly one of stringValue(), readerValue() and
binaryValue() must be set. return fieldsData instanceof byte[] ? (byte[])fieldsData : null;
| public float | getBoost()Returns the boost factor for hits for this field.
The default value is 1.0.
Note: this value is not stored directly with the document in the index.
Documents returned from {@link IndexReader#document(int)} and
{@link Hits#doc(int)} may thus not have the same value present as when
this field was indexed.
return boost;
| public boolean | getOmitNorms()True if norms are omitted for this indexed field return omitNorms;
| public final boolean | isBinary()True iff the value of the filed is stored as binary return isBinary;
| public final boolean | isCompressed()True if the value of the field is stored and compressed within the index return isCompressed;
| public final boolean | isIndexed()True iff the value of the field is to be indexed, so that it may be
searched on. return isIndexed;
| public boolean | isStoreOffsetWithTermVector()True iff terms are stored as term vector together with their offsets
(start and end positon in source text).
return storeOffsetWithTermVector;
| public boolean | isStorePositionWithTermVector()True iff terms are stored as term vector together with their token positions.
return storePositionWithTermVector;
| public final boolean | isStored()True iff the value of the field is to be stored in the index for return
with search hits. It is an error for this to be true if a field is
Reader-valued. return isStored;
| public final boolean | isTermVectorStored()True iff the term or terms used to index this field are stored as a term
vector, available from {@link IndexReader#getTermFreqVector(int,String)}.
These methods do not provide access to the original content of the field,
only to terms used to index it. If the original content must be
preserved, use the stored attribute instead. return storeTermVector;
| public final boolean | isTokenized()True iff the value of the field should be tokenized as text prior to
indexing. Un-tokenized fields are indexed as a single word and may not be
Reader-valued. return isTokenized;
| public java.lang.String | name()Returns the name of the field as an interned string.
For example "date", "title", "body", ... return name;
| 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 binaryValue() must be set. return fieldsData instanceof Reader ? (Reader)fieldsData : null;
| public void | setBoost(float boost)Sets the boost factor hits on this field. This value will be
multiplied into the score of all hits on this this field of this
document.
The boost is multiplied by {@link Document#getBoost()} of the document
containing this field. If a document has multiple fields with the same
name, all such values are multiplied together. This product is then
multipled by the value {@link Similarity#lengthNorm(String,int)}, and
rounded by {@link Similarity#encodeNorm(float)} before it is stored in the
index. One should attempt to ensure that this product does not overflow
the range of that encoding.
this.boost = boost;
| public void | setOmitNorms(boolean omitNorms)Expert:
If set, omit normalization factors associated with this indexed field.
This effectively disables indexing boosts and length normalization for this field. this.omitNorms=omitNorms;
| private void | setStoreTermVector(org.apache.lucene.document.Field$TermVector termVector)
if (termVector == TermVector.NO) {
this.storeTermVector = false;
this.storePositionWithTermVector = false;
this.storeOffsetWithTermVector = false;
}
else if (termVector == TermVector.YES) {
this.storeTermVector = true;
this.storePositionWithTermVector = false;
this.storeOffsetWithTermVector = false;
}
else if (termVector == TermVector.WITH_POSITIONS) {
this.storeTermVector = true;
this.storePositionWithTermVector = true;
this.storeOffsetWithTermVector = false;
}
else if (termVector == TermVector.WITH_OFFSETS) {
this.storeTermVector = true;
this.storePositionWithTermVector = false;
this.storeOffsetWithTermVector = true;
}
else if (termVector == TermVector.WITH_POSITIONS_OFFSETS) {
this.storeTermVector = true;
this.storePositionWithTermVector = true;
this.storeOffsetWithTermVector = true;
}
else {
throw new IllegalArgumentException("unknown termVector parameter " + termVector);
}
| 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
binaryValue() must be set. return fieldsData instanceof String ? (String)fieldsData : null;
| public final java.lang.String | toString()Prints a Field for human consumption.
StringBuffer result = new StringBuffer();
if (isStored) {
result.append("stored");
if (isCompressed)
result.append("/compressed");
else
result.append("/uncompressed");
}
if (isIndexed) {
if (result.length() > 0)
result.append(",");
result.append("indexed");
}
if (isTokenized) {
if (result.length() > 0)
result.append(",");
result.append("tokenized");
}
if (storeTermVector) {
if (result.length() > 0)
result.append(",");
result.append("termVector");
}
if (storeOffsetWithTermVector) {
if (result.length() > 0)
result.append(",");
result.append("termVectorOffsets");
}
if (storePositionWithTermVector) {
if (result.length() > 0)
result.append(",");
result.append("termVectorPosition");
}
if (isBinary) {
if (result.length() > 0)
result.append(",");
result.append("binary");
}
if (omitNorms) {
result.append(",omitNorms");
}
result.append('<");
result.append(name);
result.append(':");
if (fieldsData != null) {
result.append(fieldsData);
}
result.append('>");
return result.toString();
|
|