Trait tantivy::collector::Collector

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

    // Required methods
    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>;

    // Provided method
    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§

source

type Fruit: Fruit

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

source

type Child: SegmentCollector

Type of the SegmentCollector associated with this collector.

Required Methods§

source

fn for_segment( &self, segment_local_id: SegmentOrdinal, segment: &SegmentReader ) -> Result<Self::Child>

set_segment is called before beginning to enumerate on this segment.

source

fn requires_scoring(&self) -> bool

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

source

fn merge_fruits( &self, segment_fruits: Vec<<Self::Child as SegmentCollector>::Fruit> ) -> Result<Self::Fruit>

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

Provided Methods§

source

fn collect_segment( &self, weight: &dyn Weight, segment_ord: u32, reader: &SegmentReader ) -> Result<<Self::Child as SegmentCollector>::Fruit>

Created a segment collector and

Implementations on Foreign Types§

source§

impl<Left, Right> Collector for (Left, Right)
where Left: Collector, Right: Collector,

§

type Fruit = (<Left as Collector>::Fruit, <Right as Collector>::Fruit)

§

type Child = (<Left as Collector>::Child, <Right as Collector>::Child)

source§

fn for_segment( &self, segment_local_id: u32, segment: &SegmentReader ) -> Result<Self::Child>

source§

fn requires_scoring(&self) -> bool

source§

fn merge_fruits( &self, segment_fruits: Vec<<Self::Child as SegmentCollector>::Fruit> ) -> Result<(Left::Fruit, Right::Fruit)>

source§

impl<One, Two, Three> Collector for (One, Two, Three)
where One: Collector, Two: Collector, Three: Collector,

§

type Fruit = (<One as Collector>::Fruit, <Two as Collector>::Fruit, <Three as Collector>::Fruit)

§

type Child = (<One as Collector>::Child, <Two as Collector>::Child, <Three as Collector>::Child)

source§

fn for_segment( &self, segment_local_id: u32, segment: &SegmentReader ) -> Result<Self::Child>

source§

fn requires_scoring(&self) -> bool

source§

fn merge_fruits( &self, children: Vec<<Self::Child as SegmentCollector>::Fruit> ) -> Result<Self::Fruit>

source§

impl<One, Two, Three, Four> Collector for (One, Two, Three, Four)
where One: Collector, Two: Collector, Three: Collector, Four: Collector,

§

type Fruit = (<One as Collector>::Fruit, <Two as Collector>::Fruit, <Three as Collector>::Fruit, <Four as Collector>::Fruit)

§

type Child = (<One as Collector>::Child, <Two as Collector>::Child, <Three as Collector>::Child, <Four as Collector>::Child)

source§

fn for_segment( &self, segment_local_id: u32, segment: &SegmentReader ) -> Result<Self::Child>

source§

fn requires_scoring(&self) -> bool

source§

fn merge_fruits( &self, children: Vec<<Self::Child as SegmentCollector>::Fruit> ) -> Result<Self::Fruit>

source§

impl<TCollector: Collector> Collector for Option<TCollector>

§

type Fruit = Option<<TCollector as Collector>::Fruit>

§

type Child = Option<<TCollector as Collector>::Child>

source§

fn for_segment( &self, segment_local_id: SegmentOrdinal, segment: &SegmentReader ) -> Result<Self::Child>

source§

fn requires_scoring(&self) -> bool

source§

fn merge_fruits( &self, segment_fruits: Vec<<Self::Child as SegmentCollector>::Fruit> ) -> Result<Self::Fruit>

Implementors§

source§

impl Collector for AggregationCollector

source§

impl Collector for DistributedAggregationCollector

source§

impl Collector for Count

§

type Fruit = usize

§

type Child = SegmentCountCollector

source§

impl Collector for DocSetCollector

§

type Fruit = HashSet<DocAddress>

§

type Child = DocSetChildCollector

source§

impl Collector for FacetCollector

§

type Fruit = FacetCounts

§

type Child = FacetSegmentCollector

source§

impl Collector for HistogramCollector

§

type Fruit = Vec<u64>

§

type Child = SegmentHistogramCollector

source§

impl Collector for TopDocs

§

type Fruit = Vec<(f32, DocAddress)>

§

type Child = TopScoreSegmentCollector

source§

impl<'a> Collector for MultiCollector<'a>

§

type Fruit = MultiFruit

§

type Child = MultiCollectorChild

source§

impl<TCollector, TPredicate> Collector for BytesFilterCollector<TCollector, TPredicate>
where TCollector: Collector + Send + Sync, TPredicate: 'static + Fn(&[u8]) -> bool + Send + Sync + Clone,

§

type Fruit = <TCollector as Collector>::Fruit

§

type Child = BytesFilterSegmentCollector<<TCollector as Collector>::Child, TPredicate>

source§

impl<TCollector, TPredicate, TPredicateValue> Collector for FilterCollector<TCollector, TPredicate, TPredicateValue>
where TCollector: Collector + Send + Sync, TPredicate: 'static + Fn(TPredicateValue) -> bool + Send + Sync + Clone, TPredicateValue: HasAssociatedColumnType, DynamicColumn: Into<Option<Column<TPredicateValue>>>,

§

type Fruit = <TCollector as Collector>::Fruit

§

type Child = FilterSegmentCollector<<TCollector as Collector>::Child, TPredicate, TPredicateValue>