Lucene - Document Class



Document represents a virtual document with Fields where Field is an object which can contain the physical document's contents, its meta data and so on. Analyzer can understand a Document only.

Class declaration

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

public final class Document
   extends Object
      implements Iterable<IndexableField>

Class Constructors

Following table shows the class constructors for Document −

S.No. Constructor & Description
1

Document()

Constructs a new document with no fields.

S.No. Method & Description
1

final void add(IndexableField field)

Adds a field to a document.

2

void clear()

Removes all the fields from document.

3

final String get(String name)

Returns the string value of the field with the given name if any exist in this document, or null.

4

final BytesRef getBinaryValue(String name)

Returns an array of bytes for the first (or only) field that has the name specified as the method parameter.

5

final BytesRef[] getBinaryValues(String name)

Returns an array of byte arrays for of the fields that have the name specified as the method parameter.

6

final IndexableField getField(String name)

Returns a field with the given name if any exist in this document, or null.

7

final List<IndexableField> getFields()

Returns a List of all the fields in a document.

8

IndexableField[] getFields(String name)

Returns an array of IndexableFields with the given name.

9

final String[] getValues(String name)

Returns an array of values of the field specified as the method parameter.

10

Iterator<IndexableField> iterator()

Returns an iterator.

11

final void removeField(String name)

Removes field with the specified name from the document.

12

final void removeFields(String name)

Removes all fields with the given name from the document.

13

final String toString()

Prints the fields of a document for human consumption.

Methods Inherited

This class inherits methods from the following classes −

  • java.lang.Object
lucene_indexing_classes.htm
Advertisements