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

Method index_document

nodedb-spatial/src/geohash_index.rs:56–73  ·  view source on GitHub ↗

Index a geometry. Only Point geometries are indexed; others are skipped. Returns the geohash string if indexed, None if skipped.

(&mut self, doc_id: &str, geometry: &Geometry)

Source from the content-addressed store, hash-verified

54 /// Index a geometry. Only Point geometries are indexed; others are skipped.
55 /// Returns the geohash string if indexed, None if skipped.
56 pub fn index_document(&mut self, doc_id: &str, geometry: &Geometry) -> Option<String> {
57 let Geometry::Point { coordinates } = geometry else {
58 return None;
59 };
60 let lng = coordinates[0];
61 let lat = coordinates[1];
62
63 // Remove old entry if exists.
64 self.remove_document(doc_id);
65
66 let hash = geohash_encode(lng, lat, self.precision);
67 self.entries.insert(doc_id.to_string(), hash.clone());
68 self.prefix_index
69 .entry(hash.clone())
70 .or_default()
71 .push(doc_id.to_string());
72 Some(hash)
73 }
74
75 /// Remove a document from the geohash index.
76 pub fn remove_document(&mut self, doc_id: &str) {

Calls 7

geohash_encodeFunction · 0.85
to_stringMethod · 0.80
entryMethod · 0.80
remove_documentMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45