mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-25 19:45:05 +08:00
Make use of helper function in one more place
This commit is contained in:
parent
cc6a2aec06
commit
65e3d61a95
@ -245,27 +245,6 @@ impl<'t, 'tokenizer> Matcher<'t, 'tokenizer, '_, '_> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns boundaries of the words that match the query.
|
|
||||||
pub fn matches(&mut self) -> Vec<MatchBounds> {
|
|
||||||
match &self.matches {
|
|
||||||
None => self.compute_matches().matches(),
|
|
||||||
Some((tokens, matches)) => matches
|
|
||||||
.iter()
|
|
||||||
.map(|m| MatchBounds {
|
|
||||||
start: tokens[match m.position {
|
|
||||||
MatchPosition::Word { token_position, .. } => token_position,
|
|
||||||
MatchPosition::Phrase {
|
|
||||||
token_positions: (first_token_position, _),
|
|
||||||
..
|
|
||||||
} => first_token_position,
|
|
||||||
}]
|
|
||||||
.byte_start,
|
|
||||||
length: m.match_len,
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_match_pos(&self, m: &Match, wt: WT, fl: FL) -> usize {
|
fn get_match_pos(&self, m: &Match, wt: WT, fl: FL) -> usize {
|
||||||
match m.position {
|
match m.position {
|
||||||
MatchPosition::Word { word_position, token_position } => match wt {
|
MatchPosition::Word { word_position, token_position } => match wt {
|
||||||
@ -287,6 +266,20 @@ impl<'t, 'tokenizer> Matcher<'t, 'tokenizer, '_, '_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns boundaries of the words that match the query.
|
||||||
|
pub fn matches(&mut self) -> Vec<MatchBounds> {
|
||||||
|
match &self.matches {
|
||||||
|
None => self.compute_matches().matches(),
|
||||||
|
Some((tokens, matches)) => matches
|
||||||
|
.iter()
|
||||||
|
.map(|m| MatchBounds {
|
||||||
|
start: tokens[self.get_match_pos(m, WT::Token, FL::First)].byte_start,
|
||||||
|
length: m.match_len,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the bounds in byte index of the crop window.
|
/// Returns the bounds in byte index of the crop window.
|
||||||
fn crop_bounds(
|
fn crop_bounds(
|
||||||
&self,
|
&self,
|
||||||
|
Loading…
Reference in New Issue
Block a user