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(engine): #677 dotted-field term/range counts fall back to the source scan

xerj-org86c325527624
diff --git a/engine/crates/xerj-engine/src/memtable.rs b/engine/crates/xerj-engine/src/memtable.rs
index 257facdc3..a72e52802 100644
--- a/engine/crates/xerj-engine/src/memtable.rs
+++ b/engine/crates/xerj-engine/src/memtable.rs
@@ -1797,6 +1797,17 @@ impl ShardedFtsMemtable {
/// refusal globally (`?` inside its loop); this makes the single-leaf
/// wrappers behave the same way.
fn dv_column_unusable(&self, field: &str) -> bool {
+ // #677: a dotted path (an object sub-field like `meta.owner`, or a
+ // `.keyword` multi-field) resolves through `get_field_value` /
+ // `get_nested_field` against the stored `_source`, NOT a faithful
+ // single-valued DV column — the same rule `terms_counts_columnar`
+ // states. Counting such a field via the column undercounts (0 while
+ // the buffered source matches → the #677 size:0-vs-size:5 split), so
+ // force the authoritative source scan. Always correct (the scan is the
+ // authority); only a bounded perf cost on dotted-field term counts.
+ if field.contains('.') {
+ return true;
+ }
self.shards.iter().any(|s| {
let g = s.read();
g.doc_values.array_fields.contains(field)
@@ -3366,6 +3377,14 @@ impl FtsMemtable {
if self.doc_values.array_fields.contains(field.as_str()) {
return None;
}
+ // #677: a dotted path (object sub-field / `.keyword`
+ // multi-field) is not faithfully represented by a single
+ // DV column — it resolves through `_source`. Bail to the
+ // source scan, else a `term` on `meta.owner` counts 0 while
+ // buffered but matches after flush (size:0 undercount).
+ if field.contains('.') {
+ return None;
+ }
if let Some(col) = self.doc_values.keyword.get(field.as_str()) {
// Step 2: analyzed-text bailout via the insert-time
// cached flag instead of an O(N) per-query column
@@ -3396,6 +3415,10 @@ impl FtsMemtable {
if self.doc_values.array_fields.contains(field.as_str()) {
return None;
}
+ // #677: dotted path → source scan (see the Term arm).
+ if field.contains('.') {
+ return None;
+ }
let col = self.doc_values.numeric.get(field.as_str())?;
cols.push(Col::Num(col, *gte, *gt, *lte, *lt));
}
@@ -3486,6 +3509,12 @@ impl FtsMemtable {
if self.doc_values.array_fields.contains(field.as_str()) {
return None;
}
+ // #677: dotted path (object sub-field / `.keyword`) → source
+ // scan, so the count and filter paths agree (see the count
+ // fn `doc_values_bool_hits`).
+ if field.contains('.') {
+ return None;
+ }
if let Some(col) = self.doc_values.keyword.get(field.as_str()) {
if self
.doc_values
@@ -3511,6 +3540,10 @@ impl FtsMemtable {
if self.doc_values.array_fields.contains(field.as_str()) {
return None;
}
+ // #677: dotted path → source scan (see the Term arm).
+ if field.contains('.') {
+ return None;
+ }
let col = self.doc_values.numeric.get(field.as_str())?;
cols.push(Col::Num(col, *gte, *gt, *lte, *lt));
}
diff --git a/engine/crates/xerj-engine/tests/object_subfield_term_flush_parity.rs b/engine/crates/xerj-engine/tests/object_subfield_term_flush_parity.rs
index 1332eb155..551c52d05 100644
--- a/engine/crates/xerj-engine/tests/object_subfield_term_flush_parity.rs
+++ b/engine/crates/xerj-engine/tests/object_subfield_term_flush_parity.rs
@@ -25,7 +25,6 @@ async fn hits(engine: &Engine, q: serde_json::Value) -> u64 {
}
#[tokio::test]
-#[ignore = "#677: memtable term path does not resolve object sub-fields; un-ignored by the fix"]
async fn term_on_object_subfield_is_flush_invariant() {
let dir = TempDir::new().unwrap();
let mut config = Config::default();
@@ -47,6 +46,12 @@ async fn term_on_object_subfield_is_flush_invariant() {
idx.refresh().await.expect("refresh");
let post = hits(&engine, q.clone()).await;
- assert_eq!(pre, post, "#677: term on an object sub-field must be flush-invariant");
- assert_eq!(post, 1, "#677: meta.owner is an indexed keyword sub-field (ES matches)");
+ assert_eq!(
+ pre, post,
+ "#677: term on an object sub-field must be flush-invariant"
+ );
+ assert_eq!(
+ post, 1,
+ "#677: meta.owner is an indexed keyword sub-field (ES matches)"
+ );
}