add SearchHit structure

This commit is contained in:
Marin Postma 2021-04-19 10:13:13 +02:00
parent 09f13823f4
commit 526a05565e
No known key found for this signature in database
GPG Key ID: D5241F0C0C865F30

View File

@ -35,10 +35,18 @@ pub struct SearchQuery {
pub facet_distributions: Option<Vec<String>>, pub facet_distributions: Option<Vec<String>>,
} }
#[derive(Debug, Clone, Serialize)]
pub struct SearchHit {
#[serde(flatten)]
pub document: Map<String, Value>,
#[serde(rename = "_formatted", skip_serializing_if = "Map::is_empty")]
pub formatted: Map<String, Value>,
}
#[derive(Serialize)] #[derive(Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct SearchResult { pub struct SearchResult {
pub hits: Vec<Map<String, Value>>, pub hits: Vec<SearchHit>,
pub nb_hits: u64, pub nb_hits: u64,
pub exhaustive_nb_hits: bool, pub exhaustive_nb_hits: bool,
pub query: String, pub query: String,
@ -90,7 +98,11 @@ impl Index {
if let Some(ref attributes_to_highlight) = query.attributes_to_highlight { if let Some(ref attributes_to_highlight) = query.attributes_to_highlight {
highlighter.highlight_record(&mut object, &matching_words, 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(); let nb_hits = candidates.len();