Order documents by the first custom criterion on basic searches

This commit is contained in:
Clément Renault 2020-11-27 14:52:53 +01:00
parent e0cc7faea1
commit d8e25a0863
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -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::<usize>() >= limit { break }
}
ordered_documents.into_iter().flatten().take(limit).collect()
},
None => documents.into_iter().flatten().take(limit).collect(),
};
Ok(SearchResult { found_words, documents_ids })
}
}