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

Method merge

nodedb-cluster/src/distributed_spatial/merge.rs:68–84  ·  view source on GitHub ↗

Merge all results: deduplicate by doc_id, optionally sort by distance. For ST_DWithin, results are sorted by distance (nearest first). For boolean predicates, order is arbitrary. Truncates to `limit`.

(&mut self, limit: usize, sort_by_distance: bool)

Source from the content-addressed store, hash-verified

66 /// For ST_DWithin, results are sorted by distance (nearest first).
67 /// For boolean predicates, order is arbitrary. Truncates to `limit`.
68 pub fn merge(&mut self, limit: usize, sort_by_distance: bool) -> Vec<SpatialHit> {
69 // Deduplicate by doc_id (a document can only appear on one shard,
70 // but defensive in case of ghost stubs or migration overlap).
71 let mut seen = std::collections::HashSet::new();
72 self.all_hits.retain(|h| seen.insert(h.doc_id.clone()));
73
74 if sort_by_distance {
75 self.all_hits.sort_by(|a, b| {
76 a.distance_meters
77 .partial_cmp(&b.distance_meters)
78 .unwrap_or(std::cmp::Ordering::Equal)
79 });
80 }
81
82 self.all_hits.truncate(limit);
83 self.all_hits.clone()
84 }
85
86 /// Total hits collected (before merge).
87 pub fn total_hits(&self) -> usize {

Callers 5

merge_two_shards_booleanFunction · 0.45
merge_with_distance_sortFunction · 0.45
merge_with_failed_shardFunction · 0.45
merge_respects_limitFunction · 0.45
merge_resultsMethod · 0.45

Calls 4

insertMethod · 0.45
cloneMethod · 0.45
partial_cmpMethod · 0.45
truncateMethod · 0.45

Tested by 4

merge_two_shards_booleanFunction · 0.36
merge_with_distance_sortFunction · 0.36
merge_with_failed_shardFunction · 0.36
merge_respects_limitFunction · 0.36