mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-10-31 16:06:31 +00:00 
			
		
		
		
	Test and Fix prefix highlight
This commit is contained in:
		| @@ -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] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user