From d9cebff61c86d528cf3d82854d7579713da46847 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 12 Apr 2023 18:17:28 +0200 Subject: [PATCH] Add a simple test to check that attributes are ranking correctly --- .../new/ranking_rule_graph/attribute/mod.rs | 2 +- milli/src/search/new/tests/attribute.rs | 58 +++++++++++++++++++ milli/src/search/new/tests/mod.rs | 1 + 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 milli/src/search/new/tests/attribute.rs diff --git a/milli/src/search/new/ranking_rule_graph/attribute/mod.rs b/milli/src/search/new/ranking_rule_graph/attribute/mod.rs index 80c1f4c6a..a2981c604 100644 --- a/milli/src/search/new/ranking_rule_graph/attribute/mod.rs +++ b/milli/src/search/new/ranking_rule_graph/attribute/mod.rs @@ -25,7 +25,7 @@ impl RankingRuleGraphTrait for AttributeGraph { universe: &RoaringBitmap, ) -> Result { let AttributeCondition { term, .. } = condition; - // maybe compute_query_term_subset_docids should accept a universe as argument + // maybe compute_query_term_subset_docids_within_field_id should accept a universe as argument let mut docids = compute_query_term_subset_docids_within_field_id( ctx, &term.term_subset, diff --git a/milli/src/search/new/tests/attribute.rs b/milli/src/search/new/tests/attribute.rs new file mode 100644 index 000000000..f9b29881b --- /dev/null +++ b/milli/src/search/new/tests/attribute.rs @@ -0,0 +1,58 @@ +use std::collections::HashMap; + +use crate::{ + index::tests::TempIndex, search::new::tests::collect_field_values, Criterion, Search, + SearchResult, TermsMatchingStrategy, +}; + +fn create_index() -> TempIndex { + let index = TempIndex::new(); + + index + .update_settings(|s| { + s.set_primary_key("id".to_owned()); + s.set_searchable_fields(vec![ + "title".to_owned(), + "description".to_owned(), + "plot".to_owned(), + ]); + s.set_criteria(vec![Criterion::Attribute]); + }) + .unwrap(); + + index + .add_documents(documents!([ + { + "id": 0, + "title": "the quick brown fox jumps over the lazy dog", + "description": "Pack my box with five dozen liquor jugs", + "plot": "How vexingly quick daft zebras jump", + }, + { + "id": 1, + "title": "Pack my box with five dozen liquor jugs", + "description": "the quick brown foxes jump over the lazy dog", + "plot": "How vexingly quick daft zebras jump", + }, + { + "id": 2, + "title": "How vexingly quick daft zebras jump", + "description": "Pack my box with five dozen liquor jugs", + "plot": "the quick brown fox jumps over the lazy dog", + } + ])) + .unwrap(); + index +} + +#[test] +fn test_attributes_are_ranked_correctly() { + let index = create_index(); + let txn = index.read_txn().unwrap(); + + let mut s = Search::new(&txn, &index); + s.terms_matching_strategy(TermsMatchingStrategy::All); + s.query("the quick brown fox"); + let SearchResult { documents_ids, .. } = s.execute().unwrap(); + insta::assert_snapshot!(format!("{documents_ids:?}"), @"[0, 1, 2]"); +} diff --git a/milli/src/search/new/tests/mod.rs b/milli/src/search/new/tests/mod.rs index 898276858..9d6d9e159 100644 --- a/milli/src/search/new/tests/mod.rs +++ b/milli/src/search/new/tests/mod.rs @@ -1,3 +1,4 @@ +pub mod attribute; pub mod distinct; #[cfg(feature = "default")] pub mod language;