mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-22 21:04:27 +01:00
Merge #216
216: optimize cropping r=MarinPostma a=MarinPostma Optimize cropping as per @kerollmops suggestion. Co-authored-by: marin postma <postma.marin@protonmail.com> Co-authored-by: marin <postma.marin@protonmail.com>
This commit is contained in:
commit
70661ce50d
@ -496,18 +496,19 @@ impl<'a, A: AsRef<[u8]>> Formatter<'a, A> {
|
||||
|
||||
tokens
|
||||
.map(|(word, token)| {
|
||||
if format_options.highlight && token.is_word() && matcher.matches(token.text()).is_some() {
|
||||
let mut new_word = String::new();
|
||||
new_word.push_str(&self.marks.0);
|
||||
if format_options.highlight && token.is_word() {
|
||||
if let Some(match_len) = matcher.matches(token.text()) {
|
||||
let mut new_word = String::new();
|
||||
|
||||
new_word.push_str(&self.marks.0);
|
||||
new_word.push_str(&word[..match_len]);
|
||||
new_word.push_str(&self.marks.1);
|
||||
new_word.push_str(&word[match_len..]);
|
||||
|
||||
return Cow::Owned(new_word)
|
||||
}
|
||||
Cow::Owned(new_word)
|
||||
} else {
|
||||
Cow::Borrowed(word)
|
||||
}
|
||||
Cow::Borrowed(word)
|
||||
})
|
||||
.collect::<String>()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user