mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-11 05:54:30 +01:00
Test and Fix prefix highlight
This commit is contained in:
parent
bd30ee97b8
commit
6dc345bc53
@ -376,8 +376,10 @@ impl<'t> Matcher<'t, '_> {
|
||||
}
|
||||
|
||||
formatted.push(self.highlight_prefix);
|
||||
formatted.push(&self.text[token.byte_start..token.byte_end]);
|
||||
formatted.push(&self.text[token.byte_start..][..m.match_len]);
|
||||
formatted.push(self.highlight_suffix);
|
||||
formatted
|
||||
.push(&self.text[token.byte_start + m.match_len..token.byte_end]);
|
||||
|
||||
byte_index = token.byte_end;
|
||||
}
|
||||
@ -516,6 +518,17 @@ mod tests {
|
||||
&matcher.format(highlight, crop),
|
||||
"Natalie risk her future to build a <em>world</em> with <em>the</em> boy she loves."
|
||||
);
|
||||
|
||||
// Text containing some matches by prefix.
|
||||
let text = "Natalie risk her future to build a worldle with the boy she loves.";
|
||||
let analyzed = analyzer.analyze(&text);
|
||||
let tokens: Vec<_> = analyzed.tokens().collect();
|
||||
let mut matcher = builder.build(&tokens[..], text);
|
||||
// no crop should return complete text with highlighted matches.
|
||||
assert_eq!(
|
||||
&matcher.format(highlight, crop),
|
||||
"Natalie risk her future to build a <em>world</em>le with <em>the</em> boy she loves."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user