From 737b519ddc10561bb4905c706f7b1a8d6d509857 Mon Sep 17 00:00:00 2001
From: Lukas Kalbertodt <lukas.kalbertodt@gmail.com>
Date: Tue, 14 Jan 2025 10:20:41 +0100
Subject: [PATCH] Add `indices` to `MatchRange` (v1.12 feature)

See https://github.com/meilisearch/meilisearch/pull/5005
---
 src/search.rs | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/search.rs b/src/search.rs
index 824db05c..d1f95ae8 100644
--- a/src/search.rs
+++ b/src/search.rs
@@ -10,6 +10,17 @@ use std::collections::HashMap;
 pub struct MatchRange {
     pub start: usize,
     pub length: usize,
+
+    /// If the match is somewhere inside a (potentially nested) array, this
+    /// field is set to the index/indices of the matched element(s).
+    ///
+    /// In the simple case, if the field has the value `["foo", "bar"]`, then
+    /// searching for `ba` will return `indices: Some([1])`. If the value
+    /// contains multiple nested arrays, the first index describes the most
+    /// top-level array, and descending from there. For example, if the value is
+    /// `[{ x: "cat" }, "bear", { y: ["dog", "fox"] }]`, searching for `dog`
+    /// will return `indices: Some([2, 0])`.
+    pub indices: Option<Vec<usize>>,
 }
 
 #[derive(Serialize, Debug, Eq, PartialEq, Clone)]
@@ -1122,7 +1133,8 @@ mod tests {
                 .unwrap(),
             &vec![MatchRange {
                 start: 0,
-                length: 5
+                length: 5,
+                indices: None,
             }]
         );
         Ok(())