it.unimi.dsi.mg4j.index.cluster
Class DocumentalConcatenatedClusterIndexIterator

java.lang.Object
  extended by it.unimi.dsi.fastutil.ints.AbstractIntIterator
      extended by it.unimi.dsi.mg4j.search.AbstractDocumentIterator
          extended by it.unimi.dsi.mg4j.index.cluster.DocumentalConcatenatedClusterDocumentIterator
              extended by it.unimi.dsi.mg4j.index.cluster.DocumentalConcatenatedClusterIndexIterator
All Implemented Interfaces:
IntIterator, IndexIterator, DocumentIterator, Iterable<Interval>, Iterator<Integer>

public class DocumentalConcatenatedClusterIndexIterator
extends DocumentalConcatenatedClusterDocumentIterator
implements IndexIterator

An index iterator concatenating iterators from local indices.

Author:
Alessandro Arrabito, Sebastiano Vigna

Nested Class Summary
 
Nested classes/interfaces inherited from class it.unimi.dsi.mg4j.search.AbstractDocumentIterator
AbstractDocumentIterator.AbstractIntervalIterator
 
Field Summary
protected  int frequency
          The precomputed frequency.
protected  int id
          The id associated to this index iterator.
protected  DocumentalConcatenatedCluster index
          The reference index.
protected  IndexIterator[] indexIterator
          A cached copy of the iterators, to avoid type casts.
protected  String term
          The term associated to this index iterator.
 
Fields inherited from class it.unimi.dsi.mg4j.index.cluster.DocumentalConcatenatedClusterDocumentIterator
currentIterator, documentIterator, documentIteratorIndex, lastIterator, n, strategy
 
Fields inherited from class it.unimi.dsi.mg4j.search.AbstractDocumentIterator
last, next
 
Constructor Summary
DocumentalConcatenatedClusterIndexIterator(DocumentalClusterIndexReader indexReader, IndexIterator[] indexIterator, int[] usedIndex)
           
 
Method Summary
 boolean accept(DocumentIteratorVisitor visitor)
          Accepts a visitor.
 boolean acceptOnTruePaths(DocumentIteratorVisitor visitor)
          Accepts a visitor after a call to DocumentIterator.nextDocument(), limiting recursion to true paths.
 int count()
          Returns the count, that is, the number of occurrences of the term in the current document.
 int frequency()
          Returns the frequency, that is, the number of documents that will be returned by this iterator.
 int id()
          Returns the id of this index iterator.
 void id(int id)
          Sets the id of this index iterator.
 Index index()
          Returns the index over which this iterator is built.
 Payload payload()
          Returns the payload, if any, associated with the current document.
 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[] positions)
          Stores the positions at which the term appears in the current document in a given array.
 String term()
          Returns the term whose inverted list is returned by this index iterator.
 void 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.
 
Methods inherited from class it.unimi.dsi.mg4j.index.cluster.DocumentalConcatenatedClusterDocumentIterator
dispose, indices, intervalIterator, intervalIterator, intervalIterators, nextDocument, skipTo, toString
 
Methods inherited from class it.unimi.dsi.mg4j.search.AbstractDocumentIterator
document, hasNext, iterator, nextInt
 
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, skipTo
 
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntIterator
skip
 
Methods inherited from interface java.util.Iterator
hasNext, next, remove
 

Field Detail

indexIterator

protected final IndexIterator[] indexIterator
A cached copy of the iterators, to avoid type casts.


frequency

protected final int frequency
The precomputed frequency.


index

protected final DocumentalConcatenatedCluster index
The reference index.


term

protected String term
The term associated to this index iterator.


id

protected int id
The id associated to this index iterator.

Constructor Detail

DocumentalConcatenatedClusterIndexIterator

public DocumentalConcatenatedClusterIndexIterator(DocumentalClusterIndexReader indexReader,
                                                  IndexIterator[] indexIterator,
                                                  int[] usedIndex)
                                           throws IOException
Throws:
IOException
Method Detail

term

public void term(CharSequence term)
Description copied from interface: IndexIterator
Sets the term whose inverted list is returned by this index iterator.

Usually, 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.

Instances of Index.EmptyIndexIterator are allowed to ignore silently calls to this method.

Specified by:
term in interface IndexIterator
Parameters:
term - 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.

term

public String term()
Description copied from interface: IndexIterator
Returns the term whose inverted list is returned by this index iterator.

Usually, the term is automatically set by IndexReader.documents(CharSequence) or IndexReader.documents(int), but you can supply your own term with IndexIterator.term(CharSequence).

Instances of Index.EmptyIndexIterator can return null.

Specified by:
term in interface IndexIterator
Returns:
the term over which this iterator is built, as a compact mutable string.
See Also:
IndexIterator.termNumber()

