MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / rank_kg_hits

Function rank_kg_hits

atomic-core/src/pristine/vault.rs:10–33  ·  view source on GitHub ↗
(
    txn: &impl crate::pristine::KgTxnT,
    hits: HashMap<String, usize>,
    limit: usize,
)

Source from the content-addressed store, hash-verified

8use std::collections::HashMap;
9
10pub(crate) fn rank_kg_hits(
11 txn: &impl crate::pristine::KgTxnT,
12 hits: HashMap<String, usize>,
13 limit: usize,
14) -> Result<Vec<KgNode>, crate::pristine::PristineError> {
15 let mut ranked = Vec::new();
16 for (id, hits) in hits {
17 if let Some(node) = txn.get_kg_node(&id)? {
18 let score = hits
19 * if node.has_type(crate::kg::ontology::Class::File) {
20 2
21 } else {
22 1
23 };
24 ranked.push((score, node));
25 }
26 }
27 ranked.sort_by(|a, b| b.0.cmp(&a.0).then_with(|| a.1.id.cmp(&b.1.id)));
28 Ok(ranked
29 .into_iter()
30 .take(limit)
31 .map(|(_, node)| node)
32 .collect())
33}
34
35/// Type of vault entry.
36#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]

Callers 2

kg_fts_searchMethod · 0.85
kg_fts_searchMethod · 0.85

Calls 6

has_typeMethod · 0.80
get_kg_nodeMethod · 0.45
pushMethod · 0.45
cmpMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected