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(engine): strip `^boost` so boosted keyword multi_match is mapping-aware too
xerj-org59ff53acb14a
diff --git a/engine/crates/xerj-engine/src/index.rs b/engine/crates/xerj-engine/src/index.rsindex 238e983ee..a6bb013ae 100644--- a/engine/crates/xerj-engine/src/index.rs+++ b/engine/crates/xerj-engine/src/index.rs@@ -32050,20 +32050,41 @@ fn rewrite_keyword_full_text_to_term(q: &QueryNode, schema: &Schema) -> QueryNodquery,boost,..- } if fields.iter().any(|f| is_keyword(schema, f)) => {- let (kw, text): (Vec<String>, Vec<String>) =- fields.iter().cloned().partition(|f| is_keyword(schema, f));+ } if fields+ .iter()+ .any(|f| is_keyword(schema, parse_field_boost(f).0)) =>+ {+ // A multi_match field spec may carry a `^boost` suffix ("tags^2");+ // strip it before consulting the mapping (otherwise a boosted+ // keyword field escapes the rewrite and keeps flipping at flush),+ // and fold that field boost into the rewritten keyword `Term`.+ let (kw, text): (Vec<String>, Vec<String>) = fields+ .iter()+ .cloned()+ .partition(|f| is_keyword(schema, parse_field_boost(f).0));let mut should: Vec<QueryNode> = kw.into_iter()- .map(|f| QueryNode::Term {- field: f,- value: Value::String(query.clone()),- boost: *boost,+ .map(|f| {+ let (name, fboost) = parse_field_boost(&f);+ // No `^boost` suffix → preserve the clause boost verbatim+ // (keeps the common unboosted case byte-identical); with a+ // suffix, combine it with the clause boost as ES does.+ let boost = if name.len() == f.len() {+ *boost+ } else {+ Some(fboost * (*boost).unwrap_or(1.0))+ };+ QueryNode::Term {+ field: name.to_string(),+ value: Value::String(query.clone()),+ boost,+ }}).collect();if !text.is_empty() {- // Preserve match_type/operator/etc. by cloning and swapping only- // the field list.+ // Preserve match_type/operator/etc. (and each text field's own+ // `^boost`, which the text matcher strips) by cloning and+ // swapping only the field list.let mut text_mm = q.clone();if let QueryNode::MultiMatch { fields: mmf, .. } = &mut text_mm {*mmf = text;diff --git a/engine/crates/xerj-engine/tests/keyword_match_is_mapping_aware.rs b/engine/crates/xerj-engine/tests/keyword_match_is_mapping_aware.rsindex 8fc1541a7..4b21d739b 100644--- a/engine/crates/xerj-engine/tests/keyword_match_is_mapping_aware.rs+++ b/engine/crates/xerj-engine/tests/keyword_match_is_mapping_aware.rs@@ -82,6 +82,20 @@ async fn keyword_match_takes_the_query_whole_in_both_phases() {&[],"multi_match 'red blue' on scalar keyword",),+ // A field spec carrying a `^boost` ("tags^2") must be recognised as+ // keyword too — the boost suffix is stripped before consulting the+ // mapping — so it takes the query whole and flips NEITHER phase.+ (+ json!({ "multi_match": { "query": "red blue", "fields": ["tags^2"] } }),+ &[],+ "multi_match 'red blue' on BOOSTED scalar keyword (tags^2)",+ ),+ // Positive control for the boosted spec: the whole value still matches.+ (+ json!({ "multi_match": { "query": "red", "fields": ["tags^2"] } }),+ &["2"],+ "multi_match 'red' on BOOSTED scalar keyword matches whole value",+ ),(json!({ "match": { "tags": "red blue" } }),&[],