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(search): blame the prefix only when the index is missing (#1718)
xerj-org008d9b6e93cf
diff --git a/engine/crates/xerj-autoindex/src/def.rs b/engine/crates/xerj-autoindex/src/def.rsindex bd1a61bdd..3025d3cfa 100644--- a/engine/crates/xerj-autoindex/src/def.rs+++ b/engine/crates/xerj-autoindex/src/def.rs@@ -17,6 +17,7 @@ use crate::esclient::Es;use crate::search::{corpus_snapshot, empty_lookup_report, field_lookup_ok, hit_location, is_identifier,mapped_property_names, numeric_property_names, parse_count_arg, passage_text,+ query_failure_message,weighted_query_fields,};use serde_json::{json, Value};@@ -482,11 +483,7 @@ pub fn run_def_cli() -> i32 {let mut resp = match es.search(&pattern, &body) {Ok(v) => v,Err(e) => {- eprintln!(- "xerj def: query failed against {url}/{pattern}: {e}\n\- (is the prefix right? `xerj autoindex` writes 'ax' by default — \- pass --prefix if you indexed under another.)"- );+ eprintln!("{}", query_failure_message("def", &url, &pattern, e));return 1;}};diff --git a/engine/crates/xerj-autoindex/src/search.rs b/engine/crates/xerj-autoindex/src/search.rsindex 2be7ed7a8..631c563e9 100644--- a/engine/crates/xerj-autoindex/src/search.rs+++ b/engine/crates/xerj-autoindex/src/search.rs@@ -669,6 +669,30 @@ fn catalog_run_prefixes(es: &Es) -> Option<Vec<String>> {Some(prefixes.into_iter().collect())}+/// What `xerj search` / `xerj def` print when the query request itself fails.+///+/// A missing index (`index_not_found_exception`, or a body that says+/// `no such index`) is the case the prefix sentence was written for. Every+/// other failure — including HTTP 400 `For input string`, which is a numeric+/// field being queried as text — must not tell the reader to change `--prefix`.+pub(crate) fn query_failure_message(+ command: &str,+ url: &str,+ pattern: &str,+ err: impl std::fmt::Display,+) -> String {+ let err = err.to_string();+ let mut msg = format!("xerj {command}: query failed against {url}/{pattern}: {err}");+ let lower = err.to_ascii_lowercase();+ if lower.contains("index_not_found") || lower.contains("no such index") {+ msg.push_str(+ "\n(is the prefix right? `xerj autoindex` writes 'ax' by default — \+ pass --prefix if you indexed under another.)",+ );+ }+ msg+}+/// Default `--full` width, and the width suggested when the user asked for 0.const DEFAULT_FULL_CHARS: usize = 600;@@ -857,11 +881,7 @@ pub fn run_search_cli() -> i32 {let mut resp = match es.search(&pattern, &body) {Ok(v) => v,Err(e) => {- eprintln!(- "xerj search: query failed against {url}/{pattern}: {e}\n\- (is the prefix right? `xerj autoindex` writes 'ax' by default — \- pass --prefix if you indexed under another.)"- );+ eprintln!("{}", query_failure_message("search", &url, &pattern, e));return 1;}};@@ -943,6 +963,52 @@ mod tests {use super::*;use xerj_common::code_query::normalize_code_search_query;+ /// HTTP 400 `For input string` is a numeric field, not a wrong prefix.+ /// A missing index still gets the prefix sentence.+ #[test]+ fn query_failure_blames_the_prefix_only_when_the_index_is_missing() {+ let numeric = query_failure_message(+ "search",+ "http://127.0.0.1:9200",+ "ax-*",+ "search /ax-* HTTP 400: {\"error\":{\"reason\":\"For input string: \\\"fingerprint dedupe comment\\\"\"}}",+ );+ assert!(numeric.contains("For input string"), "{numeric}");+ assert!(+ !numeric.contains("is the prefix right"),+ "a parse failure must not blame --prefix, got: {numeric}"+ );+ assert!(+ numeric.starts_with("xerj search: query failed against http://127.0.0.1:9200/ax-*: ")+ );++ let missing = query_failure_message(+ "def",+ "http://127.0.0.1:9200",+ "nope-*",+ "search /nope-* HTTP 404: {\"error\":{\"type\":\"index_not_found_exception\"}}",+ );+ assert!(missing.contains("index_not_found_exception"), "{missing}");+ assert!(missing.contains("is the prefix right"), "{missing}");+ assert!(missing.contains("xerj def:"), "{missing}");++ let phrase = query_failure_message(+ "search",+ "http://localhost:9200",+ "ax-*",+ "no such index: ax-missing",+ );+ assert!(phrase.contains("is the prefix right"), "{phrase}");++ let other = query_failure_message(+ "search",+ "http://localhost:9200",+ "ax-*",+ "search /ax-* HTTP 403: {\"error\":{\"type\":\"security_exception\"}}",+ );+ assert!(!other.contains("is the prefix right"), "{other}");+ }+#[test]fn search_refuses_a_mode_flag_and_names_the_embedder() {for asked in ["semantic", "hybrid", "bm25"] {