Fieldpublic final class Field extends AbstractField implements Serializable, FieldableA 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. |
Constructors Summary |
---|
public Field(String name, TokenStream tokenStream, 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 until {@link IndexWriter#addDocument(Document)}
has been called.
if (name == null)
throw new NullPointerException("name cannot be null");
if (tokenStream == null)
throw new NullPointerException("tokenStream cannot be null");
this.name = name.intern(); // field names are interned
this.fieldsData = tokenStream;
this.isStored = false;
this.isCompressed = false;
this.isIndexed = true;
this.isTokenized = true;
this.isBinary = false;
setStoreTermVector(termVector);
| 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 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 (name.length() == 0 && value.length() == 0)
throw new IllegalArgumentException("name and value cannot both be empty");
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. The Reader is read only when the Document is added to the index,
i.e. you may not close the Reader until {@link IndexWriter#addDocument(Document)}
has been called.
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. The Reader is read only when the Document is added to the index,
i.e. you may not close the Reader until {@link IndexWriter#addDocument(Document)}
has been called.
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, 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 until {@link IndexWriter#addDocument(Document)}
has been called.
this(name, tokenStream, TermVector.NO);
|
Methods Summary |
---|
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. return fieldsData instanceof byte[] ? (byte[])fieldsData : null;
| 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. return fieldsData instanceof Reader ? (Reader)fieldsData : null;
| 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.
return fieldsData instanceof String ? (String)fieldsData : null;
| public org.apache.lucene.analysis.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. return fieldsData instanceof TokenStream ? (TokenStream)fieldsData : null;
|
|