Skip to content

Commit 548ec19

Browse files
Merge #632
632: Add `indices` to `MatchRange` r=curquiza a=LukasKalbertodt See meilisearch/meilisearch#5005 I already tested this with my production project, where it works as expected. Unfortunately, I believe this is a breaking change. But shouldn't be a big problem, since this is still pre 1.0. ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Lukas Kalbertodt <[email protected]>
2 parents 8575e24 + 737b519 commit 548ec19

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/search.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ use std::collections::HashMap;
1010
pub struct MatchRange {
1111
pub start: usize,
1212
pub length: usize,
13+
14+
/// If the match is somewhere inside a (potentially nested) array, this
15+
/// field is set to the index/indices of the matched element(s).
16+
///
17+
/// In the simple case, if the field has the value `["foo", "bar"]`, then
18+
/// searching for `ba` will return `indices: Some([1])`. If the value
19+
/// contains multiple nested arrays, the first index describes the most
20+
/// top-level array, and descending from there. For example, if the value is
21+
/// `[{ x: "cat" }, "bear", { y: ["dog", "fox"] }]`, searching for `dog`
22+
/// will return `indices: Some([2, 0])`.
23+
pub indices: Option<Vec<usize>>,
1324
}
1425

1526
#[derive(Serialize, Debug, Eq, PartialEq, Clone)]
@@ -1122,7 +1133,8 @@ mod tests {
11221133
.unwrap(),
11231134
&vec![MatchRange {
11241135
start: 0,
1125-
length: 5
1136+
length: 5,
1137+
indices: None,
11261138
}]
11271139
);
11281140
Ok(())

0 commit comments

Comments
 (0)