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
SegmentCollector
s 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§
sourcetype Fruit: Fruit
type Fruit: Fruit
Fruit
is the type for the result of our collection.
e.g. usize
for the Count
collector.
sourcetype Child: SegmentCollector
type Child: SegmentCollector
Type of the SegmentCollector
associated with this collector.
Required Methods§
sourcefn for_segment(
&self,
segment_local_id: SegmentOrdinal,
segment: &SegmentReader
) -> Result<Self::Child>
fn for_segment( &self, segment_local_id: SegmentOrdinal, segment: &SegmentReader ) -> Result<Self::Child>
set_segment
is called before beginning to enumerate
on this segment.
sourcefn requires_scoring(&self) -> bool
fn requires_scoring(&self) -> bool
Returns true iff the collector requires to compute scores for documents.
sourcefn merge_fruits(
&self,
segment_fruits: Vec<<Self::Child as SegmentCollector>::Fruit>
) -> Result<Self::Fruit>
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§
sourcefn collect_segment(
&self,
weight: &dyn Weight,
segment_ord: u32,
reader: &SegmentReader
) -> Result<<Self::Child as SegmentCollector>::Fruit>
fn collect_segment( &self, weight: &dyn Weight, segment_ord: u32, reader: &SegmentReader ) -> Result<<Self::Child as SegmentCollector>::Fruit>
Created a segment collector and