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(query): query_string fallback splits on whitespace; disclose operators

xerj-orgdf0b3943f406
diff --git a/engine/crates/xerj-query/src/planner.rs b/engine/crates/xerj-query/src/planner.rs
index 32da144aa..23ef86dec 100644
--- a/engine/crates/xerj-query/src/planner.rs
+++ b/engine/crates/xerj-query/src/planner.rs
@@ -309,15 +309,23 @@ fn plan_node(query: QueryNode, schema: &Schema) -> ExecutionPlan {
}
QueryNode::QueryString { query, .. } => {
- // Treat as a full-scan with score for now. A proper query-string
- // parser would produce a full QueryNode tree; that is future work.
+ // Fallback only: the common case is lowered into a Bool tree by
+ // try_lower_query_string (parser.rs), so this branch is reached
+ // only for inputs that could not be translated. Split the raw
+ // query on whitespace and OR the tokens across `_all` rather than
+ // searching for the entire raw string as one opaque token (which
+ // would never match). This is an approximation — operators
+ // (AND/OR/NOT, +/-, parens, phrases, field:value) are not honored
+ // on this path — but it yields sensible hits instead of none.
+ let tokens: Vec<String> = query.split_whitespace().map(str::to_string).collect();
+ let cost = 15.0 * tokens.len().max(1) as f64;
ExecutionPlan::FtsSearch {
field: "_all".to_string(),
- tokens: vec![query],
+ tokens,
require_all: false,
phrase: false,
slop: 0,
- cost: 15.0,
+ cost,
}
}
diff --git a/engine/tests/es-compat-yaml/yaml/search/60_query_string.yml b/engine/tests/es-compat-yaml/yaml/search/60_query_string.yml
index a264f6c69..776054fdb 100644
--- a/engine/tests/es-compat-yaml/yaml/search/60_query_string.yml
+++ b/engine/tests/es-compat-yaml/yaml/search/60_query_string.yml
@@ -53,6 +53,25 @@
- match: {hits.total: 1}
+ # Grouped sub-query: `field:(foo OR bar)` — parenthesized OR group.
+ # The doc `{field: "foo bar"}` matches on either term.
+ - do:
+ search:
+ rest_total_hits_as_int: true
+ index: test
+ q: field:(foo OR bar)
+
+ - match: {hits.total: 1}
+
+ # Grouped OR where only one arm matches still returns the doc.
+ - do:
+ search:
+ rest_total_hits_as_int: true
+ index: test
+ q: field:(foo OR xyz)
+
+ - match: {hits.total: 1}
+
- do:
search:
rest_total_hits_as_int: true