org.apache.lucene.document

Class Field

public final class Field extends AbstractField implements Fieldable, 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.
Nested Class Summary
static classField.Index
Specifies whether and how a field should be indexed.
static classField.Store
Specifies whether and how a field should be stored.
static classField.TermVector
Specifies whether and how a field should have term vectors.
Constructor Summary
Field(String name, 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(String name, 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(String name, Reader reader)
Create a tokenized and indexed field that is not stored.
Field(String name, Reader reader, Field.TermVector termVector)
Create a tokenized and indexed field that is not stored, optionally with storing term vectors.
Field(String name, TokenStream tokenStream)
Create a tokenized and indexed field that is not stored.
Field(String name, TokenStream tokenStream, Field.TermVector termVector)
Create a tokenized and indexed field that is not stored, optionally with storing term vectors.
Field(String name, byte[] value, Field.Store store)
Create a stored field with binary value.
Method Summary
byte[]binaryValue()
The value of the field in Binary, or null.
ReaderreaderValue()
The value of the field as a Reader, or null.
StringstringValue()
The value of the field as a String, or null.
TokenStreamtokenStreamValue()
The value of the field as a TokesStream, or null.

Constructor Detail

Field

public Field(String name, 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 field value The string to process store Whether value should be stored in the index index Whether the field should be indexed, and if so, if it should be tokenized before indexing

Throws: NullPointerException if name or value is null IllegalArgumentException if the field is neither stored nor indexed

Field

public Field(String name, 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 field value The string to process store Whether value should be stored in the index index Whether the field should be indexed, and if so, if it should be tokenized before indexing termVector Whether term vector should be stored

Throws: NullPointerException if name or value is null IllegalArgumentException in any of the following situations:

Field

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 addDocument has been called.

Parameters: name The name of the field reader The reader with the content

Throws: NullPointerException if name or reader is null

Field

public Field(String name, 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 until addDocument has been called.

Parameters: name The name of the field reader The reader with the content termVector Whether term vector should be stored

Throws: NullPointerException if name or reader is null

Field

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 addDocument has been called.

Parameters: name The name of the field tokenStream The TokenStream with the content

Throws: NullPointerException if name or tokenStream is null

Field

public Field(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 until addDocument has been called.

Parameters: name The name of the field tokenStream The TokenStream with the content termVector Whether term vector should be stored

Throws: NullPointerException if name or tokenStream is null

Field

public Field(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 field value The binary value store How value should be stored (compressed or not)

Throws: IllegalArgumentException if store is Store.NO

Method Detail

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.

readerValue

public 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.

stringValue

public 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.

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.
Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.