about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/search/native.rs32
1 files changed, 32 insertions, 0 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() {