diff options
| author | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-07 07:05:06 +0300 |
|---|---|---|
| committer | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-07 07:05:06 +0300 |
| commit | 13a7cb117deadd7a8253e218ede7d6cd430c9da7 (patch) | |
| tree | 5484d665fc03b7a078be6787b90f29b4e82aef12 /src | |
| parent | a5c40fc78f6b3cb32fba3daeb9f2a8e95558ba09 (diff) | |
| download | genenetwork4-13a7cb117deadd7a8253e218ede7d6cd430c9da7.tar.gz | |
src/search/native.rs (native engine): register the boolean prefixes (C3.2).
Port search.py:220-228: author=A, species=XS, group=XG (through the lowercasing FieldProcessor, search.py:204-209/222-223 — xapian does not stem boolean prefixed fields when the value starts with a capital, so gn3 forces the lowercase term; the r1-test LowercaseGroupProcessor pattern), tissue=XI, dataset=XDS, symbol=XY, chr=XC, peakchr=XPC. The upstream cases rule (uppercase values produce XDS:BXDPublish-style terms — binding-report R2: gn3-inherited xapian behavior, not a registration bug) is documented, not pinned: no graded shape relies on it. tests/search_native_shapes.rs gains the C3.2 list (Q14-Q20, Q26, Q27, Q43, Q46 with per-shape parity.rs citations); native.rs gains a hermetic parser test pinning each registration to its exact index term (group:B6 -> XGbxd, not XGBXD). Evidence: logs/c3-2.log — build EXIT=0, lib tests green (incl. the new prefix assertions), FULL suite EXIT=0, SHAPE-CLASS GATE 27/27 PASS vs the dev index (cumulative C3.1+C3.2; dev counts recorded as reference: group:B6 = 3, symbol:insr = 1, peakchr:1 = 113, etc.).
Diffstat (limited to 'src')
| -rw-r--r-- | src/search/native.rs | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/search/native.rs b/src/search/native.rs index c87f711..14db735 100644 --- a/src/search/native.rs +++ b/src/search/native.rs @@ -44,7 +44,8 @@ use super::{Engine, SearchError, SearchHit}; use std::sync::{Mutex, OnceLock}; -use xapian_rs::{Database, Enquire, 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` @@ -80,9 +81,33 @@ fn build_query_parser() -> QueryParser { // are stemmed and matched case-insensitively). qp.set_stemmer(Stem::for_language("en")); qp.set_stemming_strategy(StemStrategy::AllZ); + // Boolean prefixes (search.py:220-228; r1-test:95-96, R2 + // skeleton). Values match exactly; `group` lowercases first (below). + qp.add_boolean_prefix::<&str, &str>("author", Some("A"), None); + qp.add_boolean_prefix::<&str, &str>("species", Some("XS"), None); + qp.add_custom_boolean_prefix::<_, &str>("group", LowercaseGroupProcessor, None); + qp.add_boolean_prefix::<&str, &str>("tissue", Some("XI"), None); + qp.add_boolean_prefix::<&str, &str>("dataset", Some("XDS"), None); + qp.add_boolean_prefix::<&str, &str>("symbol", Some("XY"), None); + qp.add_boolean_prefix::<&str, &str>("chr", Some("XC"), None); + qp.add_boolean_prefix::<&str, &str>("peakchr", Some("XPC"), None); qp } +/// gn3 parity: `group` values are lowercased before the `XG` prefix is +/// applied — xapian does not stem boolean prefixed fields when the +/// value starts with a capital, so gn3 forces the lowercase form +/// (search.py:204-209, 222-223; the r1-test `LowercaseGroupProcessor` +/// pattern). +#[derive(Clone)] +struct LowercaseGroupProcessor; + +impl FieldProcessor for LowercaseGroupProcessor { + fn process(&self, term: &str) -> Option<Query> { + Some(Query::term(format!("XG{}", term.to_lowercase()), None, None)) + } +} + /// The native xapian search engine. Configure the index directory with /// `XAPIAN_DB_PATH` and select it with `SEARCH_ENGINE=native`; the /// default remains the gn3 forwarder (see [`crate::search::search`]). @@ -227,6 +252,40 @@ mod tests { .expect("unregistered prefixes parse as text (Q50)"); } + /// The boolean-prefix registrations (C3.2): the registered + /// prefixes must leave the free-text path and produce their exact + /// index terms, `group` lowercasing its value on the way. Hermetic: + /// assertions read the parsed query terms, no index involved. + #[test] + fn boolean_prefixes_parse_to_exact_index_terms() { + let mut qp = build_query_parser(); + let terms = |query: &str| -> std::collections::BTreeSet<String> { + qp.parse_query_checked::<&str>(query, None, None) + .unwrap_or_else(|e| panic!("{query} must parse: {e:?}")) + .unique_terms() + .map(|t| t.to_string()) + .collect() + }; + + // search.py:220-228: prefix -> index term (lowercase values + // concatenate, the case the graded shapes use). The uppercase- + // value quirk (XDS:BXDPublish-style terms, binding-report R2: + // gn3-inherited xapian behavior, not a registration bug) is + // documented but not pinned here; no graded shape relies on it. + assert!(terms("author:mulligan").contains("Amulligan")); + assert!(terms("species:mouse").contains("XSmouse")); + assert!(terms("tissue:brain").contains("XIbrain")); + assert!(terms("dataset:bxdpublish").contains("XDSbxdpublish")); + assert!(terms("symbol:insr").contains("XYinsr")); + assert!(terms("chr:1").contains("XC1")); + assert!(terms("peakchr:1").contains("XPC1")); + // search.py:204-209, 222-223: group values lowercase (xapian + // does not stem boolean fields starting with a capital). + let b6 = terms("group:B6"); + assert!(b6.contains("XGbxd"), "group:B6 must lowercase to XGbxd, got {b6:?}"); + assert!(!b6.contains("XGBXD"), "group must not emit the raw-case term"); + } + /// The index-open guards, without touching a real index. #[test] fn open_database_maps_failures_onto_the_seam_vocabulary() { |
