pub struct Search<T> { /* private fields */ }Expand description
A typed query against one index — a plain, client-free value.
Built from FlussoDocument::query (or Search::new(index, hash) by
hand). Clauses accumulate into a bool query: query/should score,
filter/must_not don’t. Because no client (and no lifetime) is
involved, a Search can be named, stored, cloned, and reused; a Client
appears only at the terminals — Search::send for a page of hits,
Search::ids for a page of bare document ids, Search::count for
just the number of matches (all &self, so running consumes nothing) —
or several searches go in one round-trip via Client::msearch.
Implementations§
Source§impl<T> Search<T>
impl<T> Search<T>
Sourcepub fn new(index: impl Into<String>, hash: impl Into<String>) -> Self
pub fn new(index: impl Into<String>, hash: impl Into<String>) -> Self
Start a query against index (the logical name) and its schema hash.
Sourcepub fn query(self, query: impl AsQuery<Root>) -> Self
pub fn query(self, query: impl AsQuery<Root>) -> Self
A scoring clause (bool.must). Accepts any root-scope AsQuery; an
absent one (e.g. a None optional) adds nothing.
Sourcepub fn filter(self, query: impl AsQuery<Root>) -> Self
pub fn filter(self, query: impl AsQuery<Root>) -> Self
A non-scoring, cacheable clause (bool.filter). An absent clause adds
nothing — so filter(opt.map(|v| handle.eq(v))) is a conditional filter.
Sourcepub fn must_not(self, query: impl AsQuery<Root>) -> Self
pub fn must_not(self, query: impl AsQuery<Root>) -> Self
An exclusion clause (bool.must_not). An absent clause excludes nothing.
Sourcepub fn should(self, query: impl AsQuery<Root>) -> Self
pub fn should(self, query: impl AsQuery<Root>) -> Self
An optional, scoring clause (bool.should). An absent clause adds nothing.
Sourcepub fn min_should_match(self, value: impl Into<MinimumShouldMatch>) -> Self
pub fn min_should_match(self, value: impl Into<MinimumShouldMatch>) -> Self
Require at least this many should clauses to match. Beside query /
filter clauses, should defaults to non-constraining (scoring only);
setting this makes a top-level should-group a real filter. Accepts a
count (1) or MinimumShouldMatch::percent / raw.
pub fn sort(self, sort: Sort) -> Self
Sourcepub fn track_total_hits(self, track: impl Into<Value>) -> Self
pub fn track_total_hits(self, track: impl Into<Value>) -> Self
Control how the hit total is counted. true counts exactly, false
disables counting, an integer caps accuracy at that many (e.g. 10_000).
Sourcepub fn track_scores(self, track: bool) -> Self
pub fn track_scores(self, track: bool) -> Self
Compute relevance scores even when sorting by a field.
Sourcepub fn search_after(
self,
values: impl IntoIterator<Item = impl Into<Value>>,
) -> Self
pub fn search_after( self, values: impl IntoIterator<Item = impl Into<Value>>, ) -> Self
Deep-paginate after the given sort values (the last hit’s sort array
from the previous page). Pair with a deterministic sort.
Sourcepub fn collapse(self, field: impl Into<String>) -> Self
pub fn collapse(self, field: impl Into<String>) -> Self
Collapse hits so only the top hit per field value is returned.
Sourcepub fn post_filter(self, query: impl AsQuery<Root>) -> Self
pub fn post_filter(self, query: impl AsQuery<Root>) -> Self
A filter applied after scoring/aggregation — narrows the returned hits without affecting scores or aggregations.
Sourcepub fn highlight(self, highlight: Highlight) -> Self
pub fn highlight(self, highlight: Highlight) -> Self
Attach match highlighting (see Highlight).
Sourcepub fn raw(self, query: Value) -> Self
pub fn raw(self, query: Value) -> Self
Replace the query body with a raw OpenSearch query DSL value. The
pressure-release valve for anything the typed builder can’t express;
results still deserialize into T.
Sourcepub fn filter_nested(self, projection: NestedProjection) -> Self
pub fn filter_nested(self, projection: NestedProjection) -> Self
Shape a nested array in the results (built via Nested::matching /
Nested::project). Each hit’s source.<path> is replaced with the
matching subset; this does not change which parents match.
Sourcepub fn body(&self) -> Value
pub fn body(&self) -> Value
The request body this search will POST to _search. Pure — useful for
tests and debugging.
Sourcepub fn count_body(&self) -> Value
pub fn count_body(&self) -> Value
The request body count will POST to _count: just the
query. Sort, from/size, and filter_nested projections are dropped —
_count accepts none of them, and none of them changes which documents
match. Pure — useful for tests and debugging.
Sourcepub fn ids_body(&self) -> Value
pub fn ids_body(&self) -> Value
The request body ids will POST to _search: the query
plus sort and pagination, with _source: false so hits carry only
their _id and nothing is fetched from stored source. filter_nested
projections are dropped — they shape returned sources, and there are
none. Pure — useful for tests and debugging.
Source§impl<T> Search<T>where
T: DeserializeOwned,
impl<T> Search<T>where
T: DeserializeOwned,
Sourcepub async fn send(&self, client: &Client) -> Result<SearchResponse<T>>
pub async fn send(&self, client: &Client) -> Result<SearchResponse<T>>
Execute the search and decode the hits into SearchResponse<T>.