id

public void id(int id)
Description copied from interface: IndexIterator
Sets the id of this index iterator.

The id is an integer associated to 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 composited document iterator (say, numbering consecutively the leaves of the composite).

Instances of Index.EmptyIndexIterator are allowed to ignore silently calls to this method.

Specified by:
id in interface IndexIterator
Parameters:
id - the new id for this index iterator.

id

public int id()
Description copied from interface: IndexIterator
Returns the id of this index iterator.

Instances of Index.EmptyIndexIterator are allowed to return -1.

Specified by:
id in interface IndexIterator
Returns:
the id of this index iterator.
See Also:
IndexIterator.id(int)

index

public Index index()
Description copied from interface: IndexIterator
Returns the index over which this iterator is built.

Specified by:
index in interface IndexIterator
Returns:
the index over which this iterator is built.

frequency

public int frequency()
Description copied from interface: IndexIterator
Returns the frequency, that is, the number of documents that will be returned by this iterator.

Specified by:
frequency in interface IndexIterator
Returns:
the number of documents that will be returned by this iterator.

payload

public Payload payload()
                throws IOException
Description copied from interface: IndexIterator
Returns the payload, if any, associated with the current document.

Specified by:
payload in interface IndexIterator
Returns:
the payload associated with the current document.
Throws:
IOException

count

public int count()
          throws IOException
Description copied from interface: IndexIterator
Returns the count, that is, the number of occurrences of the term in the current document.

Specified by:
count in interface IndexIterator
Returns:
the count (number of occurrences) of the term in the current document.
Throws:
IOException

positions

public IntIterator positions()
                      throws IOException
Description copied from interface: IndexIterator
Returns the positions at which the term appears in the current document.

Specified by:
positions in interface IndexIterator
Returns:
the positions of the current document in which the current term appears.
Throws:
IOException

positions

public int positions(int[] positions)
              throws IOException
Description copied from interface: IndexIterator
Stores the positions at which the term appears in the current document in a given array.

If 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).

Specified by:
positions in interface IndexIterator
Parameters:
positions - an array that will be used to store positions.
Returns:
the count; it will have the sign changed if positions cannot hold all positions.
Throws:
IOException

positionArray

public int[] positionArray()
                    throws IOException
Description copied from interface: IndexIterator
Returns the positions at which the term appears in the current document in an array.

Implementations are allowed to return the same array across different calls to this method.

Specified by:
positionArray in interface IndexIterator
Returns:
an array whose first IndexIterator.count() elements contain the document positions.
Throws:
IOException

accept

public boolean accept(DocumentIteratorVisitor visitor)
               throws IOException
Description copied from interface: DocumentIterator
Accepts a visitor.

A document iterator is usually structured as composite, with operators as internal nodes and IndexIterators as leaves. This method implements the visitor pattern.

Specified by:
accept in interface DocumentIterator
Overrides:
accept in class DocumentalConcatenatedClusterDocumentIterator
Parameters:
visitor - the visitor.
Returns:
true if the visit should continue.
Throws:
IOException

acceptOnTruePaths

public boolean acceptOnTruePaths(DocumentIteratorVisitor visitor)
                          throws IOException
Description copied from interface: DocumentIterator
Accepts a visitor after a call to DocumentIterator.nextDocument(), limiting recursion to true paths.

After a call to DocumentIterator.nextDocument(), a document iterator is positioned over a document. This call is equivalent to DocumentIterator.accept(DocumentIteratorVisitor), but visits only along true paths.

We define a true path as a path from the root of the composite that passes only through nodes whose associated subtree is positioned on the same document of the root. Note that OrDocumentIterators detach exhausted iterators from the composite tree, so true paths define the subtree that is causing the current document to satisfy the query represented by this document iterator.

For more elaboration, and the main application of this method, see CounterCollectionVisitor.

Specified by:
acceptOnTruePaths in interface DocumentIterator
Overrides:
acceptOnTruePaths in class DocumentalConcatenatedClusterDocumentIterator
Parameters:
visitor - the visitor.
Returns:
true if the visit should continue.
Throws:
IOException
See Also:
DocumentIterator.accept(DocumentIteratorVisitor), CounterCollectionVisitor

termNumber

public int termNumber()
Description copied from interface: IndexIterator
Returns the number of the term whose inverted list is returned by this index iterator.

Usually, the term number is automatically set by IndexReader.documents(CharSequence) or IndexReader.documents(int). Instances of Index.EmptyIndexIterator can return -1.

Specified by:
termNumber in interface IndexIterator
Returns:
the number of the term over which this iterator is built, or -1 for an Index.EmptyIndexIterator.
See Also:
IndexIterator.term()