logo
pub trait Collector: Sync + Send {
    type Fruit: Fruit;
    type Child: SegmentCollector;

    fn for_segment(
        &self,
        segment_local_id: SegmentOrdinal,
        segment: &SegmentReader
    ) -> Result<Self::Child>; fn requires_scoring(&self) -> bool; fn merge_fruits(
        &self,
        segment_fruits: Vec<<Self::Child as SegmentCollector>::Fruit>
    ) -> Result<Self::Fruit>; fn collect_segment(
        &self,
        weight: &dyn Weight,
        segment_ord: u32,
        reader: &SegmentReader
    ) -> Result<<Self::Child as SegmentCollector>::Fruit> { ... } }
Expand description

Collectors are in charge of collecting and retaining relevant information from the document found and scored by the query.

For instance,

  • keeping track of the top 10 best documents
  • computing a breakdown over a fast field
  • computing the number of documents matching the query

Our search index is in fact a collection of segments, so a Collector trait is actually more of a factory to instance SegmentCollectors for each segments.

The collection logic itself is in the SegmentCollector.

Segments are not guaranteed to be visited in any specific order.

Required Associated Types

Fruit is the type for the result of our collection. e.g. usize for the Count collector.

Type of the SegmentCollector associated to this collector.

Required Methods

set_segment is called before beginning to enumerate on this segment.

Returns true iff the collector requires to compute scores for documents.

Combines the fruit associated to the collection of each segments into one fruit.

Provided Methods

Created a segment collector and

Implementations on Foreign Types

Implementors