IndexReader is an abstract class, providing an interface for accessing an index. Search of an index is done entirely through this abstract interface, so that any subclass which implements it is searchable.

Concrete subclasses of IndexReader are usually constructed with a call to one of the static

CopyC#
open()
methods, e.g. {@link #Open(String, boolean)}.

For efficiency, in this API documents are often referred to via document numbers, non-negative integers which each name a unique document in the index. These document numbers are ephemeral--they may change as documents are added to and deleted from an index. Clients should thus not rely on a given document having the same number between sessions.

An IndexReader can be opened on a directory for which an IndexWriter is opened already, but it cannot be used to delete documents from the index then.

NOTE: for backwards API compatibility, several methods are not listed as abstract, but have no useful implementations in this base class and instead always throw UnsupportedOperationException. Subclasses are strongly encouraged to override these methods, but in many cases may not need to.

NOTE: as of 2.4, it's possible to open a read-only IndexReader using one of the static open methods that accepts the boolean readOnly parameter. Such a reader has better concurrency as it's not necessary to synchronize on the isDeleted method. Currently the default for readOnly is false, meaning if not specified you will get a read/write IndexReader. But in 3.0 this default will change to true, meaning you must explicitly specify false if you want to make changes with the resulting IndexReader.

NOTE: {@link

} instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently. If your application requires external synchronization, you should not synchronize on the
CopyC#
IndexReader
instance; use your own (non-Lucene) objects instead.

The IndexReader..::..FieldOption type exposes the following members.

Methods

  NameDescription
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString (Overrides Object..::..ToString()()()().)

Fields

  NameDescription
Public fieldStatic memberALL
All fields
Public fieldStatic memberINDEXED
All indexed fields
Public fieldStatic memberINDEXED_NO_TERMVECTOR
All fields which are indexed but don't have termvectors enabled
Public fieldStatic memberINDEXED_WITH_TERMVECTOR
All fields which are indexed with termvectors enabled
Public fieldStatic memberOMIT_TERM_FREQ_AND_POSITIONS
All fields that omit tf
Public fieldStatic memberOMIT_TF Obsolete.
Public fieldStatic memberSTORES_PAYLOADS
All fields that store payloads
Public fieldStatic memberTERMVECTOR
All fields with termvectors enabled. Please note that only standard termvector fields are returned
Public fieldStatic memberTERMVECTOR_WITH_OFFSET
All fields with termvectors with offset values enabled
Public fieldStatic memberTERMVECTOR_WITH_POSITION
All fields with termvectors with position values enabled
Public fieldStatic memberTERMVECTOR_WITH_POSITION_OFFSET
All fields with termvectors with offset values and position values enabled
Public fieldStatic memberUNINDEXED
All fields which are not indexed

See Also