mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 05:14:27 +01:00
First version of highlight after refacto
This commit is contained in:
parent
a03d9d496e
commit
60f6d1c373
@ -308,7 +308,7 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
|
|||||||
) -> Value {
|
) -> Value {
|
||||||
match value {
|
match value {
|
||||||
Value::String(old_string) => {
|
Value::String(old_string) => {
|
||||||
let value = self.format_string(old_string, need_to_crop, need_to_highlight);
|
let value = self.format_string(old_string, matcher, need_to_crop, need_to_highlight);
|
||||||
Value::String(value)
|
Value::String(value)
|
||||||
}
|
}
|
||||||
Value::Array(values) => Value::Array(
|
Value::Array(values) => Value::Array(
|
||||||
@ -326,19 +326,28 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
|
|||||||
value => value,
|
value => value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn format_string(&self, s: String, need_to_crop: Option<u32>, need_to_highlight: bool) -> String {
|
fn format_string(&self, s: String, matcher: &impl Matcher, need_to_crop: Option<u32>, need_to_highlight: bool) -> String {
|
||||||
|
let analyzed = self.analyzer.analyze(&s);
|
||||||
let word_iter: Box<dyn Iterator<Item = (String, bool)>> = if let Some(_crop_len) = need_to_crop {
|
let word_iter: Box<dyn Iterator<Item = (String, bool)>> = if let Some(_crop_len) = need_to_crop {
|
||||||
// cropping iterator
|
// cropping iterator
|
||||||
todo!()
|
todo!()
|
||||||
} else {
|
} else {
|
||||||
// normal Iterator
|
Box::new(analyzed.reconstruct().map(|(word, token)| {
|
||||||
todo!()
|
if token.is_word() && matcher.matches(token.text()){
|
||||||
|
(word.to_string(), true)
|
||||||
|
} else {
|
||||||
|
(word.to_string(), false)
|
||||||
|
}
|
||||||
|
}))
|
||||||
};
|
};
|
||||||
|
|
||||||
word_iter.map(|(word, is_match)| {
|
word_iter.map(|(word, is_match)| {
|
||||||
if need_to_highlight && is_match {
|
if need_to_highlight && is_match {
|
||||||
// highlight word
|
let mut new_word = String::new();
|
||||||
todo!()
|
new_word.push_str(&self.marks.0);
|
||||||
|
new_word.push_str(&word);
|
||||||
|
new_word.push_str(&self.marks.1);
|
||||||
|
new_word
|
||||||
} else {
|
} else {
|
||||||
word
|
word
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user