首页 > 解决方案 > MeiliSearch with Rust SDK search query with limit

问题描述

I am trying to search for documents by a search value and also set a limit. The default limit set by the SDK is 20 and I would like to increase it a little bit. With a standard curl this is easy but I struggle to implement the same functionality with the Rust SDK for MeiliSearch.

curl \
  'http://localhost:7700/indexes/movies/search' \
  --data '{ "q": "american","limit":55 }'

the docs (https://docs.meilisearch.com/references/documents.html#get-documents) offer this solution but I don't know how to send a search query value with this approach

let documents: Vec<Movie> = movies.get_documents(None, Some(55), None).await.unwrap(); 

my current way to search:

let results: SearchResults<Movie> = index
    .search()
    .with_query(&sometestval)
    .execute()
    .await
    .expect("Failed to execute query"); 

I tried to use arguments like .limit() but nothing worked. I am not sure if I overlooked something or this functionality is currently not supported by this relatively new project. If anybody has an idea I would be happy to hear it.

标签: rustmeilisearch

解决方案


You're close, it's not called limit() but with_limit().

let results: SearchResults<Movie> = index
    .search()
    .with_query(&sometestval)
    .with_limit(55)
    .execute()
    .await
    .expect("Failed to execute query"); 

See also "Limit - Search Parameters | MeiliSearch Documentation v0.18".


推荐阅读