Lucene - Field



Field is the lowest unit or the starting point of the indexing process. It represents the key value pair relationship where a key is used to identify the value to be indexed. Say a field used to represent contents of a document will have key as "contents" and the value may contain the part or all of the text or numeric content of the document.

Lucene can index only text or numeric contents only. This class represents the storage location of the indexes and generally it is a list of files. These files are called index files. Index files are normally created once and then used for read operation or can be deleted.

Class Declaration

Following is the declaration for org.apache.lucene.document.Field class −

public final class Field
   extends AbstractField 
      implements Fieldable, Serializable

Class Constructors

Following table shows a list of class constructors −

S.No. Constructor & Description
1

Field(String name, boolean internName, String value, Field.Store store, Field.Index index, Field.TermVector termVector)

Creates a field by specifying its name, value and how it will be saved in the index.

2

Field(String name, byte[] value)

Creates a stored field with binary value.

3

Field(String name, byte[] value, Field.Store store)

Deprecated.

4

Field(String name, byte[] value, int offset, int length)

Creates a stored field with binary value.

5

Field(String name, byte[] value, int offset, int length, Field.Store store)

Deprecated.

6

Field(String name, Reader reader)

Creates a tokenized and indexed field that is not stored.

7

Field(String name, Reader reader, Field.TermVector termVector)

Creates a tokenized and indexed field that is not stored, optionally with storing term vectors.

8

Field(String name, String value, Field.Store store, Field.Index index)

Creates a field by specifying its name, value and how it will be saved in the index.

9

Field(String name, String value, Field.Store store, Field.Index index, Field.TermVector termVector)

Creates a field by specifying its name, value and how it will be saved in the index.

10

Field(String name, TokenStream tokenStream)

Creates a tokenized and indexed field that is not stored.

11

Field(String name, TokenStream tokenStream, Field.TermVector termVector)

Creates a tokenized and indexed field that is not stored, optionally with storing term vectors.

Class Methods

The following table shows the different class methods −

S.No. Method & Description
1

void clearLock(String name)

Attempts to clear (forcefully unlock and remove) the specified lock.

2

Reader readerValue()

The value of the field as a Reader, or null.

3

void setTokenStream(TokenStream tokenStream)

Expert: sets the token stream to be used for indexing and causes isIndexed() and isTokenized() to return true.

4

void setValue(byte[] value)

Expert: changes the value of this field.

5

void setValue(byte[] value, int offset, int length)

Expert: changes the value of this field.

6

void setValue(Reader value)

Expert: changes the value of this field.

7

void setValue(String value)

Expert: changes the value of this field.

8

String stringValue()

The value of the field as a String, or null.

9

TokenStream tokenStreamValue()

The TokesStream for this field to be used when indexing, or null.

Methods Inherited

This class inherits methods from the following classes −

  • org.apache.lucene.document.AbstractField
  • java.lang.Object
lucene_indexing_classes.htm
Advertisements