Merge branch 'main' into indexer-edition-2024

This commit is contained in:
Louis Dureuil 2024-11-20 16:59:58 +01:00
commit 6e6acfcf1b
No known key found for this signature in database
330 changed files with 10063 additions and 1499 deletions

View file

@ -104,6 +104,8 @@ impl FormatOptions {
pub struct MatchBounds {
pub start: usize,
pub length: usize,
#[serde(skip_serializing_if = "Option::is_none")]
pub indices: Option<Vec<usize>>,
}
/// Structure used to analyze a string, compute words that match,
@ -219,15 +221,20 @@ impl<'t, 'tokenizer> Matcher<'t, 'tokenizer, '_, '_> {
}
/// Returns boundaries of the words that match the query.
pub fn matches(&mut self) -> Vec<MatchBounds> {
pub fn matches(&mut self, array_indices: &[usize]) -> Vec<MatchBounds> {
match &self.matches {
None => self.compute_matches().matches(),
None => self.compute_matches().matches(array_indices),
Some((tokens, matches)) => matches
.iter()
.map(|m| MatchBounds {
start: tokens[m.get_first_token_pos()].byte_start,
// TODO: Why is this in chars, while start is in bytes?
length: m.char_count,
indices: if array_indices.is_empty() {
None
} else {
Some(array_indices.to_owned())
},
})
.collect(),
}

View file

@ -96,6 +96,14 @@ impl<T> Setting<T> {
}
}
/// Returns other if self is not set.
pub fn or(self, other: Self) -> Self {
match self {
Setting::Set(_) | Setting::Reset => self,
Setting::NotSet => other,
}
}
/// Returns `true` if applying the new setting changed this setting
pub fn apply(&mut self, new: Self) -> bool
where