Trait tantivy::query::Weight

source ·
pub trait Weight: Send + Sync + 'static {
    // Required methods
    fn scorer(
        &self,
        reader: &SegmentReader,
        boost: Score
    ) -> Result<Box<dyn Scorer>>;
    fn explain(&self, reader: &SegmentReader, doc: DocId) -> Result<Explanation>;

    // Provided methods
    fn count(&self, reader: &SegmentReader) -> Result<u32> { ... }
    fn for_each(
        &self,
        reader: &SegmentReader,
        callback: &mut dyn FnMut(DocId, Score)
    ) -> Result<()> { ... }
    fn for_each_no_score(
        &self,
        reader: &SegmentReader,
        callback: &mut dyn FnMut(&[DocId])
    ) -> Result<()> { ... }
    fn for_each_pruning(
        &self,
        threshold: Score,
        reader: &SegmentReader,
        callback: &mut dyn FnMut(DocId, Score) -> Score
    ) -> Result<()> { ... }
}
Expand description

A Weight is the specialization of a Query for a given set of segments.

See Query.

Required Methods§

source

fn scorer( &self, reader: &SegmentReader, boost: Score ) -> Result<Box<dyn Scorer>>

Returns the scorer for the given segment.

boost is a multiplier to apply to the score.

See Query.

source

fn explain(&self, reader: &SegmentReader, doc: DocId) -> Result<Explanation>

Returns an Explanation for the given document.

Provided Methods§

source

fn count(&self, reader: &SegmentReader) -> Result<u32>

Returns the number documents within the given SegmentReader.

source

fn for_each( &self, reader: &SegmentReader, callback: &mut dyn FnMut(DocId, Score) ) -> Result<()>

Iterates through all of the document matched by the DocSet DocSet and push the scored documents to the collector.

source

fn for_each_no_score( &self, reader: &SegmentReader, callback: &mut dyn FnMut(&[DocId]) ) -> Result<()>

Iterates through all of the document matched by the DocSet DocSet and push the scored documents to the collector.

source

fn for_each_pruning( &self, threshold: Score, reader: &SegmentReader, callback: &mut dyn FnMut(DocId, Score) -> Score ) -> Result<()>

Calls callback with all of the (doc, score) for which score is exceeding a given threshold.

This method is useful for the TopDocs collector. For all docsets, the blanket implementation has the benefit of prefiltering (doc, score) pairs, avoiding the virtual dispatch cost.

More importantly, it makes it possible for scorers to implement important optimization (e.g. BlockWAND for union).

Implementors§