From 5989528833d1f70baf49a288f566a09555ff052c Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 7 Sep 2021 11:01:37 +0200 Subject: [PATCH] Add a test to make sure we throw the right error message --- milli/tests/search/mod.rs | 1 + milli/tests/search/sort.rs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 milli/tests/search/sort.rs diff --git a/milli/tests/search/mod.rs b/milli/tests/search/mod.rs index 0fbc0e1b6..c34434c4e 100644 --- a/milli/tests/search/mod.rs +++ b/milli/tests/search/mod.rs @@ -13,6 +13,7 @@ use slice_group_by::GroupBy; mod distinct; mod filters; mod query_criteria; +mod sort; pub const TEST_QUERY: &'static str = "hello world america"; diff --git a/milli/tests/search/sort.rs b/milli/tests/search/sort.rs new file mode 100644 index 000000000..fe87f0623 --- /dev/null +++ b/milli/tests/search/sort.rs @@ -0,0 +1,23 @@ +use big_s::S; +use milli::Criterion::{Attribute, Exactness, Proximity, Typo, Words}; +use milli::{AscDesc, Error, Search, UserError}; + +use crate::search::{self, EXTERNAL_DOCUMENTS_IDS}; + +#[test] +fn sort_ranking_rule_missing() { + let criteria = vec![Words, Typo, Proximity, Attribute, Exactness]; + // sortables: `tag` and `asc_desc_rank` + let index = search::setup_search_index_with_criteria(&criteria); + let rtxn = index.read_txn().unwrap(); + + let mut search = Search::new(&rtxn, &index); + search.query(search::TEST_QUERY); + search.limit(EXTERNAL_DOCUMENTS_IDS.len()); + search.authorize_typos(true); + search.optional_words(true); + search.sort_criteria(vec![AscDesc::Asc(S("tag"))]); + + let result = search.execute(); + assert!(matches!(result, Err(Error::UserError(UserError::SortRankingRuleMissing)))); +}