Skip to content

armgit / xerj

Public Imported from GitHub
0

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.

fix(search,code): rank .pyi stubs behind the implementation (#1651)

xerj-org3fe14a62bb50
diff --git a/engine/crates/xerj-autoindex/src/search.rs b/engine/crates/xerj-autoindex/src/search.rs
index 98a7d10bd..d5b29dd02 100644
--- a/engine/crates/xerj-autoindex/src/search.rs
+++ b/engine/crates/xerj-autoindex/src/search.rs
@@ -12,6 +12,7 @@ use std::collections::BTreeSet;
use crate::esclient::Es;
use serde_json::{json, Value};
+use xerj_common::xccode::demote_catalog_noise;
const USAGE: &str = "\
xerj search — retrieve code from a running XERJ node (reference coding, no scripts)
@@ -667,7 +668,7 @@ pub fn run_search_cli() -> i32 {
.as_ref()
.and(raw_mapping.as_ref().map(numeric_property_names));
let body = search_query_body_for_mapping(&query, k, 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!(
@@ -679,6 +680,15 @@ pub fn run_search_cli() -> i32 {
}
};
+ // Stubs and catalogs repeat the words of a question and outrank the
+ // implementation. Same partition `xerj code` applies (#1504, candle
+ // `.pyi` report). `--json` sees the same order as the text printer.
+ if let Some(arr) = resp.pointer("/hits/hits").and_then(Value::as_array) {
+ let ordered = demote_catalog_noise(arr.clone());
+ if let Some(slot) = resp.pointer_mut("/hits/hits") {
+ *slot = Value::Array(ordered);
+ }
+ }
if as_json {
println!(
"{}",
diff --git a/engine/crates/xerj-common/src/xccode/mod.rs b/engine/crates/xerj-common/src/xccode/mod.rs
index 4c34d6b08..2b5be5398 100644
--- a/engine/crates/xerj-common/src/xccode/mod.rs
+++ b/engine/crates/xerj-common/src/xccode/mod.rs
@@ -699,7 +699,7 @@ pub(crate) fn diversity_fetch(k: usize) -> usize {
/// Stable partition: hits whose path is a translation catalog or a minified
/// bundle move behind every other hit, keeping their relative order. A page
/// that is only catalogs is unchanged. Hits with no path stay where they are.
-pub(crate) fn demote_catalog_noise(hits: Vec<Value>) -> Vec<Value> {
+pub fn demote_catalog_noise(hits: Vec<Value>) -> Vec<Value> {
let mut primary = Vec::with_capacity(hits.len());
let mut catalogs = Vec::new();
for hit in hits {
@@ -717,8 +717,14 @@ pub(crate) fn demote_catalog_noise(hits: Vec<Value>) -> Vec<Value> {
/// ones a multilingual repo uses for key→string tables, not a general
/// "prose file" filter: `lang/*.php`, `values*/strings.xml`, `*.lproj/*.strings`,
/// `*.po` / `*.pot`, and `*.min.js` / `*.min.mjs` / `*.min.css`.
-pub(crate) fn is_catalog_noise(path: &str) -> bool {
+pub fn is_catalog_noise(path: &str) -> bool {
let name = path.rsplit(['/', '\\']).next().unwrap_or(path);
+ // Type stubs repeat the public signature and outrank the implementation
+ // on a natural-language query (candle field report 2026-10-17: `.pyi`
+ // files were the top hits). They stay searchable, behind source.
+ if name.ends_with(".pyi") {
+ return true;
+ }
if name.ends_with(".min.js") || name.ends_with(".min.mjs") || name.ends_with(".min.css") {
return true;
}
@@ -1609,6 +1615,39 @@ mod tests {
);
}
+ /// Candle field report 2026-10-17: natural-language search put `.pyi`
+ /// stubs above the implementation. Stubs stay in the page, after source.
+ /// A page that is only stubs keeps its order.
+ #[test]
+ fn pyi_stubs_rank_behind_the_implementation() {
+ let hit = |path: &str, score: f64| {
+ serde_json::json!({
+ "_score": score,
+ "_source": { "ax_path": path }
+ })
+ };
+ let demoted = demote_catalog_noise(vec![
+ hit("candle/pyo3/quantized.pyi", 9.0),
+ hit("candle/quantized.py", 2.0),
+ hit("candle/pyo3/tensor.pyi", 8.0),
+ ]);
+ let paths: Vec<&str> = demoted
+ .iter()
+ .map(|h| h["_source"]["ax_path"].as_str().unwrap())
+ .collect();
+ assert_eq!(
+ paths,
+ [
+ "candle/quantized.py",
+ "candle/pyo3/quantized.pyi",
+ "candle/pyo3/tensor.pyi",
+ ]
+ );
+ let only = demote_catalog_noise(vec![hit("a.pyi", 3.0), hit("b.pyi", 1.0)]);
+ assert_eq!(only[0]["_source"]["ax_path"], "a.pyi");
+ assert_eq!(only[1]["_source"]["ax_path"], "b.pyi");
+ }
+
/// #1504: lang catalogs, Android strings, Apple .strings, gettext, and
/// minified bundles sort behind an implementing source file. A page that
/// is only catalogs keeps its order. A PHP service file is not a catalog
@@ -1669,6 +1708,8 @@ mod tests {
assert_eq!(only[0]["_source"]["ax_path"], "web/lang/hr.php");
assert_eq!(only[1]["_source"]["ax_path"], "web/lang/en.php");
+ assert!(is_catalog_noise("candle/quantized.pyi"));
+ assert!(!is_catalog_noise("candle/quantized.py"));
assert!(!is_catalog_noise("src/main.rs"));
assert!(!is_catalog_noise("res/layout/activity.xml"));
assert!(is_catalog_noise("web/lang/en.php"));