MultiLeafKnnCollector (Lucene 10.5.1 core API)
Description: declaration: package: org.apache.lucene.search.knn, class: MultiLeafKnnCollector

Package org.apache.lucene.search.knn

# Class MultiLeafKnnCollector

java.lang.Object
org.apache.lucene.search.KnnCollector.Decorator
org.apache.lucene.search.knn.MultiLeafKnnCollector

All Implemented Interfaces:
  `KnnCollector`

public final class MultiLeafKnnCollector extends KnnCollector.Decorator
MultiLeafKnnCollector is a specific KnnCollector that can exchange the top collected results across segments through a shared global queue.

WARNING: This API is experimental and might change in incompatible ways in the next release.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface org.apache.lucene.search.KnnCollector

  `KnnCollector.Decorator`

- ## Field Summary

  ### Fields inherited from class org.apache.lucene.search.KnnCollector.Decorator

  `collector`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MultiLeafKnnCollector(int k, float greediness, int interval, BlockingFloatHeap globalSimilarityQueue, AbstractKnnCollector subCollector)`
  Create a new MultiLeafKnnCollector.
  `MultiLeafKnnCollector(int k, BlockingFloatHeap globalSimilarityQueue, AbstractKnnCollector subCollector)`
  Create a new MultiLeafKnnCollector.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `collect(int docId, float similarity)`
  Collect the provided docId and include in the result set.
  `float`
  `minCompetitiveSimilarity()`
  This method is utilized during search to ensure only competitive results are explored.
  `String`
  `toString()`

  ### Methods inherited from class org.apache.lucene.search.KnnCollector.Decorator

  `earlyTerminated, getSearchStrategy, incVisitedCount, k, topDocs, visitedCount, visitLimit`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### MultiLeafKnnCollector

    public MultiLeafKnnCollector(int k, BlockingFloatHeap globalSimilarityQueue, AbstractKnnCollector subCollector)
    Create a new MultiLeafKnnCollector.
    Parameters:
      `k` - the number of neighbors to collect
      `globalSimilarityQueue` - the global queue of the highest similarities collected so far across all segments
      `subCollector` - the local collector

  - ### MultiLeafKnnCollector

    public MultiLeafKnnCollector(int k, float greediness, int interval, BlockingFloatHeap globalSimilarityQueue, AbstractKnnCollector subCollector)
    Create a new MultiLeafKnnCollector.
    Parameters:
      `k` - the number of neighbors to collect
      `greediness` - the greediness of the global search
      `interval` - (by number of collected values) the interval to synchronize the local and global queues
      `globalSimilarityQueue` - the global queue of the highest similarities collected so far
      `subCollector` - the local collector

- ## Method Details

  - ### collect

    public boolean collect(int docId, float similarity)
    Description copied from interface: `KnnCollector`
    Collect the provided docId and include in the result set.
    Specified by:
      `collect` in interface `KnnCollector`
    Overrides:
      `collect` in class `KnnCollector.Decorator`
    Parameters:
      `docId` - of the vector to collect
      `similarity` - its calculated similarity
    Returns:
      true if the vector is collected

  - ### minCompetitiveSimilarity

    public float minCompetitiveSimilarity()
    Description copied from interface: `KnnCollector`
    This method is utilized during search to ensure only competitive results are explored.

    Consequently, if this results collector wants to collect `k` results, this should return `Float.NEGATIVE_INFINITY` when not full.

    When full, the minimum score should be returned.

    Specified by:
      `minCompetitiveSimilarity` in interface `KnnCollector`
    Overrides:
      `minCompetitiveSimilarity` in class `KnnCollector.Decorator`
    Returns:
      the current minimum competitive similarity in the collection

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`