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(autoindex): use the singular when a count is one (#1716)

xerj-org476de137e346
diff --git a/engine/crates/xerj-autoindex/src/estimate.rs b/engine/crates/xerj-autoindex/src/estimate.rs
index 6fe5d8573..999a3267c 100644
--- a/engine/crates/xerj-autoindex/src/estimate.rs
+++ b/engine/crates/xerj-autoindex/src/estimate.rs
@@ -485,6 +485,51 @@ pub fn human_bytes(bytes: u64) -> String {
format!("{bytes} B")
}
+/// `1 file`, `0 files`, `810 files`. Zero takes the plural.
+pub fn count_phrase(n: u64, one: &str, many: &str) -> String {
+ if n == 1 {
+ format!("1 {one}")
+ } else {
+ format!("{n} {many}")
+ }
+}
+
+/// The estimate table's count cell. The number stays width 5 and the noun
+/// stays width 5, so `1 file` does not shift the byte column and does not
+/// read as `1 files`.
+pub fn count_files_column(n: u64) -> String {
+ format!("{n:>5} {:<5}", if n == 1 { "file" } else { "files" })
+}
+
+/// `phase A: 1 dataset inferred, 0 junk/skipped files`.
+pub fn phase_a_line(datasets: u64, junk_files: u64) -> String {
+ format!(
+ "phase A: {} inferred, {}",
+ count_phrase(datasets, "dataset", "datasets"),
+ count_phrase(junk_files, "junk/skipped file", "junk/skipped files"),
+ )
+}
+
+/// The interactive `done in …` line. A count of one uses the singular noun.
+pub fn done_summary_line(
+ wall: f64,
+ datasets: u64,
+ records: u64,
+ aliases: u64,
+ junk_records: u64,
+ junk_files: u64,
+ docs_per_sec: f64,
+) -> String {
+ format!(
+ "done in {wall:.1}s — {}, {} live, {}, {}, {} ({docs_per_sec:.1} docs/sec)",
+ count_phrase(datasets, "dataset", "datasets"),
+ count_phrase(records, "record", "records"),
+ count_phrase(aliases, "duplicate alias", "duplicate aliases"),
+ count_phrase(junk_records, "junk record", "junk records"),
+ count_phrase(junk_files, "junk/skipped file", "junk/skipped files"),
+ )
+}
+
/// `3.2 s`, `4.7 min`, `1.9 h`.
pub fn human_secs(seconds: f64) -> String {
if seconds < 90.0 {
@@ -500,6 +545,31 @@ pub fn human_secs(seconds: f64) -> String {
mod tests {
use super::*;
+ /// Tokio's json family printed `1 files` and `1 file(s)`.
+ #[test]
+ fn a_count_of_one_uses_the_singular_noun() {
+ assert_eq!(count_phrase(1, "dataset", "datasets"), "1 dataset");
+ assert_eq!(count_phrase(0, "dataset", "datasets"), "0 datasets");
+ assert_eq!(count_phrase(2, "file", "files"), "2 files");
+ assert_eq!(count_files_column(1), " 1 file ");
+ assert_eq!(count_files_column(810), " 810 files");
+ assert_eq!(count_files_column(1).len(), count_files_column(810).len());
+ assert_eq!(
+ phase_a_line(1, 0),
+ "phase A: 1 dataset inferred, 0 junk/skipped files"
+ );
+ let done = done_summary_line(6.8, 1, 11246, 6, 0, 0, 1644.3);
+ assert!(done.contains("1 dataset,"), "{done}");
+ assert!(!done.contains("1 datasets"), "{done}");
+ assert!(done.contains("11246 records live"), "{done}");
+ assert!(done.contains("6 duplicate aliases"), "{done}");
+ assert!(done.contains("0 junk records"), "{done}");
+ assert!(done.contains("0 junk/skipped files"), "{done}");
+ assert!(done_summary_line(0.2, 1, 1, 1, 1, 1, 0.0).contains(
+ "1 dataset, 1 record live, 1 duplicate alias, 1 junk record, 1 junk/skipped file"
+ ));
+ }
+
fn rate(family: &'static str, bytes_per_sec: f64) -> (&'static str, MeasuredRate) {
(
family,
diff --git a/engine/crates/xerj-autoindex/src/lib.rs b/engine/crates/xerj-autoindex/src/lib.rs
index 80ef33c36..1a0162930 100644
--- a/engine/crates/xerj-autoindex/src/lib.rs
+++ b/engine/crates/xerj-autoindex/src/lib.rs
@@ -5035,13 +5035,17 @@ fn finish_generated_run(es: &Es, journal: &mut state::Journal, cfg: &IndexCfg) -
println!("{summary}");
} else if !cfg.quiet {
println!(
- "generation {} committed — {} datasets, {} records live",
+ "generation {} committed — {}, {} live",
generation,
- dataset_count,
- summary
- .get("records_total")
- .and_then(Value::as_u64)
- .unwrap_or(0)
+ estimate::count_phrase(dataset_count as u64, "dataset", "datasets"),
+ estimate::count_phrase(
+ summary
+ .get("records_total")
+ .and_then(Value::as_u64)
+ .unwrap_or(0),
+ "record",
+ "records",
+ ),
);
// #929: read from the committed manifest, so a no-op re-run names the
// refused datasets again instead of only the run that met the refusal.
@@ -6985,10 +6989,9 @@ fn run_index_report_inner(
&cfg,
);
pdf_spools = spools;
- pr.note(&format!(
- "phase A: {} datasets inferred, {} junk/skipped files",
- plan.datasets.len(),
- plan.junk_files.len()
+ pr.note(&estimate::phase_a_line(
+ plan.datasets.len() as u64,
+ plan.junk_files.len() as u64,
));
clusters_rt = Some(clusters);
plan
@@ -7106,21 +7109,21 @@ fn run_index_report_inner(
pr.note(&format!("estimate: basis — {}", run_estimate.basis));
for family in &run_estimate.families {
pr.note(&format!(
- " estimate: {:<10} {:>5} files {:>9} at {}/s measured over {} file(s) / {} → {}",
+ " estimate: {:<10} {} {:>9} at {}/s measured over {} / {} → {}",
family.family,
- family.planned_files,
+ estimate::count_files_column(family.planned_files),
estimate::human_bytes(family.planned_bytes),
estimate::human_bytes(family.bytes_per_sec as u64),
- family.measured_files,
+ estimate::count_phrase(family.measured_files, "file", "files"),
estimate::human_bytes(family.measured_bytes),
estimate::human_secs(family.seconds_of_work),
));
}
for family in &run_estimate.unmeasured_families {
pr.note(&format!(
- " estimate: {:<10} {:>5} files {:>9} NOT priced — {}",
+ " estimate: {:<10} {} {:>9} NOT priced — {}",
family.family,
- family.planned_files,
+ estimate::count_files_column(family.planned_files),
estimate::human_bytes(family.planned_bytes),
family.reason,
));
@@ -9414,8 +9417,18 @@ fn run_index_report_inner(
if cfg.json {
println!("{run_doc}");
} else if !cfg.quiet {
- println!("\ndone in {wall:.1}s — {} datasets, {} records live, {} duplicate aliases, {} junk records, {} junk/skipped files ({docs_per_sec:.1} docs/sec)",
- plan.datasets.len(), total_records, plan.duplicate_files.len(), junk_total_records, junk_file_count);
+ println!(
+ "\n{}",
+ estimate::done_summary_line(
+ wall,
+ plan.datasets.len() as u64,
+ total_records,
+ plan.duplicate_files.len() as u64,
+ junk_total_records,
+ junk_file_count as u64,
+ docs_per_sec,
+ )
+ );
// Indexed-vs-submitted honesty line (#195): the live count against
// what this run actually submitted, so a silent-rejection mismatch
// is visible in the client output alone. Units differ on purpose: a
diff --git a/engine/crates/xerj-autoindex/src/order.rs b/engine/crates/xerj-autoindex/src/order.rs
index 4ae3ff6f5..43caa3475 100644
--- a/engine/crates/xerj-autoindex/src/order.rs
+++ b/engine/crates/xerj-autoindex/src/order.rs
@@ -333,9 +333,9 @@ pub fn work_order_line(bands: &[BandSummary], workers: usize) -> String {
.iter()
.map(|band| {
format!(
- "{} ({} files, {})",
+ "{} ({}, {})",
band.band,
- band.files,
+ crate::estimate::count_phrase(band.files, "file", "files"),
crate::estimate::human_bytes(band.bytes)
)
})