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.

style: rustfmt 1.97 pass — CI toolchain parity

xerj-org3249d6e6055d
diff --git a/engine/crates/xerj-common/src/fsio.rs b/engine/crates/xerj-common/src/fsio.rs
index 7576db517..d77d043cc 100644
--- a/engine/crates/xerj-common/src/fsio.rs
+++ b/engine/crates/xerj-common/src/fsio.rs
@@ -40,11 +40,7 @@ pub fn fsync_dir(dir: &Path) -> std::io::Result<()> {
/// same target never clobber each other's temp file (see the
/// `save_snapshot` race note in `xerj-storage`).
pub fn write_file_durable(path: &Path, bytes: &[u8]) -> std::io::Result<()> {
- let nonce = format!(
- "{:x}-{:?}",
- std::process::id(),
- std::thread::current().id()
- );
+ let nonce = format!("{:x}-{:?}", std::process::id(), std::thread::current().id());
let file_name = path
.file_name()
.map(|n| n.to_string_lossy().into_owned())
diff --git a/engine/crates/xerj-engine/src/aggs.rs b/engine/crates/xerj-engine/src/aggs.rs
index 155c14aec..e0d4904c5 100644
--- a/engine/crates/xerj-engine/src/aggs.rs
+++ b/engine/crates/xerj-engine/src/aggs.rs
@@ -5242,9 +5242,8 @@ pub(crate) fn doc_matches_filter(doc: &Value, filter: &Value) -> bool {
// keyword-range semantics.
let raw = Value::String(values[0].clone());
let doc_ms = parse_date_ms(&raw);
- let bound_ms = |k: &str| -> Option<i64> {
- bounds.get(k).and_then(parse_date_ms)
- };
+ let bound_ms =
+ |k: &str| -> Option<i64> { bounds.get(k).and_then(parse_date_ms) };
if let Some(v) = doc_ms {
if let Some(b) = bound_ms("gte") {
if v < b {
@@ -12377,8 +12376,14 @@ mod date_range_filter_tests {
let f = json!({"range": {"ts": {"gte": "2026-06-17T00:00:00.000Z",
"lt": "2026-06-18T00:00:00.000Z"}}});
assert!(doc_matches_filter(&inside, &f), "in-window doc must match");
- assert!(!doc_matches_filter(&before, &f), "doc before window must NOT match");
- assert!(!doc_matches_filter(&after, &f), "doc at exclusive upper must NOT match");
+ assert!(
+ !doc_matches_filter(&before, &f),
+ "doc before window must NOT match"
+ );
+ assert!(
+ !doc_matches_filter(&after, &f),
+ "doc at exclusive upper must NOT match"
+ );
}
/// Bounds are compared as instants, so differing-but-equivalent renderings
@@ -12386,8 +12391,14 @@ mod date_range_filter_tests {
#[test]
fn date_bounds_compare_as_instants_not_strings() {
let doc = json!({"ts": "2026-06-17T00:00:00.000Z"});
- assert!(doc_matches_filter(&doc, &json!({"range": {"ts": {"gte": "2026-06-17"}}})));
- assert!(!doc_matches_filter(&doc, &json!({"range": {"ts": {"gt": "2026-06-17"}}})));
+ assert!(doc_matches_filter(
+ &doc,
+ &json!({"range": {"ts": {"gte": "2026-06-17"}}})
+ ));
+ assert!(!doc_matches_filter(
+ &doc,
+ &json!({"range": {"ts": {"gt": "2026-06-17"}}})
+ ));
// Same instant expressed with an offset.
let f = json!({"range": {"ts": {"gte": "2026-06-17T02:00:00.000+02:00"}}});
assert!(doc_matches_filter(&doc, &f));
diff --git a/engine/crates/xerj-engine/src/fast_aggs.rs b/engine/crates/xerj-engine/src/fast_aggs.rs
index 9b5413d78..013381f05 100644
--- a/engine/crates/xerj-engine/src/fast_aggs.rs
+++ b/engine/crates/xerj-engine/src/fast_aggs.rs
@@ -4877,7 +4877,9 @@ fn compile_pred(filter: &Value) -> Option<Pred> {
.iter()
.filter_map(|k| bo.get(*k))
.all(|v| v.is_string());
- let any_bound = ["gte", "gt", "lte", "lt"].iter().any(|k| bo.contains_key(*k));
+ let any_bound = ["gte", "gt", "lte", "lt"]
+ .iter()
+ .any(|k| bo.contains_key(*k));
if any_bound && str_bounds {
let get_str = |k: &str| -> Option<Option<String>> {
match bo.get(k) {
@@ -5439,8 +5441,22 @@ mod range_kw_tests {
#[test]
fn empty_and_out_of_range_windows() {
let c = cols();
- assert_eq!(count(&rng(Some("2026-07-01T00:00:00.000Z"), true, None, true), &c, 72), 0);
- assert_eq!(count(&rng(None, true, Some("2026-05-01T00:00:00.000Z"), false), &c, 72), 0);
+ assert_eq!(
+ count(
+ &rng(Some("2026-07-01T00:00:00.000Z"), true, None, true),
+ &c,
+ 72
+ ),
+ 0
+ );
+ assert_eq!(
+ count(
+ &rng(None, true, Some("2026-05-01T00:00:00.000Z"), false),
+ &c,
+ 72
+ ),
+ 0
+ );
}
/// The order-safety gate: a dictionary mixing widths (a hand-indexed
@@ -5453,7 +5469,10 @@ mod range_kw_tests {
let mut m = std::collections::BTreeMap::new();
m.insert("ts".to_string(), Column::Keyword(k));
let p = rng(Some(&ts(2, 0)), true, Some(&ts(3, 0)), false);
- assert!(resolve_pred(&m, &p).is_none(), "ragged dictionary must bail");
+ assert!(
+ resolve_pred(&m, &p).is_none(),
+ "ragged dictionary must bail"
+ );
}
/// A bound whose width disagrees with the dictionary must bail too.
diff --git a/engine/crates/xerj-engine/src/index.rs b/engine/crates/xerj-engine/src/index.rs
index 53e9ed3d5..cde29a562 100644
--- a/engine/crates/xerj-engine/src/index.rs
+++ b/engine/crates/xerj-engine/src/index.rs
@@ -105,7 +105,10 @@ fn query_node_to_agg_filter(node: &QueryNode) -> Option<Value> {
lt,
..
} => {
- let present: Vec<&Value> = [gte, gt, lte, lt].iter().filter_map(|o| o.as_ref()).collect();
+ let present: Vec<&Value> = [gte, gt, lte, lt]
+ .iter()
+ .filter_map(|o| o.as_ref())
+ .collect();
if present.is_empty() {
return None;
}
diff --git a/engine/crates/xerj-engine/tests/integration.rs b/engine/crates/xerj-engine/tests/integration.rs
index b93bdf525..e20d999be 100644
--- a/engine/crates/xerj-engine/tests/integration.rs
+++ b/engine/crates/xerj-engine/tests/integration.rs
@@ -5141,10 +5141,18 @@ async fn test_filtered_extended_stats_sees_only_matching_docs() {
let es = &res.aggs.as_ref().unwrap()["es"];
// Group b only: 6 000 docs, every value 100.0.
- assert_eq!(es["count"].as_u64().unwrap(), 6_000, "count must exclude group a");
+ assert_eq!(
+ es["count"].as_u64().unwrap(),
+ 6_000,
+ "count must exclude group a"
+ );
assert_eq!(es["min"].as_f64().unwrap(), 100.0);
assert_eq!(es["max"].as_f64().unwrap(), 100.0);
- assert_eq!(es["avg"].as_f64().unwrap(), 100.0, "avg of a filter-blind fold would be 50.5");
+ assert_eq!(
+ es["avg"].as_f64().unwrap(),
+ 100.0,
+ "avg of a filter-blind fold would be 50.5"
+ );
// Constant population → zero variance. A filter-blind fold gives ~2450.
assert!(
es["variance"].as_f64().unwrap() < 1e-6,
@@ -5198,11 +5206,12 @@ async fn test_filtered_median_absolute_deviation_sees_only_matching_docs() {
}))
.unwrap();
let res = idx.search(&req).await.unwrap();
- let mad = res.aggs.as_ref().unwrap()["m"]["value"]
- .as_f64()
- .unwrap();
+ let mad = res.aggs.as_ref().unwrap()["m"]["value"].as_f64().unwrap();
// Constant population → MAD 0. Filter-blind would give ~49.5.
- assert!(mad < 1e-6, "MAD must be ~0 for a constant population, got {mad}");
+ assert!(
+ mad < 1e-6,
+ "MAD must be ~0 for a constant population, got {mad}"
+ );
}
#[tokio::test]
@@ -5271,7 +5280,10 @@ async fn test_highlight_survives_source_filtering() {
.as_ref()
.expect("highlight must be present even when _source excludes the field");
let frag = &hl["body"][0];
- assert!(frag.contains("<em>"), "fragment must carry highlight tags: {frag}");
+ assert!(
+ frag.contains("<em>"),
+ "fragment must carry highlight tags: {frag}"
+ );
assert!(
frag.to_lowercase().contains("neural") || frag.to_lowercase().contains("embedder"),
"fragment must surround the match: {frag}"
@@ -5281,5 +5293,8 @@ async fn test_highlight_survives_source_filtering() {
hit.source.get("body").is_none(),
"_source filtering must still exclude body; caller should not pay for it"
);
- assert!(hit.source.get("path").is_some(), "requested field must survive");
+ assert!(
+ hit.source.get("path").is_some(),
+ "requested field must survive"
+ );
}
diff --git a/engine/crates/xerj-fts/src/index.rs b/engine/crates/xerj-fts/src/index.rs
index 250d99c5d..ea6ec7e2d 100644
--- a/engine/crates/xerj-fts/src/index.rs
+++ b/engine/crates/xerj-fts/src/index.rs
@@ -810,9 +810,7 @@ impl FtsIndexWriter {
.with_context(|| format!("inserting term '{}' into FST", term))?;
}
}
- let mut fst_out = fst_builder
- .into_inner()
- .with_context(|| "finishing FST")?;
+ let mut fst_out = fst_builder.into_inner().with_context(|| "finishing FST")?;
fst_out.flush().with_context(|| "flushing FST")?;
fst_out
.get_ref()
diff --git a/engine/crates/xerj-query/src/dates.rs b/engine/crates/xerj-query/src/dates.rs
index 92fa85d21..413740038 100644
--- a/engine/crates/xerj-query/src/dates.rs
+++ b/engine/crates/xerj-query/src/dates.rs
@@ -119,13 +119,23 @@ pub enum PatTok {
/// Year; payload = minimum digit count (`yyyy` → 4).
Year(usize),
/// Numeric month; payload = exact-width flag (`MM` → true, `M` → false).
- Month { two_digit: bool },
+ Month {
+ two_digit: bool,
+ },
/// Text month name (`MMM`/`MMMM`) — English abbreviations/full names.
MonthName,
- Day { two_digit: bool },
- Hour { two_digit: bool },
- Minute { two_digit: bool },
- Second { two_digit: bool },
+ Day {
+ two_digit: bool,
+ },
+ Hour {
+ two_digit: bool,
+ },
+ Minute {
+ two_digit: bool,
+ },
+ Second {
+ two_digit: bool,
+ },
/// Fractional seconds (`S+`); stores as milliseconds.
Fraction,
/// `Z`/`X`/`x`/`z` — accepts `Z` or `±hh[:mm]` / `±hhmm` (also `UTC`/`GMT`).
@@ -232,14 +242,26 @@ fn compile_pattern(pattern: &str) -> Result<Vec<PatTok>, DateResolveError> {
if run >= 3 {
PatTok::MonthName
} else {
- PatTok::Month { two_digit: run == 2 }
+ PatTok::Month {
+ two_digit: run == 2,
+ }
}
}
- 'd' => PatTok::Day { two_digit: run >= 2 },
- 'H' | 'k' => PatTok::Hour { two_digit: run >= 2 },
- 'h' | 'K' => PatTok::Hour { two_digit: run >= 2 },
- 'm' => PatTok::Minute { two_digit: run >= 2 },
- 's' => PatTok::Second { two_digit: run >= 2 },
+ 'd' => PatTok::Day {
+ two_digit: run >= 2,
+ },
+ 'H' | 'k' => PatTok::Hour {
+ two_digit: run >= 2,
+ },
+ 'h' | 'K' => PatTok::Hour {
+ two_digit: run >= 2,
+ },
+ 'm' => PatTok::Minute {
+ two_digit: run >= 2,
+ },
+ 's' => PatTok::Second {
+ two_digit: run >= 2,
+ },
'S' | 'n' | 'A' | 'N' => PatTok::Fraction,
'Z' | 'X' | 'x' | 'z' | 'V' | 'O' | 'v' => PatTok::TzOffset,
'E' | 'e' | 'c' => PatTok::WeekdayName,
diff --git a/engine/crates/xerj-query/src/parser.rs b/engine/crates/xerj-query/src/parser.rs
index 57ce2290e..a6f9c5569 100644
--- a/engine/crates/xerj-query/src/parser.rs
+++ b/engine/crates/xerj-query/src/parser.rs
@@ -891,9 +891,7 @@ fn parse_range(params: &Value) -> Result<QueryNode> {
// matching live ES 8.13.4.
let fmt_raw = inner.get("format").and_then(|v| v.as_str());
let formats = match fmt_raw {
- Some(f) => {
- Some(dates::compile_formats(f).map_err(|e| date_resolve_err(e, fmt_raw, ""))?)
- }
+ Some(f) => Some(dates::compile_formats(f).map_err(|e| date_resolve_err(e, fmt_raw, ""))?),
None => None,
};
// Round-up bounds: `lte` includes its whole covered interval, `gt`