pub trait Query:
Display
+ Send
+ Sync {
// Required methods
fn scorer<'a>(
&self,
reader: &'a SegmentReader,
limit: usize,
) -> ScorerFuture<'a>;
fn count_estimate<'a>(&self, reader: &'a SegmentReader) -> CountFuture<'a>;
// Provided methods
fn scorer_sync<'a>(
&self,
reader: &'a SegmentReader,
limit: usize,
) -> Result<Box<dyn Scorer + 'a>> { ... }
fn as_term_query_info(&self) -> Option<TermQueryInfo> { ... }
fn as_sparse_term_query_info(&self) -> Option<SparseTermQueryInfo> { ... }
fn is_filter(&self) -> bool { ... }
fn as_doc_predicate<'a>(
&self,
_reader: &'a SegmentReader,
) -> Option<DocPredicate<'a>> { ... }
}Expand description
A search query (async)
Note: scorer takes &self (not &'a self) so that scorers don’t borrow the query.
This enables query composition - queries can create sub-queries locally and get their scorers.
Implementations must clone/capture any data they need during scorer creation.
Required Methods§
Sourcefn scorer<'a>(
&self,
reader: &'a SegmentReader,
limit: usize,
) -> ScorerFuture<'a>
fn scorer<'a>( &self, reader: &'a SegmentReader, limit: usize, ) -> ScorerFuture<'a>
Create a scorer for this query against a single segment (async)
The limit parameter specifies the maximum number of results to return.
This is passed from the top-level search limit.
Note: The scorer borrows only the reader, not the query. Implementations should capture any needed query data (field, terms, etc.) during creation.
Sourcefn count_estimate<'a>(&self, reader: &'a SegmentReader) -> CountFuture<'a>
fn count_estimate<'a>(&self, reader: &'a SegmentReader) -> CountFuture<'a>
Estimated number of matching documents in a segment (async)
Provided Methods§
Sourcefn scorer_sync<'a>(
&self,
reader: &'a SegmentReader,
limit: usize,
) -> Result<Box<dyn Scorer + 'a>>
fn scorer_sync<'a>( &self, reader: &'a SegmentReader, limit: usize, ) -> Result<Box<dyn Scorer + 'a>>
Create a scorer synchronously (mmap/RAM only).
Available when the sync feature is enabled.
Default implementation returns an error.
Sourcefn as_term_query_info(&self) -> Option<TermQueryInfo>
fn as_term_query_info(&self) -> Option<TermQueryInfo>
Return term info if this is a simple term query eligible for MaxScore optimization
Returns None for complex queries (boolean, phrase, etc.)
Sourcefn as_sparse_term_query_info(&self) -> Option<SparseTermQueryInfo>
fn as_sparse_term_query_info(&self) -> Option<SparseTermQueryInfo>
Return sparse term info if this is a single-dimension sparse query eligible for MaxScore optimization
Sourcefn is_filter(&self) -> bool
fn is_filter(&self) -> bool
True if this query is a pure filter (always scores 1.0, no positions). Used by the planner to convert non-selective MUST filters into predicates.
Sourcefn as_doc_predicate<'a>(
&self,
_reader: &'a SegmentReader,
) -> Option<DocPredicate<'a>>
fn as_doc_predicate<'a>( &self, _reader: &'a SegmentReader, ) -> Option<DocPredicate<'a>>
For filter queries: return a cheap per-doc predicate against a segment. The predicate does O(1) work per doc (e.g., fast-field lookup).