mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
Patch prefix match
This commit is contained in:
parent
ba8dcc2d78
commit
f7e7f438f8
@ -20,6 +20,7 @@ pub struct LocatedMatchingWords {
|
|||||||
pub value: Vec<Interned<String>>,
|
pub value: Vec<Interned<String>>,
|
||||||
pub positions: RangeInclusive<WordId>,
|
pub positions: RangeInclusive<WordId>,
|
||||||
pub is_prefix: bool,
|
pub is_prefix: bool,
|
||||||
|
pub original_char_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Structure created from a query tree
|
/// Structure created from a query tree
|
||||||
@ -101,10 +102,12 @@ impl MatchingWords {
|
|||||||
positions: located_term.positions.clone(),
|
positions: located_term.positions.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
words.push(LocatedMatchingWords {
|
words.push(LocatedMatchingWords {
|
||||||
value: matching_words,
|
value: matching_words,
|
||||||
positions: located_term.positions.clone(),
|
positions: located_term.positions.clone(),
|
||||||
is_prefix: term.is_prefix,
|
is_prefix: term.is_prefix,
|
||||||
|
original_char_count: ctx.word_interner.get(term.original).chars().count(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +134,11 @@ impl MatchingWords {
|
|||||||
let word = self.word_interner.get(*word);
|
let word = self.word_interner.get(*word);
|
||||||
// if the word is a prefix we match using starts_with.
|
// if the word is a prefix we match using starts_with.
|
||||||
if located_words.is_prefix && token.lemma().starts_with(word) {
|
if located_words.is_prefix && token.lemma().starts_with(word) {
|
||||||
let char_len = token.original_lengths(word.len()).0;
|
let Some((char_index, c)) = word.char_indices().take(located_words.original_char_count).last() else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let prefix_length = char_index + c.len_utf8();
|
||||||
|
let char_len = token.original_lengths(prefix_length).0;
|
||||||
let ids = &located_words.positions;
|
let ids = &located_words.positions;
|
||||||
return Some(MatchType::Full { char_len, ids });
|
return Some(MatchType::Full { char_len, ids });
|
||||||
// else we exact match the token.
|
// else we exact match the token.
|
||||||
|
Loading…
Reference in New Issue
Block a user