MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / index_lookup

Method index_lookup

nodedb/src/engine/document/store/engine/batch.rs:56–82  ·  view source on GitHub ↗

Lookup documents by a secondary index value.

(
        &self,
        collection: &str,
        path: &str,
        value: &str,
    )

Source from the content-addressed store, hash-verified

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}

Calls 5

range_scanMethod · 0.80
to_stringMethod · 0.80
as_bytesMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45

Tested by 4

array_index_extractionFunction · 0.64
nested_field_indexFunction · 0.64