Skip to main content

Search

Struct Search 

Source
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>

Source

pub fn new(index: impl Into<String>, hash: impl Into<String>) -> Self

Start a query against index (the logical name) and its schema hash.

Source

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.

Source

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.

Source

pub fn must_not(self, query: impl AsQuery<Root>) -> Self

An exclusion clause (bool.must_not). An absent clause excludes nothing.

Source

pub fn should(self, query: impl AsQuery<Root>) -> Self

An optional, scoring clause (bool.should). An absent clause adds nothing.

Source

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.

Source

pub fn sort(self, sort: Sort) -> Self

Source

pub fn min_score(self, min_score: f32) -> Self

Drop hits scoring below min_score.

Source

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).

Source

pub fn track_scores(self, track: bool) -> Self

Compute relevance scores even when sorting by a field.

Source

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.

Source

pub fn collapse(self, field: impl Into<String>) -> Self

Collapse hits so only the top hit per field value is returned.

Source

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.

Source

pub fn highlight(self, highlight: Highlight) -> Self

Attach match highlighting (see Highlight).

Source

pub fn from(self, from: u64) -> Self

Offset of the first hit to return.

Source

pub fn size(self, size: u64) -> Self

Maximum number of hits to return.

Source

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.

Source

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.

Source

pub fn body(&self) -> Value

The request body this search will POST to _search. Pure — useful for tests and debugging.

Source

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.

Source

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

pub async fn ids(&self, client: &Client) -> Result<Vec<String>>

Execute the search and return only the matching document ids (the root primary keys, stringified by OpenSearch) — no sources are fetched, so this is the cheap way to feed another lookup (e.g. load the rows from Postgres). Sort, from, and size apply as in send; the page’s ids are returned in order.

Source

pub async fn count(&self, client: &Client) -> Result<u64>

Execute the query as a count: how many documents match, without fetching (or scoring) any hits — cheaper than send when only the total is needed. Sort, pagination, and nested projections are ignored (see count_body).

Source§

impl<T> Search<T>

Source

pub async fn send(&self, client: &Client) -> Result<SearchResponse<T>>

Execute the search and decode the hits into SearchResponse<T>.

Trait Implementations§

Source§

impl<T: Clone> Clone for Search<T>

Source§

fn clone(&self) -> Search<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Search<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Search<T>

§

impl<T> RefUnwindSafe for Search<T>

§

impl<T> Send for Search<T>

§

impl<T> Sync for Search<T>

§

impl<T> Unpin for Search<T>

§

impl<T> UnsafeUnpin for Search<T>

§

impl<T> UnwindSafe for Search<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more