pub trait Query:
QueryClone
+ Send
+ Sync
+ Downcast
+ Debug {
// Required method
fn weight(
&self,
enable_scoring: EnableScoring<'_>,
) -> Result<Box<dyn Weight>>;
// Provided methods
fn explain(
&self,
searcher: &Searcher,
doc_address: DocAddress,
) -> Result<Explanation> { ... }
fn count(&self, searcher: &Searcher) -> Result<usize> { ... }
fn query_terms<'a>(&'a self, _visitor: &mut dyn FnMut(&'a Term, bool)) { ... }
}
Expand description
The Query
trait defines a set of documents and a scoring method
for those documents.
The Query
trait is 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 a recipe to define a set of documents as well the way to score them. - a
Weight
is this recipe tied to a specificSearcher
. 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 specificSegmentReader
. It is created by theWeight
.
When implementing a new type of Query
, it is normal to implement a
dedicated Query
, Weight
and Scorer
.
Required Methods§
Provided Methods§
Sourcefn explain(
&self,
searcher: &Searcher,
doc_address: DocAddress,
) -> Result<Explanation>
fn explain( &self, searcher: &Searcher, doc_address: DocAddress, ) -> Result<Explanation>
Returns an Explanation
for the score of the document.
Sourcefn count(&self, searcher: &Searcher) -> Result<usize>
fn count(&self, searcher: &Searcher) -> Result<usize>
Returns the number of documents matching the query.
Sourcefn query_terms<'a>(&'a self, _visitor: &mut dyn FnMut(&'a Term, bool))
fn query_terms<'a>(&'a self, _visitor: &mut dyn FnMut(&'a Term, bool))
Extract all of the terms associated with the query and pass them to the given closure.
Each term is associated with a boolean indicating whether positions are required or not.
Note that there can be multiple instances of any given term in a query and deduplication must be handled by the visitor.
Implementations§
Source§impl dyn Query
impl dyn Query
Sourcepub fn is<__T: Query>(&self) -> bool
pub fn is<__T: Query>(&self) -> bool
Returns true if the trait object wraps an object of type __T
.
Sourcepub fn downcast<__T: Query>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
pub fn downcast<__T: Query>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
Returns a boxed object from a boxed trait object if the underlying object is of type
__T
. Returns the original boxed trait if it isn’t.
Sourcepub fn downcast_rc<__T: Query>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
pub fn downcast_rc<__T: Query>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
Returns an Rc
-ed object from an Rc
-ed trait object if the underlying object is of
type __T
. Returns the original Rc
-ed trait if it isn’t.
Sourcepub fn downcast_ref<__T: Query>(&self) -> Option<&__T>
pub fn downcast_ref<__T: Query>(&self) -> Option<&__T>
Returns a reference to the object within the trait object if it is of type __T
, or
None
if it isn’t.
Sourcepub fn downcast_mut<__T: Query>(&mut self) -> Option<&mut __T>
pub fn downcast_mut<__T: Query>(&mut self) -> Option<&mut __T>
Returns a mutable reference to the object within the trait object if it is of type
__T
, or None
if it isn’t.
Trait Implementations§
Source§impl Query for Box<dyn Query>
impl Query for Box<dyn Query>
Source§fn weight(&self, enabled_scoring: EnableScoring<'_>) -> Result<Box<dyn Weight>>
fn weight(&self, enabled_scoring: EnableScoring<'_>) -> Result<Box<dyn Weight>>
Source§fn count(&self, searcher: &Searcher) -> Result<usize>
fn count(&self, searcher: &Searcher) -> Result<usize>
Source§fn query_terms<'a>(&'a self, visitor: &mut dyn FnMut(&'a Term, bool))
fn query_terms<'a>(&'a self, visitor: &mut dyn FnMut(&'a Term, bool))
Source§fn explain(
&self,
searcher: &Searcher,
doc_address: DocAddress,
) -> Result<Explanation>
fn explain( &self, searcher: &Searcher, doc_address: DocAddress, ) -> Result<Explanation>
Explanation
for the score of the document.