diff --git a/milli/src/search/matching_words.rs b/milli/src/search/matching_words.rs index 74ff14382..67bdefb37 100644 --- a/milli/src/search/matching_words.rs +++ b/milli/src/search/matching_words.rs @@ -42,10 +42,7 @@ impl MatchingWords { let len = bytes_to_highlight(word_to_highlight.text(), query_word); Some(word_to_highlight.num_chars_from_bytes(len)) } else { - Some( - word_to_highlight - .num_chars_from_bytes(word_to_highlight.text().len()), - ) + Some(word_to_highlight.num_chars_from_bytes(word_to_highlight.text().len())) } } _otherwise => None, @@ -276,61 +273,82 @@ mod tests { let matching_words = MatchingWords::from_query_tree(&query_tree); - assert_eq!(matching_words.matching_bytes(&Token{ - kind: TokenKind::Word, - word: Cow::Borrowed("word"), - byte_start: 0, - char_index: 0, - byte_end: "word".len(), - char_map: None, - }), Some(3)); - assert_eq!(matching_words.matching_bytes(&Token{ - kind: TokenKind::Word, - word: Cow::Borrowed("nyc"), - byte_start: 0, - char_index: 0, - byte_end: "nyc".len(), - char_map: None, - }), None); - assert_eq!(matching_words.matching_bytes(&Token{ - kind: TokenKind::Word, - word: Cow::Borrowed("world"), - byte_start: 0, - char_index: 0, - byte_end: "world".len(), - char_map: None, - }), Some(5)); - assert_eq!(matching_words.matching_bytes(&Token{ - kind: TokenKind::Word, - word: Cow::Borrowed("splitted"), - byte_start: 0, - char_index: 0, - byte_end: "splitted".len(), - char_map: None, - }), Some(5)); - assert_eq!(matching_words.matching_bytes(&Token{ - kind: TokenKind::Word, - word: Cow::Borrowed("thisnew"), - byte_start: 0, - char_index: 0, - byte_end: "thisnew".len(), - char_map: None, - }), None); - assert_eq!(matching_words.matching_bytes(&Token{ - kind: TokenKind::Word, - word: Cow::Borrowed("borld"), - byte_start: 0, - char_index: 0, - byte_end: "borld".len(), - char_map: None, - }), Some(5)); - assert_eq!(matching_words.matching_bytes(&Token{ - kind: TokenKind::Word, - word: Cow::Borrowed("wordsplit"), - byte_start: 0, - char_index: 0, - byte_end: "wordsplit".len(), - char_map: None, - }), Some(4)); + assert_eq!( + matching_words.matching_bytes(&Token { + kind: TokenKind::Word, + word: Cow::Borrowed("word"), + byte_start: 0, + char_index: 0, + byte_end: "word".len(), + char_map: None, + }), + Some(3) + ); + assert_eq!( + matching_words.matching_bytes(&Token { + kind: TokenKind::Word, + word: Cow::Borrowed("nyc"), + byte_start: 0, + char_index: 0, + byte_end: "nyc".len(), + char_map: None, + }), + None + ); + assert_eq!( + matching_words.matching_bytes(&Token { + kind: TokenKind::Word, + word: Cow::Borrowed("world"), + byte_start: 0, + char_index: 0, + byte_end: "world".len(), + char_map: None, + }), + Some(5) + ); + assert_eq!( + matching_words.matching_bytes(&Token { + kind: TokenKind::Word, + word: Cow::Borrowed("splitted"), + byte_start: 0, + char_index: 0, + byte_end: "splitted".len(), + char_map: None, + }), + Some(5) + ); + assert_eq!( + matching_words.matching_bytes(&Token { + kind: TokenKind::Word, + word: Cow::Borrowed("thisnew"), + byte_start: 0, + char_index: 0, + byte_end: "thisnew".len(), + char_map: None, + }), + None + ); + assert_eq!( + matching_words.matching_bytes(&Token { + kind: TokenKind::Word, + word: Cow::Borrowed("borld"), + byte_start: 0, + char_index: 0, + byte_end: "borld".len(), + char_map: None, + }), + Some(5) + ); + assert_eq!( + matching_words.matching_bytes(&Token { + kind: TokenKind::Word, + word: Cow::Borrowed("wordsplit"), + byte_start: 0, + char_index: 0, + byte_end: "wordsplit".len(), + char_map: None, + }), + Some(4) + ); } }