mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
Put crop markers direclty around words
This commit is contained in:
parent
a93cd8c61c
commit
56e0edd621
@ -225,25 +225,6 @@ impl<'t> Matcher<'t, '_> {
|
||||
}
|
||||
}
|
||||
|
||||
// if tokens after the end of the window are separators,
|
||||
// then add them to the window in order to keep context in cropped text.
|
||||
while let Some(_separator_kind) = last_token_position
|
||||
.checked_add(1)
|
||||
.and_then(|i| self.tokens.get(i))
|
||||
.and_then(|t| t.is_separator())
|
||||
{
|
||||
last_token_position += 1;
|
||||
}
|
||||
|
||||
// same for start
|
||||
while let Some(_separator_kind) = first_token_position
|
||||
.checked_sub(1)
|
||||
.and_then(|i| self.tokens.get(i))
|
||||
.and_then(|t| t.is_separator())
|
||||
{
|
||||
first_token_position -= 1;
|
||||
}
|
||||
|
||||
(first_token_position, last_token_position)
|
||||
}
|
||||
|
||||
@ -593,7 +574,7 @@ mod tests {
|
||||
// no highlight should return 10 first words with a marker at the end.
|
||||
assert_eq!(
|
||||
&matcher.format(highlight, crop),
|
||||
"A quick brown fox can not jump 32 feet, right? …"
|
||||
"A quick brown fox can not jump 32 feet, right…"
|
||||
);
|
||||
|
||||
// Text without any match starting by a separator.
|
||||
@ -604,7 +585,7 @@ mod tests {
|
||||
// no highlight should return 10 first words with a marker at the end.
|
||||
assert_eq!(
|
||||
&matcher.format(highlight, crop),
|
||||
"(A quick brown fox can not jump 32 feet, right? …"
|
||||
"(A quick brown fox can not jump 32 feet, right…"
|
||||
);
|
||||
|
||||
// Test phrase propagation
|
||||
@ -615,7 +596,7 @@ mod tests {
|
||||
// should crop the phrase instead of croping around the match.
|
||||
assert_eq!(
|
||||
&matcher.format(highlight, crop),
|
||||
"…. Split The World is a book written by Emily Henry. …"
|
||||
"…Split The World is a book written by Emily Henry…"
|
||||
);
|
||||
|
||||
// Text containing some matches.
|
||||
@ -626,7 +607,7 @@ mod tests {
|
||||
// no highlight should return 10 last words with a marker at the start.
|
||||
assert_eq!(
|
||||
&matcher.format(highlight, crop),
|
||||
"… future to build a world with the boy she loves."
|
||||
"…future to build a world with the boy she loves…"
|
||||
);
|
||||
|
||||
// Text containing all matches.
|
||||
@ -706,7 +687,7 @@ mod tests {
|
||||
// both should return 10 first words with a marker at the end.
|
||||
assert_eq!(
|
||||
&matcher.format(highlight, crop),
|
||||
"A quick brown fox can not jump 32 feet, right? …"
|
||||
"A quick brown fox can not jump 32 feet, right…"
|
||||
);
|
||||
|
||||
// Text containing some matches.
|
||||
@ -717,7 +698,7 @@ mod tests {
|
||||
// both should return 10 last words with a marker at the start and highlighted matches.
|
||||
assert_eq!(
|
||||
&matcher.format(highlight, crop),
|
||||
"… future to build a <em>world</em> with <em>the</em> boy she loves."
|
||||
"…future to build a <em>world</em> with <em>the</em> boy she loves…"
|
||||
);
|
||||
|
||||
// Text containing all matches.
|
||||
|
Loading…
Reference in New Issue
Block a user