org.apache.lucene.document

Class Field

Implemented Interfaces:
Fieldable, Serializable

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 class
Field.Index
Specifies whether and how a field should be indexed.
static class
Field.Store
Specifies whether and how a field should be stored.
static class
Field.TermVector
Specifies whether and how a field should have term vectors.

Field Summary

Fields inherited from class org.apache.lucene.document.AbstractField

boost, fieldsData, isBinary, isCompressed, isIndexed, isStored, isTokenized, lazy, name, omitNorms, storeOffsetWithTermVector, storePositionWithTermVector, storeTermVector

Constructor Summary

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, 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, 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.
Reader
readerValue()
The value of the field as a Reader, or null.
String
stringValue()
The value of the field as a String, or null.

Methods inherited from class org.apache.lucene.document.AbstractField

getBoost, getOmitNorms, isBinary, isCompressed, isIndexed, isLazy, isStoreOffsetWithTermVector, isStorePositionWithTermVector, isStored, isTermVectorStored, isTokenized, name, setBoost, setOmitNorms, setStoreTermVector, toString

Constructor Details

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.
Parameters:
name - The name of the field
reader - The reader with the content

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.
Parameters:
name - The name of the field
reader - The reader with the content
termVector - Whether term vector should be stored

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

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

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)

Method Details

binaryValue

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.
Specified by:
binaryValue in interface Fieldable

readerValue

public 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.
Specified by:
readerValue in interface Fieldable

stringValue

public 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.
Specified by:
stringValue in interface Fieldable

Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.