Class SortedDocValues

java.lang.Object
org.apache.lucene.search.DocIdSetIterator
org.apache.lucene.index.SortedDocValues
Direct Known Subclasses:
FilterSortedDocValues, MultiDocValues.MultiSortedDocValues

public abstract class SortedDocValues extends DocIdSetIterator
A per-document byte[] with presorted values. This is fundamentally an iterator over the int ord values per document, with random access APIs to resolve an int ord to BytesRef.

Per-Document values in a SortedDocValues are deduplicated, dereferenced, and sorted into a dictionary of unique values. A pointer to the dictionary value (ordinal) can be retrieved for each document. Ordinals are dense and in increasing sorted order.

  • Constructor Details

    • SortedDocValues

      protected SortedDocValues()
      Sole constructor. (For invocation by subclass constructors, typically implicit.)
  • Method Details

    • ordValue

      public abstract int ordValue() throws IOException
      Returns the ordinal for the current docID. It is illegal to call this method after advanceExact(int) returned false.
      Returns:
      ordinal for the document: this is dense, starts at 0, then increments by 1 for the next value in sorted order.
      Throws:
      IOException
    • lookupOrd

      public abstract BytesRef lookupOrd(int ord) throws IOException
      Retrieves the value for the specified ordinal. The returned BytesRef may be re-used across calls to lookupOrd(int) so make sure to copy it if you want to keep it around.
      Parameters:
      ord - ordinal to lookup (must be >= 0 and < getValueCount())
      Throws:
      IOException
      See Also:
    • getValueCount

      public abstract int getValueCount()
      Returns the number of unique values.
      Returns:
      number of unique values in this SortedDocValues. This is also equivalent to one plus the maximum ordinal.
    • lookupTerm

      public int lookupTerm(BytesRef key) throws IOException
      If key exists, returns its ordinal, else returns -insertionPoint-1, like Arrays.binarySearch.
      Parameters:
      key - Key to look up
      Throws:
      IOException
    • termsEnum

      public TermsEnum termsEnum() throws IOException
      Returns a TermsEnum over the values. The enum supports TermsEnum.ord() and TermsEnum.seekExact(long).
      Throws:
      IOException
    • ordinalRangeIntoBitSet

      public void ordinalRangeIntoBitSet(int fromDoc, int toDoc, long minOrd, long maxOrd, FixedBitSet bitSet, int offset) throws IOException
      Fills bitSet with the doc IDs in [fromDoc, toDoc) whose ordinals are in [minOrd, maxOrd]. This is a bulk operation that avoids per-doc virtual dispatch overhead.

      The default implementation falls back to per-doc evaluation via advanceExact(int) and ordValue(). Subclasses with random-access storage (e.g., dense fixed-bitsPerValue fields) can override this for significantly better performance.

      Parameters:
      fromDoc - first doc ID to evaluate (inclusive)
      toDoc - last doc ID to evaluate (exclusive)
      minOrd - lower bound of the ordinal range (inclusive)
      maxOrd - upper bound of the ordinal range (inclusive)
      bitSet - the bitset to fill
      offset - subtracted from each doc ID before setting the bit
      Throws:
      IOException
    • intersect

      public TermsEnum intersect(CompiledAutomaton automaton) throws IOException
      Returns a TermsEnum over the values, filtered by a CompiledAutomaton The enum supports TermsEnum.ord().
      Throws:
      IOException
    • advanceExact

      public abstract boolean advanceExact(int target) throws IOException
      Advance the iterator to exactly target and return whether target has a value. target must be greater than or equal to the current doc ID and must be a valid doc ID, ie. ≥ 0 and < maxDoc. After this method returns, DocIdSetIterator.docID() returns target.

      Note: it is illegal to call DocIdSetIterator.intoBitSet(int, org.apache.lucene.util.FixedBitSet, int) or DocIdSetIterator.docIDRunEnd() when this method returns false.

      Throws:
      IOException