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): fuzzy query matches whole keyword values, not just tokens

xerj-orgba016912b51d
diff --git a/engine/crates/xerj-engine/src/index.rs b/engine/crates/xerj-engine/src/index.rs
index 2fa900488..bf689e9d3 100644
--- a/engine/crates/xerj-engine/src/index.rs
+++ b/engine/crates/xerj-engine/src/index.rs
@@ -9812,12 +9812,19 @@ fn doc_matches_query(q: &QueryNode, source: &Value) -> bool {
Fuzziness::Fixed(n) => *n as usize,
};
let q_lower = query_value.to_lowercase();
- // ES's Fuzzy query matches at the TERM level: we tokenize the
- // field value and check if any individual token is within
- // max_edits edit-distance of the query. Full-string Levenshtein
- // would never match a multi-word text field.
+ // ES's Fuzzy query matches at the TERM level with an UNANALYZED
+ // query term. For keyword fields the indexed term is the whole
+ // field value, so first compare the full (case-folded) string
+ // against the query — e.g. doc "claude-haiku-4-5" vs query
+ // "claude-haiku-4-6" is 1 edit and must match. Then fall back to
+ // per-token comparison for text-field semantics, where each
+ // analyzed token is an indexed term.
let token_match = |s: &str| -> bool {
- s.to_lowercase()
+ let s_lower = s.to_lowercase();
+ if levenshtein_distance(&s_lower, &q_lower) <= max_edits {
+ return true;
+ }
+ s_lower
.split(|c: char| !c.is_alphanumeric())
.filter(|t| !t.is_empty())
.any(|tok| levenshtein_distance(tok, &q_lower) <= max_edits)