Lookup documents by a secondary index value.
(
&self,
collection: &str,
path: &str,
value: &str,
)
| 54 | |
| 55 | /// Lookup documents by a secondary index value. |
| 56 | pub fn index_lookup( |
| 57 | &self, |
| 58 | collection: &str, |
| 59 | path: &str, |
| 60 | value: &str, |
| 61 | ) -> crate::Result<Vec<String>> { |
| 62 | let prefix_with_value = format!("{value}:"); |
| 63 | let results = self.sparse.range_scan( |
| 64 | self.tenant_id, |
| 65 | collection, |
| 66 | path, |
| 67 | Some(prefix_with_value.as_bytes()), |
| 68 | None, |
| 69 | 1000, |
| 70 | )?; |
| 71 | |
| 72 | let mut doc_ids = Vec::new(); |
| 73 | for (key, _) in results { |
| 74 | if let Some(doc_id) = key.rsplit(':').next() { |
| 75 | let expected_prefix = format!("{}:{collection}:{path}:{value}:", self.tenant_id); |
| 76 | if key.starts_with(&expected_prefix) { |
| 77 | doc_ids.push(doc_id.to_string()); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | Ok(doc_ids) |
| 82 | } |
| 83 | } |