diff options
| author | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-07 07:30:24 +0300 |
|---|---|---|
| committer | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-07 07:30:24 +0300 |
| commit | d563910a0fc7f61e2a77cd7cc43643e2fe493939 (patch) | |
| tree | 4ab046a9c4169540d57da6f0781b81919fb2e86d | |
| parent | 95e9e7e920be5ccd4bf037b51bef6ab077b59c9a (diff) | |
| download | genenetwork4-d563910a0fc7f61e2a77cd7cc43643e2fe493939.tar.gz | |
src/search/native.rs (native engine): register the probabilistic prefixes and aliases (C3.3).
Port search.py:229-233: description=XD, rif=XRF, wiki=XWK, plus the uppercase aliases RIF=XRF and WIKI=XWK. With STEM_ALL_Z the parsed field term is Z+<prefix>+stem (e.g. wiki:diabetes -> ZXWKdiabet, matching the TermGenerator emission the production indexer writes), pinned hermetically by prefix in native.rs tests. tests/search_native_shapes.rs gains the C3.3 list (Q21-Q25, Q45 with per-shape parity.rs citations). Dev-index reference counts recorded, never compared to production: description:insulin=0, rif:insulin=0, RIF:insulin=0, wiki:diabetes=0 (phenotype type filter: XWK text lives only on gene documents, d.v. index-genenetwork:432-443), WIKI:diabetes=0, symbol:insr OR rif:insulin=1. The 0s are faithful, not registration failures: xapian-delve confirms the fields are populated on the dev index (term ZXWKdiabet: 24 gene docs; ZXRFdiabet exists) while ZXRFinsulin simply does not occur in the crawled RIF text and the phenotype-typed wiki shapes are filtered to an empty set exactly as gn3 would do on this index. Evidence: logs/c3-3.log — build EXIT=0, lib tests green (incl. the probabilistic-prefix assertions), FULL suite EXIT=0, SHAPE-CLASS GATE 33/33 PASS vs the dev index (cumulative C3.1+C3.2+C3.3); delve probe: /home/kabui/zxrf-all.txt, delve-result.txt.
| -rw-r--r-- | src/search/native.rs | 32 | ||||
| -rw-r--r-- | tests/search_native_shapes.rs | 23 |
2 files changed, 51 insertions, 4 deletions
diff --git a/src/search/native.rs b/src/search/native.rs index 14db735..a7b2fb5 100644 --- a/src/search/native.rs +++ b/src/search/native.rs @@ -91,6 +91,14 @@ fn build_query_parser() -> QueryParser { 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); + // Probabilistic prefixes (search.py:229-233): weighted (BM25-scored) + // text fields, freely mixable with free text and operators; rif and + // wiki also answer to their uppercase aliases (search.py:232-233). + qp.add_prefix::<&str>("description", Some("XD")); + qp.add_prefix::<&str>("rif", Some("XRF")); + qp.add_prefix::<&str>("wiki", Some("XWK")); + qp.add_prefix::<&str>("RIF", Some("XRF")); + qp.add_prefix::<&str>("WIKI", Some("XWK")); qp } @@ -286,6 +294,30 @@ mod tests { assert!(!b6.contains("XGBXD"), "group must not emit the raw-case term"); } + /// The probabilistic-prefix registrations (C3.3): description, rif, + /// wiki and the uppercase aliases must parse as weighted field + /// terms, not free text (search.py:229-233). With STEM_ALL_Z the + /// field term is the prefix + Z-stemmed value (e.g. XDZinsulin), + /// so assert on the prefix, the invariant the registration owns. + #[test] + fn probabilistic_prefixes_and_aliases_parse_as_field_terms() { + let mut qp = build_query_parser(); + let prefixed = |query: &str, prefix: &str| { + let set = 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::<std::collections::BTreeSet<_>>(); + set.iter().any(|t| t.starts_with(prefix)) + }; + assert!(prefixed("description:insulin", "XD")); + assert!(prefixed("rif:insulin", "XRF")); + assert!(prefixed("RIF:insulin", "XRF")); + assert!(prefixed("wiki:diabetes", "XWK")); + assert!(prefixed("WIKI:diabetes", "XWK")); + } + /// The index-open guards, without touching a real index. #[test] fn open_database_maps_failures_onto_the_seam_vocabulary() { diff --git a/tests/search_native_shapes.rs b/tests/search_native_shapes.rs index 9d87615..a9b7489 100644 --- a/tests/search_native_shapes.rs +++ b/tests/search_native_shapes.rs @@ -18,9 +18,13 @@ //! //! The lists are cumulative per stage, matching the parser //! configuration at each commit: -//! - stage C3.1 (this file's first commit): free text, operators, -//! phrase, wildcard, case, unknown-prefix-as-text, the && shapes -//! and the one parser-error shape — Stem("en") + STEM_ALL_Z only. +//! - stage C3.1: free text, operators, phrase, wildcard, case, +//! unknown-prefix-as-text, the && shapes and the one parser-error +//! shape — Stem("en") + STEM_ALL_Z only; +//! - stage C3.2: + the boolean prefixes (author/species/group/tissue/ +//! dataset/symbol/chr/peakchr) and the two mixed shapes; +//! - stage C3.3: + the probabilistic prefixes and aliases +//! (description/rif/wiki/RIF/WIKI). //! //! Env: `XAPIAN_DB_PATH` must point at the dev index (the gate runs //! set it to ~/spikes/index-self-build/xapian-index); the test skips @@ -85,6 +89,17 @@ const SHAPES: &[(&str, &str, &str, Class)] = &[ ("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 + // ---- 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 + ("Q45", "symbol:insr OR rif:insulin", "gene", Class::Match200), // parity.rs:443 ]; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -125,7 +140,7 @@ async fn native_engine_shape_class_gate() { } let summary = if failed.is_empty() { - "stages C3.1 + C3.2".to_string() + "stages C3.1 + C3.2 + C3.3".to_string() } else { format!("FAILED: {failed:?}") }; |
