From 526a05565efbdf9fadbaeee8267d4ac4a6351b65 Mon Sep 17 00:00:00 2001 From: Marin Postma Date: Mon, 19 Apr 2021 10:13:13 +0200 Subject: [PATCH] add SearchHit structure --- meilisearch-http/src/index/search.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/meilisearch-http/src/index/search.rs b/meilisearch-http/src/index/search.rs index 4b9753b82..28eb7af98 100644 --- a/meilisearch-http/src/index/search.rs +++ b/meilisearch-http/src/index/search.rs @@ -35,10 +35,18 @@ pub struct SearchQuery { pub facet_distributions: Option>, } +#[derive(Debug, Clone, Serialize)] +pub struct SearchHit { + #[serde(flatten)] + pub document: Map, + #[serde(rename = "_formatted", skip_serializing_if = "Map::is_empty")] + pub formatted: Map, +} + #[derive(Serialize)] #[serde(rename_all = "camelCase")] pub struct SearchResult { - pub hits: Vec>, + pub hits: Vec, pub nb_hits: u64, pub exhaustive_nb_hits: bool, pub query: String, @@ -90,7 +98,11 @@ impl Index { if let Some(ref attributes_to_highlight) = query.attributes_to_highlight { highlighter.highlight_record(&mut object, &matching_words, attributes_to_highlight); } - documents.push(object); + let hit = SearchHit { + document: object, + formatted: Map::new(), + }; + documents.push(hit); } let nb_hits = candidates.len();