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)
| 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) { |