AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(def): list each path:line once (#1644)
xerj-orgae4a7ae2a5f6
diff --git a/engine/crates/xerj-autoindex/src/def.rs b/engine/crates/xerj-autoindex/src/def.rsindex f3e2127b7..320be0faa 100644--- a/engine/crates/xerj-autoindex/src/def.rs+++ b/engine/crates/xerj-autoindex/src/def.rs@@ -383,7 +383,7 @@ pub fn run_def_cli() -> i32 {mapped.as_ref(),numeric.as_ref(),);- let resp = match es.search(&pattern, &body) {+ let mut resp = match es.search(&pattern, &body) {Ok(v) => v,Err(e) => {eprintln!(@@ -395,6 +395,16 @@ pub fn run_def_cli() -> i32 {}};+ let hits = unique_locations(+ resp.pointer("/hits/hits")+ .and_then(Value::as_array)+ .cloned()+ .unwrap_or_default(),+ );+ if let Some(arr) = resp.pointer_mut("/hits/hits") {+ *arr = Value::Array(hits.clone());+ }+if as_json {println!("{}",@@ -403,11 +413,6 @@ pub fn run_def_cli() -> i32 {return 0;}- let hits = resp- .pointer("/hits/hits")- .and_then(Value::as_array)- .cloned()- .unwrap_or_default();if hits.is_empty() {let snap = corpus_snapshot(&es, &prefix);let (lines, exit) = empty_lookup_report("def", &prefix, &query, false, &snap);@@ -449,6 +454,20 @@ pub fn run_def_cli() -> i32 {0}+/// The same `path:line` can come back twice: a symbol doc and a file-level+/// hit, or two passages of one declaration. `xerj def` is a location list,+/// so the first (highest-ranked) hit for a location is the one that is shown.+fn unique_locations(hits: Vec<Value>) -> Vec<Value> {+ let mut seen = BTreeSet::new();+ let mut out = Vec::with_capacity(hits.len());+ for hit in hits {+ if seen.insert(hit_location(&hit)) {+ out.push(hit);+ }+ }+ out+}+#[cfg(test)]mod tests {use super::*;@@ -457,6 +476,20 @@ mod tests {/// clauses are optional unless `minimum_should_match` says otherwise. A/// `--kind`/`--lang` filter must narrow the definitions of the name, not/// replace the name with "anything of this kind".+ #[test]+ fn the_same_path_and_line_is_listed_once() {+ let hit = |id: &str, line: u64| {+ json!({+ "_id": id,+ "_source": { "ax_path": "qabot/agents.py", "line": line, "code": "def _run():" }+ })+ };+ let kept = unique_locations(vec![hit("a", 266), hit("b", 266), hit("c", 10)]);+ assert_eq!(kept.len(), 2, "{kept:?}");+ assert_eq!(kept[0]["_id"], "a");+ assert_eq!(kept[1]["_id"], "c");+ }+#[test]fn kind_and_lang_filters_still_require_the_name_to_match() {for (kind, lang) in [