This commit is contained in:
F. Levi 2024-10-04 11:30:31 +03:00
parent 8221c94e7f
commit c3de3a9ab7
2 changed files with 3 additions and 10 deletions

View File

@ -130,7 +130,7 @@ impl<'a> Iterator for MatchesIter<'a, '_> {
word.map(|word| self.matching_words.word_interner.get(word).as_str()) word.map(|word| self.matching_words.word_interner.get(word).as_str())
}) })
.collect(); .collect();
let partial = PartialMatch { matching_words: words, ids, char_len: 0 }; let partial = PartialMatch { matching_words: words, ids };
partial.match_token(self.token).or_else(|| self.next()) partial.match_token(self.token).or_else(|| self.next())
} }
@ -158,7 +158,6 @@ pub enum MatchType<'a> {
pub struct PartialMatch<'a> { pub struct PartialMatch<'a> {
matching_words: Vec<Option<&'a str>>, matching_words: Vec<Option<&'a str>>,
ids: &'a RangeInclusive<WordId>, ids: &'a RangeInclusive<WordId>,
char_len: usize,
} }
impl<'a> PartialMatch<'a> { impl<'a> PartialMatch<'a> {
@ -176,25 +175,20 @@ impl<'a> PartialMatch<'a> {
None => token.is_stopword(), None => token.is_stopword(),
}; };
let char_len = token.char_end - token.char_start;
// if there are remaining words to match in the phrase and the current token is matching, // if there are remaining words to match in the phrase and the current token is matching,
// return a new Partial match allowing the highlighter to continue. // return a new Partial match allowing the highlighter to continue.
if is_matching && matching_words.len() > 1 { if is_matching && matching_words.len() > 1 {
matching_words.remove(0); matching_words.remove(0);
Some(MatchType::Partial(Self { matching_words, ids, char_len })) Some(MatchType::Partial(Self { matching_words, ids }))
// if there is no remaining word to match in the phrase and the current token is matching, // if there is no remaining word to match in the phrase and the current token is matching,
// return a Full match. // return a Full match.
} else if is_matching { } else if is_matching {
Some(MatchType::Full { char_len, ids }) Some(MatchType::Full { char_len: token.char_end - token.char_start, ids })
// if the current token doesn't match, return None to break the match sequence. // if the current token doesn't match, return None to break the match sequence.
} else { } else {
None None
} }
} }
pub fn char_len(&self) -> usize {
self.char_len
}
} }
impl fmt::Debug for MatchingWords { impl fmt::Debug for MatchingWords {

View File

@ -139,7 +139,6 @@ impl<'t, 'tokenizer> Matcher<'t, 'tokenizer, '_, '_> {
Some(MatchType::Full { ids, .. }) => { Some(MatchType::Full { ids, .. }) => {
// save the token that closes the partial match as a match. // save the token that closes the partial match as a match.
matches.push(Match { matches.push(Match {
// @TODO: Shouldn't this be +1?
match_len: word.char_end - *first_word_char_start, match_len: word.char_end - *first_word_char_start,
ids: ids.clone().collect(), ids: ids.clone().collect(),
position: MatchPosition::Phrase { position: MatchPosition::Phrase {