about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabua@gmail.com>2026-10-07 10:29:24 +0300
committerAlexander_Kabui <alexanderkabua@gmail.com>2026-10-07 10:29:24 +0300
commitb68531c40d91cadfd868e4b65ff92989ffd4fb27 (patch)
tree1a19ec19d674b6b7a38e5d46be238341bb92310f
parent80c52c495abc58d07df42ed825d7c40b1df2e767 (diff)
downloadgenenetwork4-b68531c40d91cadfd868e4b65ff92989ffd4fb27.tar.gz
src/search/native.rs, src/search/mod.rs, tests/search_native*.rs: apply
rustfmt to the native engine code (lane round-1 files were not
rustfmt-clean; pre-existing drift in config.rs, routes/search.rs,
tests/search_engine.rs is untouched — the parked house question).
-rw-r--r--src/search/native.rs33
-rw-r--r--tests/search_native.rs16
-rw-r--r--tests/search_native_shapes.rs103
3 files changed, 104 insertions, 48 deletions
diff --git a/src/search/native.rs b/src/search/native.rs
index 665477a..5e5e254 100644
--- a/src/search/native.rs
+++ b/src/search/native.rs
@@ -44,8 +44,9 @@
 
 use super::{Engine, SearchError, SearchHit};
 use std::sync::{Mutex, OnceLock};
-use xapian_rs::{Database, Enquire, FieldProcessor, Operator, Query, QueryParser, Stem,
-    StemStrategy};
+use xapian_rs::{
+    Database, Enquire, FieldProcessor, Operator, Query, QueryParser, Stem, StemStrategy,
+};
 
 /// MSet bound for full-match-set retrieval: deliberately large so the
 /// whole match set comes back regardless of the forwarded `limit`
@@ -112,7 +113,11 @@ struct LowercaseGroupProcessor;
 
 impl FieldProcessor for LowercaseGroupProcessor {
     fn process(&self, term: &str) -> Option<Query> {
-        Some(Query::term(format!("XG{}", term.to_lowercase()), None, None))
+        Some(Query::term(
+            format!("XG{}", term.to_lowercase()),
+            None,
+            None,
+        ))
     }
 }
 
@@ -135,9 +140,7 @@ impl Engine for Native {
         let search_type = type_.to_string();
         tokio::task::spawn_blocking(move || search_blocking(&query, &search_type, limit))
             .await
-            .map_err(|e| {
-                SearchError::Internal(format!("native search task failed to join: {e}"))
-            })?
+            .map_err(|e| SearchError::Internal(format!("native search task failed to join: {e}")))?
     }
 }
 
@@ -223,9 +226,8 @@ fn open_database(path: &str) -> Result<Database, SearchError> {
 /// not hold what gn3 would serve — `Misbehaving`, the doc-data analogue
 /// of an undecodable backend response body.
 fn hit_from_doc_data(data: &[u8]) -> Result<SearchHit, SearchError> {
-    serde_json::from_slice::<SearchHit>(data).map_err(|e| {
-        SearchError::Misbehaving(format!("xapian doc data is not a search hit: {e}"))
-    })
+    serde_json::from_slice::<SearchHit>(data)
+        .map_err(|e| SearchError::Misbehaving(format!("xapian doc data is not a search hit: {e}")))
 }
 
 #[cfg(test)]
@@ -296,7 +298,10 @@ mod tests {
             b6.contains("XGb6"),
             "group:B6 must lowercase to XGb6, got {b6:?}"
         );
-        assert!(!b6.contains("XGB6"), "group must not emit the raw-case term");
+        assert!(
+            !b6.contains("XGB6"),
+            "group must not emit the raw-case term"
+        );
     }
 
     /// The probabilistic-prefix registrations (C3.3): description, rif,
