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.

perf(query): admit keyword match_phrase into the scored-columnar plan (2.7x -> WIN, bool-wrapped mp scores ES-exact)

xerj-org886d804151ff
diff --git a/engine/crates/xerj-engine/src/index.rs b/engine/crates/xerj-engine/src/index.rs
index 8f68ecd24..97611b538 100644
--- a/engine/crates/xerj-engine/src/index.rs
+++ b/engine/crates/xerj-engine/src/index.rs
@@ -21225,6 +21225,27 @@ fn scored_fast_plan(
kind: ScoredLeafKind::NumericEq(query.parse::<f64>().ok()?),
boost: mult * scoring_boost(boost)?,
}),
+ // match_phrase on a KEYWORD field: the keyword analyzer emits one
+ // whole-value token, so the "phrase" degenerates to exact term
+ // equality — identical semantics AND scoring to `match` on the
+ // same keyword field (the arm above; ES builds the same
+ // TermQuery). Mirrors the FTS lowering in `query_node_to_fts`
+ // (which routes keyword match_phrase to `FtsTerm`), but lands on
+ // the columnar TopKCand path instead of the O(matches) postings
+ // enumeration. `slop` is irrelevant for a single-position term
+ // (Lucene ignores slop on 1-term phrases); a custom `analyzer`
+ // bails to the brute path.
+ QueryNode::MatchPhrase {
+ field,
+ query,
+ analyzer: None,
+ boost,
+ ..
+ } if fs.kw.contains(field) => Some(ScoredLeaf {
+ field: field.clone(),
+ kind: ScoredLeafKind::Keyword(query.clone()),
+ boost: mult * scoring_boost(boost)?,
+ }),
_ => None,
}
}
@@ -21366,7 +21387,7 @@ fn scored_fast_plan(
tie_breaker: *tie_breaker,
})
}
- QueryNode::Term { .. } | QueryNode::Match { .. } => {
+ QueryNode::Term { .. } | QueryNode::Match { .. } | QueryNode::MatchPhrase { .. } => {
Some(ScoredClause::Leaf(scoring_leaf(node, mult, fs)?))
}
// multi_match(best_fields) over keyword/numeric fields lowers to
@@ -21610,7 +21631,8 @@ fn scored_fast_plan(
| QueryNode::Boosted { .. }
| QueryNode::Term { .. }
| QueryNode::MultiMatch { .. }
- | QueryNode::Match { .. } => {
+ | QueryNode::Match { .. }
+ | QueryNode::MatchPhrase { .. } => {
let root = match scoring_clause(query, 1.0, &fs)? {
leaf @ ScoredClause::Leaf(_) => ScoredClause::Bool {
must: vec![leaf],