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
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
Fruit
is the type for the result of our collection.
e.g. usize
for the Count
collector.
type Child: SegmentCollector
type Child: SegmentCollector
Type of the SegmentCollector
associated to this collector.
Required Methods
fn 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.
fn requires_scoring(&self) -> bool
fn requires_scoring(&self) -> bool
Returns true iff the collector requires to compute scores for documents.
fn 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 to the collection of each segments into one fruit.
Provided Methods
fn 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