about summary refs log tree commit diff
path: root/src/bin
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-10-12 19:08:38 +0200
committerPjotr Prins <pjotr.public01@thebird.nl>2026-10-12 19:08:38 +0200
commit8db38664938c4db10573efc0be04b3d12b249f41 (patch)
treea587d6ceb1d72485096b175555572822aadddb85 /src/bin
parent9cc1631324216d564aca4448cbe71f49dbf2a4af (diff)
parentad3bb1e37e5feb22d3a8eb9e99e072f613fa186c (diff)
downloadgenenetwork4-8db38664938c4db10573efc0be04b3d12b249f41.tar.gz
Merge branch 'main' into gemma
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/gn-indexer.rs91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/bin/gn-indexer.rs b/src/bin/gn-indexer.rs
new file mode 100644
index 0000000..3b70945
--- /dev/null
+++ b/src/bin/gn-indexer.rs
@@ -0,0 +1,91 @@
+//! `gn-indexer`: the GeneNetwork4 native search-index builder.
+//!
+//! Usage:
+//!   gn-indexer full        [--index PATH] [--rdf-cache PATH] [--no-publish-filter]
+//!   gn-indexer incremental [--index PATH] [--rdf-cache PATH] [--no-publish-filter]
+//!
+//! The target index comes from `--index`, else `XAPIAN_DB_PATH` (the
+//! same key the search engine reads), and is written IN PLACE. The RDF
+//! caches come from `--rdf-cache`, else `GN4_RDF_CACHE`, else
+//! `/tmp/gn4-rdf-cache.json`. `SQL_URI` comes from the crate's normal
+//! layered configuration.
+//!
+//! Test-only RED controls for the incremental gates are read from
+//! `GN4_INDEXER_RED` (values `hash`, `delete`, `commit`); they sabotage
+//! one guarantee each and are never set in a normal run.
+
+use std::path::PathBuf;
+use std::process::ExitCode;
+
+use genenetwork4::config::Config;
+use genenetwork4::indexer::{RunConfig, run_full, run_incremental};
+
+fn usage() -> ExitCode {
+    eprintln!(
+        "usage: gn-indexer <full|incremental> [--index PATH] [--rdf-cache PATH] \
+         [--no-publish-filter]"
+    );
+    ExitCode::from(2)
+}
+
+fn main() -> ExitCode {
+    let mut args = std::env::args().skip(1);
+    let Some(mode) = args.next() else {
+        return usage();
+    };
+    let mut index_arg: Option<PathBuf> = None;
+    let mut rdf_arg: Option<PathBuf> = None;
+    let mut publish_filter = true;
+    while let Some(arg) = args.next() {
+        match arg.as_str() {
+            "--index" => index_arg = args.next().map(PathBuf::from),
+            "--rdf-cache" => rdf_arg = args.next().map(PathBuf::from),
+            "--no-publish-filter" => publish_filter = false,
+            other => {
+                eprintln!("unknown argument: {other}");
+                return usage();
+            }
+        }
+    }
+
+    let config = Config::load();
+    let index_path = index_arg.unwrap_or_else(|| PathBuf::from(&config.xapian_db_path));
+    if index_path.as_os_str().is_empty() {
+        eprintln!("no index path: pass --index or set XAPIAN_DB_PATH");
+        return ExitCode::from(1);
+    }
+    let rdf_cache = rdf_arg.unwrap_or_else(|| {
+        PathBuf::from(
+            std::env::var("GN4_RDF_CACHE").unwrap_or_else(|_| "/tmp/gn4-rdf-cache.json".into()),
+        )
+    });
+
+    let run_config = RunConfig {
+        sql_uri: config.sql_uri,
+        index_path,
+        rdf_cache,
+        publish_filter,
+    };
+
+    let result = match mode.as_str() {
+        "full" => run_full(&run_config),
+        "incremental" => run_incremental(&run_config),
+        _ => return usage(),
+    };
+
+    match result {
+        Ok(stats) => {
+            println!("mode={}", stats.mode);
+            println!("built={}", stats.built);
+            println!("replaced={}", stats.replaced);
+            println!("deleted={}", stats.deleted);
+            println!("unchanged={}", stats.unchanged);
+            println!("index_doc_count={}", stats.index_doc_count);
+            ExitCode::SUCCESS
+        }
+        Err(error) => {
+            eprintln!("gn-indexer: {error}");
+            ExitCode::from(1)
+        }
+    }
+}