-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SearchResults<T> doesn't implement trait serde::Serialize #517
Comments
This is not a bug. When you search with Meilisearch's client it will return the SearchResults is just the response object with the details for the search result (i.e. how many hits or results were returned, in what page you are in case that you are using pagination, etc.) and it's obviously not meant to be exposed to the user, hence why I guess it doesn't implement Serialize. It's the API telling you that you are doing something wrong. In your case, I would just extract the hits from it and send the response to the consumer of the |
What is the solutions for this case? |
The solution is entirely dependent on what you WANT the API to return. Example:
I would say that adding your own struct for these return types is better. |
Running into the same thing, trying to return the query result as Json in a Rocket server. I also had expected the result structs to implement Serialize when T supports it, since the data in the results is pretty harmless to be exposed to the client. |
Here's a workaround for now, by defining a new struct that mirrors the search results, then mapping SearchResult to a Vector of Combined Items and then finally construct a serializable structure. (CombinedItem is my data structure, similar to the author's Posting) #[derive(Serialize)]
struct SerializableSearchResults {
hits: Vec<CombinedItem>,
}
#[get("/search")]
pub async fn search(query: web::Query<SearchQuery>) -> HttpResponse {
let client = Client::new("http://localhost:7700", None::<&str>).unwrap();
let index = client.index("library");
let search_results: SearchResults<CombinedItem> = index.search()
.with_query(&query.query)
.execute()
.await
.unwrap();
let hits: Vec<CombinedItem> = search_results.hits.into_iter().map(|result| result.result).collect();
let serializable_results = SerializableSearchResults {
hits,
};
HttpResponse::Ok().json(serializable_results)
} |
Description
Not sure if this is a bug or a feature request.
SearchResults doesn't seem to have the serde serialize trait, this prevents passing the results to something like actix httpresponse json.
code block
Expected behavior
SearchResults will have the serde serialize trait.
Current behavior
HttpResponse::Ok().json(results)
---- ^^^^^^^ the trait
_::_serde::Serialize
is not implemented forSearchResults<Posting>
Screenshots or Logs
N/A
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: