From d8e25a086387ff32a8849669c71abced908e2a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Fri, 27 Nov 2020 14:52:53 +0100 Subject: [PATCH] Order documents by the first custom criterion on basic searches --- src/search/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/search/mod.rs b/src/search/mod.rs index b62a831c8..b56f5a345 100644 --- a/src/search/mod.rs +++ b/src/search/mod.rs @@ -277,7 +277,19 @@ impl<'a> Search<'a> { } let found_words = derived_words.into_iter().flat_map(|(w, _)| w).map(|(w, _)| w).collect(); - let documents_ids = documents.into_iter().flatten().take(limit).collect(); + let documents_ids = match order_by_facet { + Some((fid, ftype, order)) => { + let mut ordered_documents = Vec::new(); + for documents_ids in documents { + let docids = self.facet_ordered(fid, ftype, order, documents_ids, limit)?; + ordered_documents.push(docids); + if ordered_documents.iter().map(Vec::len).sum::() >= limit { break } + } + ordered_documents.into_iter().flatten().take(limit).collect() + }, + None => documents.into_iter().flatten().take(limit).collect(), + }; + Ok(SearchResult { found_words, documents_ids }) } }