An {@link it.unimi.dsi.mg4j.index.Index} contains global read-only metadata. To get actual datafrom an index, you need to get an index reader via a call to {@link Index#getReader()}. Once you have an index reader, you can ask for the {@linkplain #documents(CharSequence) documents matching a term}.
Alternatively, you can perform a read-once scan of the index calling {@link #nextIterator()}, which will return in order the {@linkplain IndexIterator index iterators} of all terms of the underlying index.More generally, {@link #nextIterator()} returns an iterator positioned at the start of the invertedlist of the term after the current one. When called just after the reader creation, it returns an index iterator for the first term.
Warning: An index reader is exactly what it looks like—a reader. It cannot be used by many threads at the same time, and all its access methods are exclusive: if you obtain a {@linkplain #documents(int) document iterator}, the previous one is no longer valid. However, you can generate many readers, and use them concurrently.
Warning: Invoking the {@link it.unimi.dsi.mg4j.search.DocumentIterator#dispose()} methodon iterators returned by an instance of this class will invoke {@link #close()} on the instance, thusmaking the instance no longer accessible. This behaviour is necessary to handle cases in which a reader is created on-the-fly just to create an iterator. @author Paolo Boldi @author Sebastiano Vigna @since 1.0
Concrete subclasses of IndexReader are usually constructed with a call to one of the static open()
methods, e.g. {@link #open(Directory,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 the static open methods that accept the boolean readOnly parameter. Such a reader has better concurrency as it's not necessary to synchronize on the isDeleted method. You must specify false if you want to make changes with the resulting IndexReader.
NOTE: {@link IndexReader} instances are completely threadsafe, meaning multiple threads can call any of its methods, concurrently. If your application requires external synchronization, you should not synchronize on the IndexReader
instance; use your own (non-Lucene) objects instead.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|