diff options
| author | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-12 01:34:27 +0300 |
|---|---|---|
| committer | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-12 08:14:57 +0300 |
| commit | cd09579987b145c7f345a16d30a66a0964025a5d (patch) | |
| tree | b7861b4d4192db61d13f17561b6f0897bd2cfa0e /src/bin | |
| parent | 8e13f31ceca05aa06b8a98b76e1141763b6a4140 (diff) | |
| download | genenetwork4-cd09579987b145c7f345a16d30a66a0964025a5d.tar.gz | |
* src/bin/gn-indexer.rs: new gn-indexer binary. FULL bootstraps a fresh
index; INCREMENTAL crawls, hashes each document's complete source, replaces only changed documents by identity term, deletes vanished identity terms, and writes nothing when nothing changed. * src/indexer/schema.rs: the identity/type/prefix/slot definitions shared by the writer and the native reader. * src/indexer/rows.rs: the gene and phenotype crawl. Both queries carry confidentiality < 1 AND public > 0; the Python phenotype query has no WHERE clause (the metadata leak this closes by construction). * src/indexer/build.rs: document construction, mirroring index_genes / index_phenotypes call for call (TermGenerator configuration, prefix order, value slots, popped-before-storage fields, identity term). * src/indexer/pyjson.rs: byte-exact reproduction of Python json.dumps (separators, ensure_ascii escaping, shortest round-trip float repr with CPython's half-to-even tie-breaking). * src/indexer/cache.rs: the RDF RIF/wiki dictionaries, reproducing build_rdf_cache(remove_common_words=True) from the authoritative cache file; each dictionary is one monolithic hashed input. * src/indexer/sha256.rs: dependency-free SHA-256 for the source and cache hashes. * src/indexer/sidecar.rs, src/indexer/run.rs: per-document source hashes in a sidecar next to the index (atomic rename strictly after the index commit), FULL and INCREMENTAL orchestration, identity-term uniqueness assertion, and the startup key-set mismatch fallback. * src/lib.rs: register the indexer module. * tests/data/pyfloat.txt: reference-docdata float-token fixture for the serializer test (generated read-only from the reference index).
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/gn-indexer.rs | 91 |
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) + } + } +} |
