Struct SearchQuery

Source
pub struct SearchQuery<'a, Http: HttpClient> {
Show 26 fields pub query: Option<&'a str>, pub offset: Option<usize>, pub limit: Option<usize>, pub page: Option<usize>, pub hits_per_page: Option<usize>, pub filter: Option<Filter<'a>>, pub facets: Option<Selectors<&'a [&'a str]>>, pub sort: Option<&'a [&'a str]>, pub attributes_to_search_on: Option<&'a [&'a str]>, pub attributes_to_retrieve: Option<Selectors<&'a [&'a str]>>, pub attributes_to_crop: Option<Selectors<&'a [(&'a str, Option<usize>)]>>, pub crop_length: Option<usize>, pub crop_marker: Option<&'a str>, pub attributes_to_highlight: Option<Selectors<&'a [&'a str]>>, pub highlight_pre_tag: Option<&'a str>, pub highlight_post_tag: Option<&'a str>, pub show_matches_position: Option<bool>, pub show_ranking_score: Option<bool>, pub show_ranking_score_details: Option<bool>, pub matching_strategy: Option<MatchingStrategies>, pub distinct: Option<&'a str>, pub ranking_score_threshold: Option<f64>, pub locales: Option<&'a [&'a str]>, pub hybrid: Option<HybridSearch<'a>>, pub vector: Option<&'a [f32]>, pub retrieve_vectors: Option<bool>, /* private fields */
}
Expand description

A struct representing a query.

You can add search parameters using the builder syntax.

See this page for the official list and description of all parameters.

§Examples

#[derive(Serialize, Deserialize, Debug)]
struct Movie {
    name: String,
    description: String,
}

let mut res = SearchQuery::new(&index)
    .with_query("space")
    .with_offset(42)
    .with_limit(21)
    .execute::<Movie>()
    .await
    .unwrap();

assert_eq!(res.limit, Some(21));
let query = index.search()
    .with_query("space")
    .with_offset(42)
    .with_limit(21)
    .build(); // you can also execute() instead of build()

Fields§

§query: Option<&'a str>

The text that will be searched for among the documents.

§offset: Option<usize>

The number of documents to skip.

If the value of the parameter offset is n, the n first documents (ordered by relevance) will not be returned. This is helpful for pagination.

Example: If you want to skip the first document, set offset to 1.

§limit: Option<usize>

The maximum number of documents returned.

If the value of the parameter limit is n, there will never be more than n documents in the response. This is helpful for pagination.

Example: If you don’t want to get more than two documents, set limit to 2.

Default: 20

§page: Option<usize>

The page number on which you paginate.

Pagination starts at 1. If page is 0, no results are returned.

Default: None unless hits_per_page is defined, in which case page is 1

§hits_per_page: Option<usize>

The maximum number of results in a page. A page can contain less results than the number of hits_per_page.

Default: None unless page is defined, in which case 20

§filter: Option<Filter<'a>>

Filter applied to documents.

Read the dedicated guide to learn the syntax.

§facets: Option<Selectors<&'a [&'a str]>>

Facets for which to retrieve the matching count.

Can be set to a wildcard value that will select all existing attributes.

Default: all attributes found in the documents.

§sort: Option<&'a [&'a str]>

Attributes to sort.

§attributes_to_search_on: Option<&'a [&'a str]>

Attributes to perform the search on.

Specify the subset of searchableAttributes for a search without modifying Meilisearch’s index settings.

Default: all searchable attributes found in the documents.

§attributes_to_retrieve: Option<Selectors<&'a [&'a str]>>

Attributes to display in the returned documents.

Can be set to a wildcard value that will select all existing attributes.

Default: all attributes found in the documents.

§attributes_to_crop: Option<Selectors<&'a [(&'a str, Option<usize>)]>>

Attributes whose values have to be cropped.

Attributes are composed by the attribute name and an optional usize that overwrites the crop_length parameter.

Can be set to a wildcard value that will select all existing attributes.

§crop_length: Option<usize>

Maximum number of words including the matched query term(s) contained in the returned cropped value(s).

See attributes_to_crop.

Default: 10

§crop_marker: Option<&'a str>

Marker at the start and the end of a cropped value.

ex: ...middle of a crop...

Default: ...

§attributes_to_highlight: Option<Selectors<&'a [&'a str]>>

Attributes whose values will contain highlighted matching terms.

Can be set to a wildcard value that will select all existing attributes.

§highlight_pre_tag: Option<&'a str>

Tag in front of a highlighted term.

ex: <mytag>hello world

Default: <em>

§highlight_post_tag: Option<&'a str>

Tag after a highlighted term.

ex: hello world</ mytag>

Default: </em>

§show_matches_position: Option<bool>

Defines whether an object that contains information about the matches should be returned or not.

Default: false

§show_ranking_score: Option<bool>

Defines whether to show the relevancy score of the match.

Default: false

§show_ranking_score_details: Option<bool>

Adds a detailed global ranking score field to each document.

Default: false

§matching_strategy: Option<MatchingStrategies>

Defines the strategy on how to handle queries containing multiple words.

§distinct: Option<&'a str>

Defines one attribute in the filterableAttributes list as a distinct attribute.

§ranking_score_threshold: Option<f64>

