|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectit.unimi.dsi.fastutil.ints.AbstractIntIterator
it.unimi.dsi.mg4j.search.AbstractDocumentIterator
it.unimi.dsi.mg4j.search.AbstractCompositeDocumentIterator
it.unimi.dsi.mg4j.search.AbstractUnionDocumentIterator
it.unimi.dsi.mg4j.index.MultiTermIndexIterator
public class MultiTermIndexIterator
A virtual index iterator that merges several component index iterators.
This class adds to AbstractUnionDocumentIterator
an interval iterator generating the OR of the intervals returned for each of the documents involved.
The main difference with an OrDocumentIterator built on the same array of component iterators
is that this class implements IndexIterator and hence provides a count() (the sum
of counts of those component iterators positioned on the current document) and a frequency(). The
latter is by default the maximum frequency of a component iterator, but it can be set
at construction time.
The main raison d'être of this class is support for query expansion: a blind application
of OrDocumentIterator to an array of index iterators would mislead scorers such as BM25Scorer
because low-frequency terms (e.g., hapax legomena) would be responsible for most of the score.
Note that DocumentIteratorVisitor has a visit method for generic index iterator
and a visit method for instances of this class.
This approach provides additional flexibility—a scorer, for instance, might treat an instance of
this class as a standard IndexIterator, or it might choose to query which terms actually appear
and do something more sophisticated (for instance, using weights).
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class it.unimi.dsi.mg4j.search.AbstractCompositeDocumentIterator |
|---|
AbstractCompositeDocumentIterator.AbstractCompositeIndexIntervalIterator, AbstractCompositeDocumentIterator.AbstractCompositeIntervalIterator |
| Nested classes/interfaces inherited from class it.unimi.dsi.mg4j.search.AbstractDocumentIterator |
|---|
AbstractDocumentIterator.AbstractIntervalIterator |
| Field Summary | |
|---|---|
protected int |
id
The id of this iterator. |
protected String |
term
The term of this iterator. |
| Fields inherited from class it.unimi.dsi.mg4j.search.AbstractUnionDocumentIterator |
|---|
front, frontSize, queue, refArray |
| Fields inherited from class it.unimi.dsi.mg4j.search.AbstractCompositeDocumentIterator |
|---|
documentIterator, indexIterator, indices, n, soleIndex |
| Fields inherited from class it.unimi.dsi.mg4j.search.AbstractDocumentIterator |
|---|
ahead, curr, weight |
| Fields inherited from interface it.unimi.dsi.mg4j.search.DocumentIterator |
|---|
END_OF_LIST |
| Constructor Summary | |
|---|---|
protected |
MultiTermIndexIterator(int defaultFrequency,
IndexIterator... indexIterator)
Creates a new document iterator that merges the given array of iterators. |
| Method Summary | ||
|---|---|---|
|
accept(DocumentIteratorVisitor<T> visitor)
Accepts a visitor. |
|
|
acceptDeep(DocumentIteratorVisitor<T> visitor)
|
|
|
acceptDeepOnTruePaths(DocumentIteratorVisitor<T> visitor)
|
|
|
acceptOnTruePaths(DocumentIteratorVisitor<T> visitor)
Invokes AbstractUnionDocumentIterator.acceptOnTruePaths(DocumentIteratorVisitor) only on component
iterators positioned on the current document. |
|
int |
count()
The count is the sum of counts of those component iterators positioned on the current document. |
|
int |
frequency()
The frequency is either the default frequency set at construction time, or the maximum frequency of the component iterators. |
|
int |
front(IndexIterator[] indexIterator)
Fills the given array with the index iterators composing the current front. |
|
protected IntervalIterator |
getComposedIntervalIterator(Index index)
|
|
static IndexIterator |
getInstance(Index index,
IndexIterator... indexIterator)
Returns an index iterator that merges the given array of iterators. |
|
static IndexIterator |
getInstance(IndexIterator... indexIterator)
Returns an index iterator that merges the given array of iterators. |
|
static IndexIterator |
getInstance(int defaultFrequency,
Index index,
IndexIterator... indexIterator)
Returns an index iterator that merges the given array of iterators. |
|
static IndexIterator |
getInstance(int defaultFrequency,
IndexIterator... indexIterator)
Returns an index iterator that merges the given array of iterators. |
|
int |
id()
Returns the id of this index iterator. |
|
IndexIterator |
id(int id)
Sets the id of this index iterator. |
|
Index |
index()
Returns the index over which this iterator is built. |
|
protected int |
nextDocumentInternal()
|
|
Payload |
payload()
This method is not implemented by this class. |
|
int[] |
positionArray()
Returns the positions at which the term appears in the current document in an array. |
|
IntIterator |
positions()
Returns the positions at which the term appears in the current document. |
|
int |
positions(int[] position)
Stores the positions at which the term appears in the current document in a given array. |
|
int |
skipTo(int n)
Skips all documents smaller than n. |
|
String |
term()
Returns the term whose inverted list is returned by this index iterator. |
|
IndexIterator |
term(CharSequence term)
Sets the term whose inverted list is returned by this index iterator. |
|
int |
termNumber()
Returns the number of the term whose inverted list is returned by this index iterator. |
|
IndexIterator |
weight(double weight)
Sets the weight of this index iterator. |
|
| Methods inherited from class it.unimi.dsi.mg4j.search.AbstractUnionDocumentIterator |
|---|
computeFront, intervalIterator, intervalIterators |
| Methods inherited from class it.unimi.dsi.mg4j.search.AbstractCompositeDocumentIterator |
|---|
dispose, indices, intervalIterator, toString |
| Methods inherited from class it.unimi.dsi.mg4j.search.AbstractDocumentIterator |
|---|
document, ensureOnADocument, fromNextDocument, hasNext, iterator, nextDocument, nextInt, toNextDocument, weight |
| Methods inherited from class it.unimi.dsi.fastutil.ints.AbstractIntIterator |
|---|
next, remove, skip |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface it.unimi.dsi.mg4j.search.DocumentIterator |
|---|
dispose, document, indices, intervalIterator, intervalIterator, intervalIterators, iterator, nextDocument, nextInt, weight |
| Methods inherited from interface it.unimi.dsi.fastutil.ints.IntIterator |
|---|
skip |
| Methods inherited from interface java.util.Iterator |
|---|
hasNext, next, remove |
| Field Detail |
|---|
protected String term
protected int id
| Constructor Detail |
|---|
protected MultiTermIndexIterator(int defaultFrequency,
IndexIterator... indexIterator)
throws IOException
defaultFrequency - the default term frequency (or Integer.MIN_VALUE for the max).indexIterator - the iterators to be joined.
IOException| Method Detail |
|---|
public static IndexIterator getInstance(IndexIterator... indexIterator)
throws IOException
index() will return the result of the same method on the first iterator.
indexIterator - the iterators to be joined (at least one).
IllegalArgumentException - if no iterators were provided.
IOException
public static IndexIterator getInstance(Index index,
IndexIterator... indexIterator)
throws IOException
Note that the special case of the empty and of the singleton arrays
are handled efficiently. The frequency is computed as a max, and
index() will return index.
index - the index that wil be returned by index().indexIterator - the iterators to be joined.
IOException
public static IndexIterator getInstance(int defaultFrequency,
IndexIterator... indexIterator)
throws IOException
defaultFrequency - the default term frequency (or Integer.MIN_VALUE for the max).indexIterator - the iterators to be joined (at least one).
IllegalArgumentException - if no iterators were provided, or they run on different indices.
IOException
public static IndexIterator getInstance(int defaultFrequency,
Index index,
IndexIterator... indexIterator)
throws IOException
Note that the special case of the empty and of the singleton arrays are handled efficiently.
defaultFrequency - the default term frequency (or Integer.MIN_VALUE for the max).index - the index that wil be returned by index().indexIterator - the iterators to be joined.
IllegalArgumentException - if there is some iterator on an index different from index.
IOExceptionprotected IntervalIterator getComposedIntervalIterator(Index index)
getComposedIntervalIterator in class AbstractUnionDocumentIterator
public int skipTo(int n)
throws IOException
DocumentIteratorn. If Iterator.hasNext() has been called returning
true but DocumentIterator.nextDocument() has not been called afterwards, then a call
to DocumentIterator.skipTo(int) will be implicitly preceded by
a call to DocumentIterator.nextDocument() (the only consequence is that skipping to the current
document after a call to Iterator.hasNext() will return the next document).
Define the current document k associated with this document iterator
as follows:
DocumentIterator.nextDocument() and this method have never been called;
DocumentIterator.END_OF_LIST, if a call to this method returned DocumentIterator.END_OF_LIST, or
DocumentIterator.nextDocument() returned -1;
DocumentIterator.nextDocument() or this method, otherwise.
If k is larger than or equal to n, then
this method does nothing and returns k. Otherwise, a
call to this method is equivalent to
while( ( k = nextDocument() ) < n && k != -1 ); return k == -1 ? END_OF_LIST : k;
Thus, when a result k ≠ DocumentIterator.END_OF_LIST
is returned, the state of this iterator
will be exactly the same as after a call to DocumentIterator.nextDocument()
that returned k.
In particular, the first document larger than or equal to n (when returned
by this method) will not be returned by the next call to
DocumentIterator.nextDocument().
skipTo in interface DocumentIteratorskipTo in class AbstractUnionDocumentIteratorn - a document pointer.
n if available, DocumentIterator.END_OF_LIST
otherwise.
IOException
protected int nextDocumentInternal()
throws IOException
nextDocumentInternal in class AbstractUnionDocumentIteratorIOException
public int count()
throws IOException
count in interface IndexIteratorIOExceptionpublic int front(IndexIterator[] indexIterator)
This method is essentially a safe exposure of the front of the queue
merging the component index iterators.
After a call to AbstractDocumentIterator.nextDocument(), you can use this method to know
which terms actually appear in the current document. You can use the public
field AbstractCompositeDocumentIterator.n to size the argument
array appropriately.
indexIterator - an array, at least large as the number of component index iterators,
that will be partially filled with the index iterators corresponding to terms appearing in the current document.
indexIterator.
public int frequency()
throws IOException
frequency in interface IndexIteratorIOExceptionpublic IndexIterator term(CharSequence term)
IndexIteratorUsually, the term is automatically set by Index.documents(CharSequence)
or by IndexReader.documents(CharSequence), but you can
use this method to ensure that IndexIterator.term() doesn't throw
an exception.
term in interface IndexIteratorterm - a character sequence (that will be defensively copied)
that will be assumed to be the term whose inverted list is returned by this index iterator.
public String term()
IndexIteratorUsually, the term is automatically set by IndexReader.documents(CharSequence) or IndexReader.documents(int), but you can
supply your own term with IndexIterator.term(CharSequence).
term in interface IndexIteratorIndexIterator.termNumber()public int termNumber()
IndexIteratorUsually, the term number is automatically set by IndexReader.documents(CharSequence) or IndexReader.documents(int).
termNumber in interface IndexIteratorIndexIterator.term()public IndexIterator id(int id)
IndexIteratorThe id is an integer associated with each index iterator. It has no specific semantics, and can be used differently in different contexts. A typical usage pattern, for instance, is using it to assign a unique number to the index iterators contained in a composite document iterator (say, numbering consecutively the leaves of the composite).
id in interface IndexIteratorid - the new id for this index iterator.
public int id()
IndexIterator
id in interface IndexIteratorIndexIterator.id(int)public Index index()
IndexIterator
index in interface IndexIteratorpublic Payload payload()
payload in interface IndexIterator
public int[] positionArray()
throws IOException
IndexIteratorImplementations are allowed to return the same array across different calls to this method.
positionArray in interface IndexIteratorIOException
public IntIterator positions()
throws IOException
IndexIterator
positions in interface IndexIteratorIOException
public int positions(int[] position)
throws IOException
IndexIteratorIf the array is not large enough (i.e., it does not contain IndexIterator.count() elements),
this method will return a negative number (the opposite of the count).
positions in interface IndexIteratorposition - an array that will be used to store positions.
positions cannot
hold all positions.
IOExceptionpublic IndexIterator weight(double weight)
DocumentIterator
weight in interface IndexIteratorweight in interface DocumentIteratorweight in class AbstractDocumentIteratorweight - the weight of this index iterator.
DocumentIterator.weight(double)
public <T> T accept(DocumentIteratorVisitor<T> visitor)
throws IOException
DocumentIteratorA document iterator is usually structured as composite,
with operators as internal nodes and IndexIterators
as leaves. This method implements the visitor pattern.
accept in interface DocumentIteratoraccept in class AbstractCompositeDocumentIteratorvisitor - the visitor.
null if the visit was interrupted.
IOException
public <T> T acceptOnTruePaths(DocumentIteratorVisitor<T> visitor)
throws IOException
AbstractUnionDocumentIteratorAbstractUnionDocumentIterator.acceptOnTruePaths(DocumentIteratorVisitor) only on component
iterators positioned on the current document.
acceptOnTruePaths in interface DocumentIteratoracceptOnTruePaths in class AbstractUnionDocumentIteratorvisitor - a visitor.
IOExceptionDocumentIterator.accept(DocumentIteratorVisitor),
CounterCollectionVisitor
public <T> T acceptDeep(DocumentIteratorVisitor<T> visitor)
throws IOException
IOException
public <T> T acceptDeepOnTruePaths(DocumentIteratorVisitor<T> visitor)
throws IOException
IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||