From 6cb1102bdb6c1508bee51b0fc78d2038701ccee4 Mon Sep 17 00:00:00 2001 From: many Date: Thu, 17 Jun 2021 15:19:03 +0200 Subject: [PATCH] Fix PR comments --- milli/tests/search/distinct.rs | 42 +++++------ milli/tests/search/filters.rs | 80 ++++++++++----------- milli/tests/search/mod.rs | 3 - milli/tests/search/query_criteria.rs | 103 +++++++++++++++++---------- 4 files changed, 121 insertions(+), 107 deletions(-) diff --git a/milli/tests/search/distinct.rs b/milli/tests/search/distinct.rs index 1204a6bfb..ef5af3272 100644 --- a/milli/tests/search/distinct.rs +++ b/milli/tests/search/distinct.rs @@ -21,9 +21,9 @@ macro_rules! test_distinct { builder.execute(|_, _| ()).unwrap(); wtxn.commit().unwrap(); - let mut rtxn = index.read_txn().unwrap(); + let rtxn = index.read_txn().unwrap(); - let mut search = Search::new(&mut rtxn, &index); + let mut search = Search::new(&rtxn, &index); search.query(search::TEST_QUERY); search.limit(EXTERNAL_DOCUMENTS_IDS.len()); search.authorize_typos(true); @@ -50,27 +50,23 @@ macro_rules! test_distinct { }; } -#[rustfmt::skip] -test_distinct!(distinct_string_default_criteria, tag, vec![Words, Typo, Proximity, Attribute, Exactness]); -#[rustfmt::skip] -test_distinct!(distinct_number_default_criteria, asc_desc_rank, vec![Words, Typo, Proximity, Attribute, Exactness]); -#[rustfmt::skip] -test_distinct!(distinct_string_criterion_words, tag, vec![Words]); -#[rustfmt::skip] -test_distinct!(distinct_number_criterion_words, asc_desc_rank, vec![Words]); -#[rustfmt::skip] -test_distinct!(distinct_string_criterion_words_typo, tag, vec![Words, Typo]); -#[rustfmt::skip] -test_distinct!(distinct_number_criterion_words_typo, asc_desc_rank, vec![Words, Typo]); -#[rustfmt::skip] -test_distinct!(distinct_string_criterion_words_proximity, tag, vec![Words, Proximity]); -#[rustfmt::skip] +test_distinct!( + distinct_string_default_criteria, + tag, + vec![Words, Typo, Proximity, Attribute, Exactness] +); +test_distinct!( + distinct_number_default_criteria, + asc_desc_rank, + vec![Words, Typo, Proximity, Attribute, Exactness] +); +test_distinct!(distinct_string_criterion_words, tag, vec![Words]); +test_distinct!(distinct_number_criterion_words, asc_desc_rank, vec![Words]); +test_distinct!(distinct_string_criterion_words_typo, tag, vec![Words, Typo]); +test_distinct!(distinct_number_criterion_words_typo, asc_desc_rank, vec![Words, Typo]); +test_distinct!(distinct_string_criterion_words_proximity, tag, vec![Words, Proximity]); test_distinct!(distinct_number_criterion_words_proximity, asc_desc_rank, vec![Words, Proximity]); -#[rustfmt::skip] -test_distinct!(distinct_string_criterion_words_attribute, tag, vec![Words, Attribute]); -#[rustfmt::skip] +test_distinct!(distinct_string_criterion_words_attribute, tag, vec![Words, Attribute]); test_distinct!(distinct_number_criterion_words_attribute, asc_desc_rank, vec![Words, Attribute]); -#[rustfmt::skip] -test_distinct!(distinct_string_criterion_words_exactness, tag, vec![Words, Exactness]); -#[rustfmt::skip] +test_distinct!(distinct_string_criterion_words_exactness, tag, vec![Words, Exactness]); test_distinct!(distinct_number_criterion_words_exactness, asc_desc_rank, vec![Words, Exactness]); diff --git a/milli/tests/search/filters.rs b/milli/tests/search/filters.rs index 790bd4a58..318197ea3 100644 --- a/milli/tests/search/filters.rs +++ b/milli/tests/search/filters.rs @@ -10,7 +10,7 @@ macro_rules! test_filter { fn $func() { let criteria = vec![Words, Typo, Proximity, Attribute, Exactness]; let index = search::setup_search_index_with_criteria(&criteria); - let mut rtxn = index.read_txn().unwrap(); + let rtxn = index.read_txn().unwrap(); let filter_conditions = FilterCondition::from_array::, &str>>, _, _, _>( @@ -19,7 +19,7 @@ macro_rules! test_filter { .unwrap() .unwrap(); - let mut search = Search::new(&mut rtxn, &index); + let mut search = Search::new(&rtxn, &index); search.query(search::TEST_QUERY); search.limit(EXTERNAL_DOCUMENTS_IDS.len()); search.authorize_typos(true); @@ -40,45 +40,39 @@ macro_rules! test_filter { }; } -#[rustfmt::skip] -test_filter!(eq_simple_string_filter, vec![Right("tag=red")]); -#[rustfmt::skip] -test_filter!(eq_simple_number_filter, vec![Right("asc_desc_rank=1")]); -#[rustfmt::skip] +test_filter!(eq_simple_string_filter, vec![Right("tag=red")]); +test_filter!(eq_simple_number_filter, vec![Right("asc_desc_rank=1")]); test_filter!(eq_string_and_filter_return_empty, vec![Right("tag=red"), Right("tag=green")]); -#[rustfmt::skip] -test_filter!(eq_mix_and_filter, vec![Right("tag=red"), Right("asc_desc_rank=1")]); -#[rustfmt::skip] -test_filter!(eq_string_or_filter, vec![Left(vec!["tag=red", "tag=green"])]); -#[rustfmt::skip] -test_filter!(eq_mix_or_filter, vec![Left(vec!["tag=red", "asc_desc_rank=1"])]); -#[rustfmt::skip] -test_filter!(eq_number_or_filter, vec![Left(vec!["asc_desc_rank=3", "asc_desc_rank=1"])]); -#[rustfmt::skip] -test_filter!(eq_complex_filter, vec![Left(vec!["tag=red", "tag=green"]), Right("asc_desc_rank=3")]); -#[rustfmt::skip] -test_filter!(eq_complex_filter_2, vec![Left(vec!["tag=red", "tag=green"]), Left(vec!["asc_desc_rank=3", "asc_desc_rank=1"])]); -#[rustfmt::skip] -test_filter!(greater_simple_number_filter, vec![Right("asc_desc_rank>1")]); -#[rustfmt::skip] -test_filter!(greater_mix_and_filter, vec![Right("tag=red"), Right("asc_desc_rank>1")]); -#[rustfmt::skip] -test_filter!(greater_mix_or_filter, vec![Left(vec!["tag=red", "asc_desc_rank>1"])]); -#[rustfmt::skip] -test_filter!(greater_number_or_filter, vec![Left(vec!["asc_desc_rank>3", "asc_desc_rank>1"])]); -#[rustfmt::skip] -test_filter!(greater_complex_filter, vec![Left(vec!["tag=red", "tag=green"]), Right("asc_desc_rank>3")]); -#[rustfmt::skip] -test_filter!(greater_complex_filter_2, vec![Left(vec!["tag=red", "tag=green"]), Left(vec!["asc_desc_rank>3", "asc_desc_rank>1"])]); -#[rustfmt::skip] -test_filter!(lower_simple_number_filter, vec![Right("asc_desc_rank<1")]); -#[rustfmt::skip] -test_filter!(lower_mix_and_filter, vec![Right("tag=red"), Right("asc_desc_rank<1")]); -#[rustfmt::skip] -test_filter!(lower_mix_or_filter, vec![Left(vec!["tag=red", "asc_desc_rank<1"])]); -#[rustfmt::skip] -test_filter!(lower_number_or_filter, vec![Left(vec!["asc_desc_rank<3", "asc_desc_rank<1"])]); -#[rustfmt::skip] -test_filter!(lower_complex_filter, vec![Left(vec!["tag=red", "tag=green"]), Right("asc_desc_rank<3")]); -#[rustfmt::skip] -test_filter!(lower_complex_filter_2, vec![Left(vec!["tag=red", "tag=green"]), Left(vec!["asc_desc_rank<3", "asc_desc_rank<1"])]); +test_filter!(eq_mix_and_filter, vec![Right("tag=red"), Right("asc_desc_rank=1")]); +test_filter!(eq_string_or_filter, vec![Left(vec!["tag=red", "tag=green"])]); +test_filter!(eq_mix_or_filter, vec![Left(vec!["tag=red", "asc_desc_rank=1"])]); +test_filter!(eq_number_or_filter, vec![Left(vec!["asc_desc_rank=3", "asc_desc_rank=1"])]); +test_filter!(eq_complex_filter, vec![Left(vec!["tag=red", "tag=green"]), Right("asc_desc_rank=3")]); +test_filter!( + eq_complex_filter_2, + vec![Left(vec!["tag=red", "tag=green"]), Left(vec!["asc_desc_rank=3", "asc_desc_rank=1"])] +); +test_filter!(greater_simple_number_filter, vec![Right("asc_desc_rank>1")]); +test_filter!(greater_mix_and_filter, vec![Right("tag=red"), Right("asc_desc_rank>1")]); +test_filter!(greater_mix_or_filter, vec![Left(vec!["tag=red", "asc_desc_rank>1"])]); +test_filter!(greater_number_or_filter, vec![Left(vec!["asc_desc_rank>3", "asc_desc_rank>1"])]); +test_filter!( + greater_complex_filter, + vec![Left(vec!["tag=red", "tag=green"]), Right("asc_desc_rank>3")] +); +test_filter!( + greater_complex_filter_2, + vec![Left(vec!["tag=red", "tag=green"]), Left(vec!["asc_desc_rank>3", "asc_desc_rank>1"])] +); +test_filter!(lower_simple_number_filter, vec![Right("asc_desc_rank<1")]); +test_filter!(lower_mix_and_filter, vec![Right("tag=red"), Right("asc_desc_rank<1")]); +test_filter!(lower_mix_or_filter, vec![Left(vec!["tag=red", "asc_desc_rank<1"])]); +test_filter!(lower_number_or_filter, vec![Left(vec!["asc_desc_rank<3", "asc_desc_rank<1"])]); +test_filter!( + lower_complex_filter, + vec![Left(vec!["tag=red", "tag=green"]), Right("asc_desc_rank<3")] +); +test_filter!( + lower_complex_filter_2, + vec![Left(vec!["tag=red", "tag=green"]), Left(vec!["asc_desc_rank<3", "asc_desc_rank<1"])] +); diff --git a/milli/tests/search/mod.rs b/milli/tests/search/mod.rs index d37904942..c5724a921 100644 --- a/milli/tests/search/mod.rs +++ b/milli/tests/search/mod.rs @@ -128,7 +128,6 @@ pub fn expected_order( fn execute_filter(filter: &str, document: &TestDocument) -> Option { let mut id = None; if let Some((field, filter)) = filter.split_once("=") { - println!("eq on field {} with filter {}", field, filter); if field == "tag" && document.tag == filter { id = Some(document.id.clone()) } else if field == "asc_desc_rank" @@ -137,12 +136,10 @@ fn execute_filter(filter: &str, document: &TestDocument) -> Option { id = Some(document.id.clone()) } } else if let Some(("asc_desc_rank", filter)) = filter.split_once("<") { - println!("lower on field asc_desc_rank with filter {}", filter); if document.asc_desc_rank < filter.parse().unwrap() { id = Some(document.id.clone()) } } else if let Some(("asc_desc_rank", filter)) = filter.split_once(">") { - println!("higher on field asc_desc_rank with filter {}", filter); if document.asc_desc_rank > filter.parse().unwrap() { id = Some(document.id.clone()) } diff --git a/milli/tests/search/query_criteria.rs b/milli/tests/search/query_criteria.rs index 486768228..f814508f5 100644 --- a/milli/tests/search/query_criteria.rs +++ b/milli/tests/search/query_criteria.rs @@ -16,9 +16,9 @@ macro_rules! test_criterion { fn $func() { let criteria = $criteria; let index = search::setup_search_index_with_criteria(&criteria); - let mut rtxn = index.read_txn().unwrap(); + let rtxn = index.read_txn().unwrap(); - let mut search = Search::new(&mut rtxn, &index); + let mut search = Search::new(&rtxn, &index); search.query(search::TEST_QUERY); search.limit(EXTERNAL_DOCUMENTS_IDS.len()); search.authorize_typos($authorize_typos); @@ -37,42 +37,69 @@ macro_rules! test_criterion { }; } -#[rustfmt::skip] -test_criterion!(none_allow_typo, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![]); -#[rustfmt::skip] -test_criterion!(none_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![]); -#[rustfmt::skip] -test_criterion!(words_allow_typo, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Words]); -#[rustfmt::skip] -test_criterion!(attribute_allow_typo, DISALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Attribute]); -#[rustfmt::skip] -test_criterion!(attribute_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![Attribute]); -#[rustfmt::skip] -test_criterion!(exactness_allow_typo, DISALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Exactness]); -#[rustfmt::skip] -test_criterion!(exactness_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![Exactness]); -#[rustfmt::skip] -test_criterion!(proximity_allow_typo, DISALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Proximity]); -#[rustfmt::skip] -test_criterion!(proximity_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![Proximity]); -#[rustfmt::skip] -test_criterion!(asc_allow_typo, DISALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Asc(S("asc_desc_rank"))]); -#[rustfmt::skip] -test_criterion!(asc_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![Asc(S("asc_desc_rank"))]); -#[rustfmt::skip] -test_criterion!(desc_allow_typo, DISALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Desc(S("asc_desc_rank"))]); -#[rustfmt::skip] -test_criterion!(desc_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![Desc(S("asc_desc_rank"))]); -#[rustfmt::skip] -test_criterion!(asc_unexisting_field_allow_typo, DISALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Asc(S("unexisting_field"))]); -#[rustfmt::skip] -test_criterion!(asc_unexisting_field_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![Asc(S("unexisting_field"))]); -#[rustfmt::skip] -test_criterion!(desc_unexisting_field_allow_typo, DISALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Desc(S("unexisting_field"))]); -#[rustfmt::skip] -test_criterion!(desc_unexisting_field_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![Desc(S("unexisting_field"))]); -#[rustfmt::skip] -test_criterion!(default_criteria_order, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Words, Typo, Proximity, Attribute, Exactness]); +test_criterion!(none_allow_typo, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![]); +test_criterion!(none_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![]); +test_criterion!(words_allow_typo, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Words]); +test_criterion!(attribute_allow_typo, DISALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Attribute]); +test_criterion!(attribute_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![Attribute]); +test_criterion!(exactness_allow_typo, DISALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Exactness]); +test_criterion!(exactness_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![Exactness]); +test_criterion!(proximity_allow_typo, DISALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Proximity]); +test_criterion!(proximity_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![Proximity]); +test_criterion!( + asc_allow_typo, + DISALLOW_OPTIONAL_WORDS, + ALLOW_TYPOS, + vec![Asc(S("asc_desc_rank"))] +); +test_criterion!( + asc_disallow_typo, + DISALLOW_OPTIONAL_WORDS, + DISALLOW_TYPOS, + vec![Asc(S("asc_desc_rank"))] +); +test_criterion!( + desc_allow_typo, + DISALLOW_OPTIONAL_WORDS, + ALLOW_TYPOS, + vec![Desc(S("asc_desc_rank"))] +); +test_criterion!( + desc_disallow_typo, + DISALLOW_OPTIONAL_WORDS, + DISALLOW_TYPOS, + vec![Desc(S("asc_desc_rank"))] +); +test_criterion!( + asc_unexisting_field_allow_typo, + DISALLOW_OPTIONAL_WORDS, + ALLOW_TYPOS, + vec![Asc(S("unexisting_field"))] +); +test_criterion!( + asc_unexisting_field_disallow_typo, + DISALLOW_OPTIONAL_WORDS, + DISALLOW_TYPOS, + vec![Asc(S("unexisting_field"))] +); +test_criterion!( + desc_unexisting_field_allow_typo, + DISALLOW_OPTIONAL_WORDS, + ALLOW_TYPOS, + vec![Desc(S("unexisting_field"))] +); +test_criterion!( + desc_unexisting_field_disallow_typo, + DISALLOW_OPTIONAL_WORDS, + DISALLOW_TYPOS, + vec![Desc(S("unexisting_field"))] +); +test_criterion!( + default_criteria_order, + ALLOW_OPTIONAL_WORDS, + ALLOW_TYPOS, + vec![Words, Typo, Proximity, Attribute, Exactness] +); #[test] fn criteria_mixup() {