use meta from milli

This commit is contained in:
mpostma 2021-03-11 19:40:18 +01:00
parent 1fad72e019
commit 79a4bc8129
No known key found for this signature in database
GPG key ID: CBC8A7C1D7A28C3A
5 changed files with 207 additions and 210 deletions

View file

@ -6,7 +6,7 @@ use either::Either;
use anyhow::bail;
use heed::RoTxn;
use meilisearch_tokenizer::{Analyzer, AnalyzerConfig};
use milli::{FacetCondition, facet::FacetValue};
use milli::{FacetCondition, MatchingWords, facet::FacetValue};
use serde::{Serialize, Deserialize};
use serde_json::{Value, Map};
@ -71,7 +71,7 @@ impl Index {
let milli::SearchResult {
documents_ids,
found_words,
matching_words,
candidates,
..
} = search.execute()?;
@ -102,7 +102,7 @@ impl Index {
for (_id, obkv) in self.documents(&rtxn, documents_ids)? {
let mut object = milli::obkv_to_json(&displayed_fields_ids, &fields_ids_map, obkv).unwrap();
if let Some(ref attributes_to_highlight) = query.attributes_to_highlight {
highlighter.highlight_record(&mut object, &found_words, attributes_to_highlight);
highlighter.highlight_record(&mut object, &matching_words, attributes_to_highlight);
}
documents.push(object);
}
@ -173,7 +173,7 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
Self { analyzer }
}
pub fn highlight_value(&self, value: Value, words_to_highlight: &HashSet<String>) -> Value {
pub fn highlight_value(&self, value: Value, words_to_highlight: &MatchingWords) -> Value {
match value {
Value::Null => Value::Null,
Value::Bool(boolean) => Value::Bool(boolean),
@ -183,7 +183,7 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
let analyzed = self.analyzer.analyze(&old_string);
for (word, token) in analyzed.reconstruct() {
if token.is_word() {
let to_highlight = words_to_highlight.contains(token.text());
let to_highlight = words_to_highlight.matches(token.text());
if to_highlight {
string.push_str("<mark>")
}
@ -215,7 +215,7 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
pub fn highlight_record(
&self,
object: &mut Map<String, Value>,
words_to_highlight: &HashSet<String>,
words_to_highlight: &MatchingWords,
attributes_to_highlight: &HashSet<String>,
) {
// TODO do we need to create a string for element that are not and needs to be highlight?