Excludes results below the specified ranking score.

§locales: Option<&'a [&'a str]>

Defines the language of the search query.

§hybrid: Option<HybridSearch<'a>>

Configures Meilisearch to return search results based on a query’s meaning and context.

§vector: Option<&'a [f32]>

Use a custom vector to perform a search query.

§retrieve_vectors: Option<bool>

Defines whether document embeddings are returned with search results.

Implementations§

Source§

impl<'a, Http: HttpClient> SearchQuery<'a, Http>

Source

pub fn new(index: &'a Index<Http>) -> SearchQuery<'a, Http>

Source

pub fn with_query<'b>( &'b mut self, query: &'a str, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_offset<'b>( &'b mut self, offset: usize, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_limit<'b>( &'b mut self, limit: usize, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_page<'b>(&'b mut self, page: usize) -> &'b mut SearchQuery<'a, Http>

Add the page number on which to paginate.

§Example
let mut index = client.index("search_with_page");

let mut query = SearchQuery::new(&index);
query.with_query("").with_page(2);
let res = query.execute::<Movie>().await.unwrap();
Source

pub fn with_hits_per_page<'b>( &'b mut self, hits_per_page: usize, ) -> &'b mut SearchQuery<'a, Http>

Add the maximum number of results per page.

§Example
let mut index = client.index("search_with_hits_per_page");

let mut query = SearchQuery::new(&index);
query.with_query("").with_hits_per_page(2);
let res = query.execute::<Movie>().await.unwrap();
Source

pub fn with_filter<'b>( &'b mut self, filter: &'a str, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_array_filter<'b>( &'b mut self, filter: Vec<&'a str>, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_retrieve_vectors<'b>( &'b mut self, retrieve_vectors: bool, ) -> &'b mut SearchQuery<'a, Http>

Defines whether document embeddings are returned with search results.

Source

pub fn with_facets<'b>( &'b mut self, facets: Selectors<&'a [&'a str]>, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_sort<'b>( &'b mut self, sort: &'a [&'a str], ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_attributes_to_search_on<'b>( &'b mut self, attributes_to_search_on: &'a [&'a str], ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_attributes_to_retrieve<'b>( &'b mut self, attributes_to_retrieve: Selectors<&'a [&'a str]>, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_attributes_to_crop<'b>( &'b mut self, attributes_to_crop: Selectors<&'a [(&'a str, Option<usize>)]>, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_crop_length<'b>( &'b mut self, crop_length: usize, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_crop_marker<'b>( &'b mut self, crop_marker: &'a str, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_attributes_to_highlight<'b>( &'b mut self, attributes_to_highlight: Selectors<&'a [&'a str]>, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_highlight_pre_tag<'b>( &'b mut self, highlight_pre_tag: &'a str, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_highlight_post_tag<'b>( &'b mut self, highlight_post_tag: &'a str, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_show_matches_position<'b>( &'b mut self, show_matches_position: bool, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_show_ranking_score<'b>( &'b mut self, show_ranking_score: bool, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_show_ranking_score_details<'b>( &'b mut self, show_ranking_score_details: bool, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_matching_strategy<'b>( &'b mut self, matching_strategy: MatchingStrategies, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_index_uid<'b>(&'b mut self) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_hybrid<'b>( &'b mut self, embedder: &'a str, semantic_ratio: f32, ) -> &'b mut SearchQuery<'a, Http>

Configures Meilisearch to return search results based on a query’s meaning and context

Source

pub fn with_vector<'b>( &'b mut self, vector: &'a [f32], ) -> &'b mut SearchQuery<'a, Http>

Use a custom vector to perform a search query

vector is mandatory when performing searches with userProvided embedders. You may also use vector to override an embedder’s automatic vector generation.

vector dimensions must match the dimensions of the embedder.

Source

pub fn with_distinct<'b>( &'b mut self, distinct: &'a str, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_ranking_score_threshold<'b>( &'b mut self, ranking_score_threshold: f64, ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn with_locales<'b>( &'b mut self, locales: &'a [&'a str], ) -> &'b mut SearchQuery<'a, Http>

Source

pub fn build(&mut self) -> SearchQuery<'a, Http>

Source

pub async fn execute<T: 'static + DeserializeOwned + Send + Sync>( &'a self, ) -> Result<SearchResults<T>, Error>

Execute the query and fetch the results.

Trait Implementations§

Source§

impl<'a, Http: Clone + HttpClient> Clone for SearchQuery<'a, Http>

Source§

fn clone(&self) -> SearchQuery<'a, Http>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, Http: Debug + HttpClient> Debug for SearchQuery<'a, Http>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a, Http: HttpClient> Serialize for SearchQuery<'a, Http>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'a, Http> Freeze for SearchQuery<'a, Http>

§

impl<'a, Http> RefUnwindSafe for SearchQuery<'a, Http>
where Http: RefUnwindSafe,

§

impl<'a, Http> Send for SearchQuery<'a, Http>

§

impl<'a, Http> Sync for SearchQuery<'a, Http>

§

impl<'a, Http> Unpin for SearchQuery<'a, Http>

§

impl<'a, Http> UnwindSafe for SearchQuery<'a, Http>
where Http: RefUnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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
Source§

impl<T> ErasedDestructor for T
where T: 'static,