From 9809ded23d18d9290f1fccadd92a4e802ead4f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 16 Jan 2020 11:38:23 +0100 Subject: [PATCH] Implement synonym fetching --- meilisearch-core/src/query_tree.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/meilisearch-core/src/query_tree.rs b/meilisearch-core/src/query_tree.rs index 6ac246963..597df6f79 100644 --- a/meilisearch-core/src/query_tree.rs +++ b/meilisearch-core/src/query_tree.rs @@ -142,9 +142,19 @@ fn split_best_frequency<'a>(reader: &heed::RoTxn, ctx: &Context, word: &' } fn fetch_synonyms(reader: &heed::RoTxn, ctx: &Context, words: &[&str]) -> MResult>> { - let words = words.join(" "); // TODO ugly - // synonyms.synonyms(reader, words.as_bytes()).cloned().unwrap_or_default() - Ok(vec![]) + let words = words.join(" "); + let set = ctx.synonyms.synonyms(reader, words.as_bytes())?.unwrap_or_default(); + + let mut strings = Vec::new(); + let mut stream = set.stream(); + while let Some(input) = stream.next() { + if let Ok(input) = std::str::from_utf8(input) { + let alts = input.split_ascii_whitespace().map(ToOwned::to_owned).collect(); + strings.push(alts); + } + } + + Ok(strings) } fn is_last(iter: I) -> impl Iterator {