mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
optimize fromat string
This commit is contained in:
parent
f6d1fb7ac2
commit
c4ee937635
@ -572,26 +572,23 @@ impl<'a, A: AsRef<[u8]>> Formatter<'a, A> {
|
|||||||
None => Box::new(analyzed.reconstruct()),
|
None => Box::new(analyzed.reconstruct()),
|
||||||
};
|
};
|
||||||
|
|
||||||
tokens
|
tokens.fold(String::new(), |mut out, (word, token)| {
|
||||||
.map(|(word, token)| {
|
// Check if we need to do highlighting or computed matches before calling
|
||||||
// Check if we need to do highlighting or computed matches before calling
|
// Matcher::match since the call is expensive.
|
||||||
// Matcher::match since the call is expensive.
|
if format_options.highlight && token.is_word() {
|
||||||
if format_options.highlight && token.is_word() {
|
if let Some(length) = matcher.matches(token.text()) {
|
||||||
if let Some(length) = matcher.matches(token.text()) {
|
if format_options.highlight {
|
||||||
if format_options.highlight {
|
out.push_str(&self.marks.0);
|
||||||
let mut new_word = String::new();
|
out.push_str(&word[..length]);
|
||||||
new_word.push_str(&self.marks.0);
|
out.push_str(&self.marks.1);
|
||||||
new_word.push_str(&word[..length]);
|
out.push_str(&word[length..]);
|
||||||
new_word.push_str(&self.marks.1);
|
return out;
|
||||||
new_word.push_str(&word[length..]);
|
|
||||||
|
|
||||||
return Cow::Owned(new_word);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Cow::Borrowed(word)
|
}
|
||||||
})
|
out.push_str(word);
|
||||||
.collect::<String>()
|
out
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user