Trait tantivy::query::Query
[−]
[src]
pub trait Query: Debug { fn as_any(&self) -> &Any; fn weight(&self, searcher: &Searcher) -> Result<Box<Weight>>; fn search(
&self,
searcher: &Searcher,
collector: &mut Collector
) -> Result<TimerTree> { ... } }
Query trait are in charge of defining :
- a set of documents
- a way to score these documents
When performing a search, these documents will then be pushed to a Collector, which will in turn be in charge of deciding what to do with them.
Concretely, this scored docset is represented by the
Scorer
trait.
Because our index is actually split into segments, the
query does not actually directly creates DocSet
object.
Instead, the query creates a Weight
object for a given searcher.
The weight object, in turn, makes it possible to create
a scorer for a specific SegmentReader
.
So to sum it up :
- a Query
is recipe to define a set of documents as well the way to score them.
- a Weight
is this recipe tied to a specific Searcher
. It may for instance
hold statistics about the different term of the query. It is created by the query.
- a Scorer
is a cursor over the set of matching documents, for a specific
SegmentReader
. It is created by the
Weight
.
When implementing a new type of Query
, it is normal to implement a
dedicated Query
, Weight
and Scorer
.
Required Methods
fn as_any(&self) -> &Any
Used to make it possible to cast Box
fn weight(&self, searcher: &Searcher) -> Result<Box<Weight>>
Create the weight associated to a query.
See Weight
.
Provided Methods
fn search(
&self,
searcher: &Searcher,
collector: &mut Collector
) -> Result<TimerTree>
&self,
searcher: &Searcher,
collector: &mut Collector
) -> Result<TimerTree>
Search works as follows :
First the weight object associated to the query is created.
Then, the query loops over the segments and for each segment :
- setup the collector and informs it that the segment being processed has changed.
- creates a Scorer
object associated for this segment
- iterate throw the matched documents and push them to the collector.
Implementors
impl Query for BooleanQuery
impl Query for TermQuery
impl Query for PhraseQuery