@@ -329,16 +334,14 @@ mod tests {
     /// The index-open guards, without touching a real index.
     #[test]
     fn open_database_maps_failures_onto_the_seam_vocabulary() {
-        assert!(matches!(
-            open_database(""),
-            Err(SearchError::Internal(_))
-        ));
+        assert!(matches!(open_database(""), Err(SearchError::Internal(_))));
         assert!(matches!(
             open_database("/nonexistent/gn4-native-test-index"),
             Err(SearchError::Unreachable(_))
         ));
         // A real directory that is not an index.
-        let not_an_index = std::env::temp_dir().join(format!("gn4-not-an-index-{}", std::process::id()));
+        let not_an_index =
+            std::env::temp_dir().join(format!("gn4-not-an-index-{}", std::process::id()));
         std::fs::create_dir_all(&not_an_index).unwrap();
         assert!(matches!(
             open_database(not_an_index.to_str().unwrap()),
diff --git a/tests/search_native.rs b/tests/search_native.rs
index f34dc55..7a519b8 100644
--- a/tests/search_native.rs
+++ b/tests/search_native.rs
@@ -14,7 +14,7 @@
 //! development index is never a recorded-count source, per
 //! AMENDMENT B — counts are printed as reference data only).
 
-use genenetwork4::search::{self as seam, Engine, SearchError, SearchHit, native::Native};
+use genenetwork4::search::{self as seam, native::Native, Engine, SearchError, SearchHit};
 
 /// The name of a result's variant, so a failed assertion can name what
 /// it got without requiring `SearchHit: Debug`.
@@ -83,9 +83,11 @@ async fn native_engine_error_contract_and_per_page_invariant() {
 
     // 6. Per-page invariant against the dev index (skips loudly when
     //    no index is configured, keeping hermetic runs green).
-    let dev_index = prior_path
-        .clone()
-        .or_else(|| std::env::var("XAPIAN_DB_PATH").ok().filter(|v| !v.is_empty()));
+    let dev_index = prior_path.clone().or_else(|| {
+        std::env::var("XAPIAN_DB_PATH")
+            .ok()
+            .filter(|v| !v.is_empty())
+    });
     let dev_index = match dev_index.filter(|path| {
         !path.is_empty() && std::fs::metadata(path).map(|m| m.is_dir()).unwrap_or(false)
     }) {
@@ -147,7 +149,11 @@ async fn native_engine_error_contract_and_per_page_invariant() {
         .search("insulin", "gene", 20)
         .await
         .expect("dev-index insulin/gene search");
-    eprintln!("dev-index reference counts: alcohol/phenotype={}, insulin/gene={}", small.len(), genes.len());
+    eprintln!(
+        "dev-index reference counts: alcohol/phenotype={}, insulin/gene={}",
+        small.len(),
+        genes.len()
+    );
 
     // Restore the environment we found.
     match prior_path {
diff --git a/tests/search_native_shapes.rs b/tests/search_native_shapes.rs
index a9b7489..ddf2944 100644
--- a/tests/search_native_shapes.rs
+++ b/tests/search_native_shapes.rs
@@ -30,7 +30,7 @@
 //! set it to ~/spikes/index-self-build/xapian-index); the test skips
 //! loudly when unset so the hermetic suites stay green.
 
-use genenetwork4::search::{Engine, SearchError, SearchHit, native::Native};
+use genenetwork4::search::{native::Native, Engine, SearchError, SearchHit};
 
 /// The recorded behavior class this gate asserts (see module doc).
 #[derive(Clone, Copy, PartialEq, Eq)]
@@ -56,56 +56,100 @@ fn variant_name(result: &Result<Vec<SearchHit>, SearchError>) -> &'static str {
 /// tests/search_parity.rs).
 const SHAPES: &[(&str, &str, &str, Class)] = &[
     // ---- stage C3.1: free text, operators, phrase, unknown prefixes ----
-    ("Q01", "alcohol", "phenotype", Class::Match200),         // parity.rs:112
+    ("Q01", "alcohol", "phenotype", Class::Match200), // parity.rs:112
     ("Q03", "alcohol dependence", "phenotype", Class::Match200), // parity.rs:121
-    ("Q04", "\"alcohol dependence\"", "phenotype", Class::Match200), // parity.rs:129
-    ("Q05", "alcohol*", "phenotype", Class::Match200),        // parity.rs:137
-    ("Q06", "Alcohol", "phenotype", Class::Match200),         // parity.rs:145
-    ("Q07", "alcohol AND dependence", "phenotype", Class::Match200), // parity.rs:153
+    (
+        "Q04",
+        "\"alcohol dependence\"",
+        "phenotype",
+        Class::Match200,
+    ), // parity.rs:129
+    ("Q05", "alcohol*", "phenotype", Class::Match200), // parity.rs:137
+    ("Q06", "Alcohol", "phenotype", Class::Match200), // parity.rs:145
+    (
+        "Q07",
+        "alcohol AND dependence",
+        "phenotype",
+        Class::Match200,
+    ), // parity.rs:153
     ("Q08", "alcohol OR dependence", "phenotype", Class::Match200), // parity.rs:161
-    ("Q09", "alcohol NOT dependence", "phenotype", Class::Match200), // parity.rs:169
-    ("Q10", "alcohol XOR dependence", "phenotype", Class::Match200), // parity.rs:177
-    ("Q11", "alcohol NEAR dependence", "phenotype", Class::Match200), // parity.rs:185
-    ("Q12", "alcohol ADJ dependence", "phenotype", Class::Match200), // parity.rs:193
-    ("Q13", "alcohol and dependence", "phenotype", Class::Match200), // parity.rs:201
+    (
+        "Q09",
+        "alcohol NOT dependence",
+        "phenotype",
+        Class::Match200,
+    ), // parity.rs:169
+    (
+        "Q10",
+        "alcohol XOR dependence",
+        "phenotype",
+        Class::Match200,
+    ), // parity.rs:177
+    (
+        "Q11",
+        "alcohol NEAR dependence",
+        "phenotype",
+        Class::Match200,
+    ), // parity.rs:185
+    (
+        "Q12",
+        "alcohol ADJ dependence",
+        "phenotype",
+        Class::Match200,
+    ), // parity.rs:193
+    (
+        "Q13",
+        "alcohol and dependence",
+        "phenotype",
+        Class::Match200,
+    ), // parity.rs:201
     // The && shapes are recorded 200s under libxapian 1.4.29 and live
     // production (harness-report §4 F2/F4; binding-report R1)…
-    ("Q47", "a&&b", "phenotype", Class::Match200),           // parity.rs:459
+    ("Q47", "a&&b", "phenotype", Class::Match200), // parity.rs:459
     // …while the truncated AND is the recorded 4xx (Q51.json).
     ("Q51", "alcohol AND", "phenotype", Class::InvalidQuery), // parity.rs:477
     // An unregistered prefix parses as free text.
-    ("Q50", "foo:bar", "phenotype", Class::Match200),         // parity.rs:469
-    ("Q54", "alcohol &&", "phenotype", Class::Match200),      // parity.rs:501
+    ("Q50", "foo:bar", "phenotype", Class::Match200), // parity.rs:469
+    ("Q54", "alcohol &&", "phenotype", Class::Match200), // parity.rs:501
     // ---- stage C3.2: boolean prefixes (author/species/group/tissue/
     // dataset/symbol/chr/peakchr + the two mixed shapes) ----
-    ("Q14", "author:mulligan", "phenotype", Class::Match200),   // parity.rs:209
-    ("Q15", "species:mouse", "phenotype", Class::Match200),    // parity.rs:217
-    ("Q16", "group:B6", "phenotype", Class::Match200),         // parity.rs:225
-    ("Q17", "group:b6", "phenotype", Class::Match200),         // parity.rs:233
-    ("Q18", "tissue:brain", "phenotype", Class::Match200),     // parity.rs:241
+    ("Q14", "author:mulligan", "phenotype", Class::Match200), // parity.rs:209
+    ("Q15", "species:mouse", "phenotype", Class::Match200),   // parity.rs:217
+    ("Q16", "group:B6", "phenotype", Class::Match200),        // parity.rs:225
+    ("Q17", "group:b6", "phenotype", Class::Match200),        // parity.rs:233
+    ("Q18", "tissue:brain", "phenotype", Class::Match200),    // parity.rs:241
     ("Q19", "dataset:bxdpublish", "phenotype", Class::Match200), // parity.rs:249
-    ("Q20", "symbol:insr", "gene", Class::Match200),           // parity.rs:257
+    ("Q20", "symbol:insr", "gene", Class::Match200),          // parity.rs:257
     ("Q26", "chr:m", "gene", Class::Match200),                // parity.rs:305
-    ("Q27", "peakchr:1", "phenotype", Class::Match200),        // parity.rs:306
+    ("Q27", "peakchr:1", "phenotype", Class::Match200),       // parity.rs:306
     ("Q43", "species:mouse alcohol", "phenotype", Class::Match200), // parity.rs:427
-    ("Q46", "(alcohol OR insulin) AND species:mouse", "phenotype", Class::Match200), // parity.rs:451
+    (
+        "Q46",
+        "(alcohol OR insulin) AND species:mouse",
+        "phenotype",
+        Class::Match200,
+    ), // parity.rs:451
     // ---- stage C3.3: probabilistic prefixes + uppercase aliases ----
     // Corpus-lane note: on the DEPLOYED production index XD is
     // unpopulated (Q21 documented-empty) while rif: has real hits on
     // the dev index (RDF crawl); class-level assertions either way,
     // counts printed as dev reference only.
     ("Q21", "description:insulin", "phenotype", Class::Match200), // parity.rs:265
-    ("Q22", "rif:insulin", "gene", Class::Match200),             // parity.rs:273
-    ("Q23", "RIF:insulin", "gene", Class::Match200),             // parity.rs:281
-    ("Q24", "wiki:diabetes", "phenotype", Class::Match200),     // parity.rs:289
-    ("Q25", "WIKI:diabetes", "phenotype", Class::Match200),     // parity.rs:297
+    ("Q22", "rif:insulin", "gene", Class::Match200),              // parity.rs:273
+    ("Q23", "RIF:insulin", "gene", Class::Match200),              // parity.rs:281
+    ("Q24", "wiki:diabetes", "phenotype", Class::Match200),       // parity.rs:289
+    ("Q25", "WIKI:diabetes", "phenotype", Class::Match200),       // parity.rs:297
     ("Q45", "symbol:insr OR rif:insulin", "gene", Class::Match200), // parity.rs:443
 ];
 
 #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
 async fn native_engine_shape_class_gate() {
     let dev_index = std::env::var("XAPIAN_DB_PATH").unwrap_or_default();
-    if dev_index.is_empty() || !std::fs::metadata(&dev_index).map(|m| m.is_dir()).unwrap_or(false) {
+    if dev_index.is_empty()
+        || !std::fs::metadata(&dev_index)
+            .map(|m| m.is_dir())
+            .unwrap_or(false)
+    {
         eprintln!(
             "SKIPPED: XAPIAN_DB_PATH is not set to an index directory \
              (set it to the dev index for the shape-class gate)"
@@ -122,7 +166,10 @@ async fn native_engine_shape_class_gate() {
             (Class::Match200, Ok(hits)) => {
                 // Dev-index counts are REFERENCE DATA ONLY (AMENDMENT B):
                 // printed, never compared to production counts.
-                eprintln!("  {id} q={query:?} type={type_} class=Match200 dev_hits={}", hits.len());
+                eprintln!(
+                    "  {id} q={query:?} type={type_} class=Match200 dev_hits={}",
+                    hits.len()
+                );
                 passed += 1;
             }
             (Class::InvalidQuery, Err(SearchError::InvalidQuery(detail))) => {