Class BitStreamIndexReader.BitStreamIndexReaderIndexIterator
- java.lang.Object
-
- it.unimi.di.big.mg4j.index.AbstractIndexIterator
-
- it.unimi.di.big.mg4j.index.BitStreamIndexReader.BitStreamIndexReaderIndexIterator
-
- All Implemented Interfaces:
IndexIterator
,DocumentIterator
- Enclosing class:
- BitStreamIndexReader
protected static final class BitStreamIndexReader.BitStreamIndexReaderIndexIterator extends AbstractIndexIterator implements IndexIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected int
b
The parameterb
for Golomb coding of pointers.protected int
count
The current count (if this index contains counts).protected CompressionFlags.Coding
countCoding
The cached copy ofindex.countCoding
.protected long
currentDocument
The last document pointer we read from current list, -1 if we just read the frequency,DocumentIterator.END_OF_LIST
if we are beyond the end of list.protected int
currentPosition
The index of the next position to be returned bynextPosition()
.protected long
currentTerm
The current term.protected long
frequency
The current frequency.protected boolean
hasCounts
The cached copy ofindex.hasCounts
.protected boolean
hasPayloads
The cached copy ofindex.hasPayloads
.protected boolean
hasPointers
Whether the current terms has pointers at all (this happens when thefrequency
is smaller than the number of documents).protected boolean
hasPositions
The cached copy ofindex.hasPositions
.protected boolean
hasSkips
Whether the underlying index has skips.int
height
The parameterh
(the maximum height of a skip tower).protected InputBitStream
ibs
The underlying input bit stream.protected BitStreamIndex
index
The reference index.protected int
log2b
The parameterlog2b
for Golomb coding of pointers; it is the most significant bit ofb
.protected long
numberOfDocumentRecord
The number of the document record we are going to read inside the current inverted list.protected Payload
payload
The payload, in case the index of this reader has payloads, ornull
.protected CompressionFlags.Coding
pointerCoding
The cached copy ofindex.pointerCoding
.protected int[]
positionCache
The cached position array.protected CompressionFlags.Coding
positionCoding
The cached copy ofindex.positionCoding
.long
quantum
The quantum.int
quantumDivisionShift
The shift giving result of the division byquantum
.long
quantumModuloMask
The bit mask giving the remainder of the division byquantum
.protected int
state
This variable tracks the current state of the reader.-
Fields inherited from class it.unimi.di.big.mg4j.index.AbstractIndexIterator
id, term, weight
-
Fields inherited from interface it.unimi.di.big.mg4j.search.DocumentIterator
END_OF_LIST
-
Fields inherited from interface it.unimi.di.big.mg4j.index.IndexIterator
END_OF_POSITIONS
-
-
Constructor Summary
Constructors Constructor Description BitStreamIndexReaderIndexIterator(BitStreamIndexReader parent, InputBitStream ibs)
-
Method Summary
Modifier and Type Method Description protected IndexIterator
advance()
int
count()
Returns the count, that is, the number of occurrences of the term in the current document.void
dispose()
Disposes this document iterator, releasing all resources.long
document()
Returns the last document returned byDocumentIterator.nextDocument()
.long
frequency()
Returns the frequency, that is, the number of documents that will be returned by this iterator.Index
index()
Returns the index over which this iterator is built.ReferenceSet<Index>
indices()
Returns the set of indices over which this iterator is built.IntervalIterator
intervalIterator()
Returns the interval iterator of this document iterator for single-index queries.IntervalIterator
intervalIterator(Index index)
Returns the interval iterator of this document iterator for the given index.Reference2ReferenceMap<Index,IntervalIterator>
intervalIterators()
Returns an unmodifiable map from indices to interval iterators.boolean
mayHaveNext()
Returns whether there may be a next document, possibly with false positives.long
nextDocument()
Returns the next document provided by this document iterator, orDocumentIterator.END_OF_LIST
if no more documents are available.int
nextPosition()
Returns the next position at which the term appears in the current document.Payload
payload()
Returns the payload, if any, associated with the current document.protected void
position(long term)
Positions the index on the inverted list of a given term.long
skipTo(long p)
Skips all documents smaller thann
.long
termNumber()
Returns the number of the term whose inverted list is returned by this index iterator.String
toString()
protected void
updatePositionCache()
We read positions, assuming state <= BEFORE_POSITIONS-
Methods inherited from class it.unimi.di.big.mg4j.index.AbstractIndexIterator
accept, acceptOnTruePaths, id, id, term, term, weight, weight
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface it.unimi.di.big.mg4j.search.DocumentIterator
accept, acceptOnTruePaths, weight
-
-
-
-
Field Detail
-
index
protected final BitStreamIndex index
The reference index.
-
ibs
protected final InputBitStream ibs
The underlying input bit stream.
-
hasPositions
protected final boolean hasPositions
The cached copy ofindex.hasPositions
.
-
hasCounts
protected final boolean hasCounts
The cached copy ofindex.hasCounts
.
-
hasPayloads
protected final boolean hasPayloads
The cached copy ofindex.hasPayloads
.
-
hasSkips
protected final boolean hasSkips
Whether the underlying index has skips.
-
pointerCoding
protected final CompressionFlags.Coding pointerCoding
The cached copy ofindex.pointerCoding
.
-
countCoding
protected final CompressionFlags.Coding countCoding
The cached copy ofindex.countCoding
.
-
positionCoding
protected final CompressionFlags.Coding positionCoding
The cached copy ofindex.positionCoding
.
-
payload
protected final Payload payload
The payload, in case the index of this reader has payloads, ornull
.
-
b
protected int b
The parameterb
for Golomb coding of pointers.
-
log2b
protected int log2b
The parameterlog2b
for Golomb coding of pointers; it is the most significant bit ofb
.
-
currentTerm
protected long currentTerm
The current term.
-
frequency
protected long frequency
The current frequency.
-
hasPointers
protected boolean hasPointers
Whether the current terms has pointers at all (this happens when thefrequency
is smaller than the number of documents).
-
count
protected int count
The current count (if this index contains counts).
-
currentDocument
protected long currentDocument
The last document pointer we read from current list, -1 if we just read the frequency,DocumentIterator.END_OF_LIST
if we are beyond the end of list.
-
numberOfDocumentRecord
protected long numberOfDocumentRecord
The number of the document record we are going to read inside the current inverted list.
-
state
protected int state
This variable tracks the current state of the reader.
-
height
public final int height
The parameterh
(the maximum height of a skip tower).
-
quantum
public long quantum
The quantum.
-
quantumModuloMask
public long quantumModuloMask
The bit mask giving the remainder of the division byquantum
.
-
quantumDivisionShift
public int quantumDivisionShift
The shift giving result of the division byquantum
.
-
currentPosition
protected int currentPosition
The index of the next position to be returned bynextPosition()
.
-
positionCache
protected int[] positionCache
The cached position array.
-
-
Constructor Detail
-
BitStreamIndexReaderIndexIterator
public BitStreamIndexReaderIndexIterator(BitStreamIndexReader parent, InputBitStream ibs)
-
-
Method Detail
-
position
protected void position(long term) throws IOException
Positions the index on the inverted list of a given term.This method can be called at any time. Note that it is always possible to call this method with argument 0, even if offsets have not been loaded.
- Parameters:
term
- a term.- Throws:
IOException
-
termNumber
public long 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)
orIndexReader.documents(long)
.- Specified by:
termNumber
in interfaceIndexIterator
- Returns:
- the number of the term over which this iterator is built.
- See Also:
IndexIterator.term()
-
advance
protected IndexIterator advance() throws IOException
- Throws:
IOException
-
index
public Index index()
Description copied from interface:IndexIterator
Returns the index over which this iterator is built.- Specified by:
index
in interfaceIndexIterator
- Returns:
- the index over which this iterator is built.
-
frequency
public long 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 interfaceIndexIterator
- Returns:
- the number of documents that will be returned by this iterator.
-
document
public long document()
Description copied from interface:DocumentIterator
Returns the last document returned byDocumentIterator.nextDocument()
.- Specified by:
document
in interfaceDocumentIterator
- Returns:
- the last document returned by
DocumentIterator.nextDocument()
, -1 if no document has been returned yet, andDocumentIterator.END_OF_LIST
if the list of results has been exhausted.
-
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 interfaceIndexIterator
- 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 interfaceIndexIterator
- Returns:
- the count (number of occurrences) of the term in the current document.
- Throws:
IOException
-
updatePositionCache
protected void updatePositionCache() throws IOException
We read positions, assuming state <= BEFORE_POSITIONS- Throws:
IOException
-
nextPosition
public int nextPosition() throws IOException
Description copied from interface:IndexIterator
Returns the next position at which the term appears in the current document.- Specified by:
nextPosition
in interfaceIndexIterator
- Returns:
- the next position of the current document in which the current term appears,
or
IndexIterator.END_OF_POSITIONS
if there are no more positions. - Throws:
IOException
-
nextDocument
public long nextDocument() throws IOException
Description copied from interface:DocumentIterator
Returns the next document provided by this document iterator, orDocumentIterator.END_OF_LIST
if no more documents are available.- Specified by:
nextDocument
in interfaceDocumentIterator
- Returns:
- the next document, or
DocumentIterator.END_OF_LIST
if no more documents are available. - Throws:
IOException
-
skipTo
public long skipTo(long p) throws IOException
Description copied from interface:DocumentIterator
Skips all documents smaller thann
.Define the current document
k
associated with this document iterator as follows:- -1, if
DocumentIterator.nextDocument()
and this method have never been called; DocumentIterator.END_OF_LIST
, if a call to this method or toDocumentIterator.nextDocument()
returnedDocumentIterator.END_OF_LIST
;- the last value returned by a call to
DocumentIterator.nextDocument()
or this method, otherwise.
If
k
is larger than or equal ton
, then this method does nothing and returnsk
. Otherwise, a call to this method is equivalent towhile( ( k = nextDocument() ) < n ); return 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 toDocumentIterator.nextDocument()
that returnedk
. In particular, the first document larger than or equal ton
(when returned by this method) will not be returned by the next call toDocumentIterator.nextDocument()
.- Specified by:
skipTo
in interfaceDocumentIterator
- Parameters:
p
- a document pointer.- Returns:
- a document pointer larger than or equal to
n
if available,DocumentIterator.END_OF_LIST
otherwise. - Throws:
IOException
- -1, if
-
dispose
public void dispose() throws IOException
Description copied from interface:DocumentIterator
Disposes this document iterator, releasing all resources.This method should propagate down to the underlying index iterators, where it should release resources such as open files and network connections. If you're doing your own resource tracking and pooling, then you do not need to call this method.
- Specified by:
dispose
in interfaceDocumentIterator
- Throws:
IOException
-
mayHaveNext
public boolean mayHaveNext()
Description copied from interface:DocumentIterator
Returns whether there may be a next document, possibly with false positives.- Specified by:
mayHaveNext
in interfaceDocumentIterator
- Returns:
- true there may be a next document; false if certainly there is no next document.
-
intervalIterators
public Reference2ReferenceMap<Index,IntervalIterator> intervalIterators() throws IOException
Description copied from interface:DocumentIterator
Returns an unmodifiable map from indices to interval iterators.After a call to
DocumentIterator.nextDocument()
, this map can be used to retrieve the intervals in the current document. An invocation ofMap.get(java.lang.Object)
on this map with argumentindex
yields the same result asintervalIterator(index)
.- Specified by:
intervalIterators
in interfaceDocumentIterator
- Returns:
- a map from indices to interval iterators over the current document.
- Throws:
IOException
- See Also:
DocumentIterator.intervalIterator(Index)
-
intervalIterator
public IntervalIterator intervalIterator() throws IOException
Description copied from interface:DocumentIterator
Returns the interval iterator of this document iterator for single-index queries.This is a commodity method that can be used only for queries built over a single index.
- Specified by:
intervalIterator
in interfaceDocumentIterator
- Returns:
- an interval iterator.
- Throws:
IOException
- See Also:
DocumentIterator.intervalIterator(Index)
-
intervalIterator
public IntervalIterator intervalIterator(Index index) throws IOException
Description copied from interface:DocumentIterator
Returns the interval iterator of this document iterator for the given index.After a call to
DocumentIterator.nextDocument()
, this iterator can be used to retrieve the intervals in the current document (the one returned byDocumentIterator.nextDocument()
) for the indexindex
.Note that if all indices have positions, it is guaranteed that at least one index will return an interval. However, for disjunctive queries it cannot be guaranteed that all indices will return an interval.
Indices without positions always return
IntervalIterators.TRUE
. Thus, in presence of indices without positions it is possible that no intervals at all are available.- Specified by:
intervalIterator
in interfaceDocumentIterator
- Parameters:
index
- an index (must be one over which the query was built).- Returns:
- an interval iterator over the current document in
index
. - Throws:
IOException
-
indices
public ReferenceSet<Index> indices()
Description copied from interface:DocumentIterator
Returns the set of indices over which this iterator is built.- Specified by:
indices
in interfaceDocumentIterator
- Returns:
- the set of indices over which this iterator is built.
-
-