mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-28 09:11:00 +00:00
Revert "Sort at query time"
This commit is contained in:
committed by
GitHub
parent
41fc0dcb62
commit
922f9fd4d5
@ -1,6 +1,6 @@
|
||||
use big_s::S;
|
||||
use milli::update::Settings;
|
||||
use milli::{AscDesc, Criterion, Search, SearchResult};
|
||||
use milli::{Criterion, Search, SearchResult};
|
||||
use Criterion::*;
|
||||
|
||||
use crate::search::{self, EXTERNAL_DOCUMENTS_IDS};
|
||||
@ -11,7 +11,7 @@ const ALLOW_OPTIONAL_WORDS: bool = true;
|
||||
const DISALLOW_OPTIONAL_WORDS: bool = false;
|
||||
|
||||
macro_rules! test_criterion {
|
||||
($func:ident, $optional_word:ident, $authorize_typos:ident, $criteria:expr, $sort_criteria:expr) => {
|
||||
($func:ident, $optional_word:ident, $authorize_typos:ident, $criteria:expr) => {
|
||||
#[test]
|
||||
fn $func() {
|
||||
let criteria = $criteria;
|
||||
@ -23,168 +23,82 @@ macro_rules! test_criterion {
|
||||
search.limit(EXTERNAL_DOCUMENTS_IDS.len());
|
||||
search.authorize_typos($authorize_typos);
|
||||
search.optional_words($optional_word);
|
||||
search.sort_criteria($sort_criteria);
|
||||
|
||||
let SearchResult { documents_ids, .. } = search.execute().unwrap();
|
||||
|
||||
let expected_external_ids: Vec<_> = search::expected_order(
|
||||
&criteria,
|
||||
$authorize_typos,
|
||||
$optional_word,
|
||||
&$sort_criteria[..],
|
||||
)
|
||||
.into_iter()
|
||||
.map(|d| d.id)
|
||||
.collect();
|
||||
let expected_external_ids: Vec<_> =
|
||||
search::expected_order(&criteria, $authorize_typos, $optional_word)
|
||||
.into_iter()
|
||||
.map(|d| d.id)
|
||||
.collect();
|
||||
let documents_ids = search::internal_to_external_ids(&index, &documents_ids);
|
||||
assert_eq!(documents_ids, expected_external_ids);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test_criterion!(none_allow_typo, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![], vec![]);
|
||||
test_criterion!(none_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS, vec![], vec![]);
|
||||
test_criterion!(words_allow_typo, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Words], vec![]);
|
||||
test_criterion!(
|
||||
attribute_allow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
ALLOW_TYPOS,
|
||||
vec![Attribute],
|
||||
vec![]
|
||||
);
|
||||
test_criterion!(
|
||||
attribute_disallow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
DISALLOW_TYPOS,
|
||||
vec![Attribute],
|
||||
vec![]
|
||||
);
|
||||
test_criterion!(
|
||||
exactness_allow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
ALLOW_TYPOS,
|
||||
vec![Exactness],
|
||||
vec![]
|
||||
);
|
||||
test_criterion!(
|
||||
exactness_disallow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
DISALLOW_TYPOS,
|
||||
vec![Exactness],
|
||||
vec![]
|
||||
);
|
||||
test_criterion!(
|
||||
proximity_allow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
ALLOW_TYPOS,
|
||||
vec![Proximity],
|
||||
vec![]
|
||||
);
|
||||
test_criterion!(
|
||||
proximity_disallow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
DISALLOW_TYPOS,
|
||||
vec![Proximity],
|
||||
vec![]
|
||||
);
|
||||
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"))],
|
||||
vec![]
|
||||
vec![Asc(S("asc_desc_rank"))]
|
||||
);
|
||||
test_criterion!(
|
||||
asc_disallow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
DISALLOW_TYPOS,
|
||||
vec![Asc(S("asc_desc_rank"))],
|
||||
vec![]
|
||||
vec![Asc(S("asc_desc_rank"))]
|
||||
);
|
||||
test_criterion!(
|
||||
desc_allow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
ALLOW_TYPOS,
|
||||
vec![Desc(S("asc_desc_rank"))],
|
||||
vec![]
|
||||
vec![Desc(S("asc_desc_rank"))]
|
||||
);
|
||||
test_criterion!(
|
||||
desc_disallow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
DISALLOW_TYPOS,
|
||||
vec![Desc(S("asc_desc_rank"))],
|
||||
vec![]
|
||||
vec![Desc(S("asc_desc_rank"))]
|
||||
);
|
||||
test_criterion!(
|
||||
asc_unexisting_field_allow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
ALLOW_TYPOS,
|
||||
vec![Asc(S("unexisting_field"))],
|
||||
vec![]
|
||||
vec![Asc(S("unexisting_field"))]
|
||||
);
|
||||
test_criterion!(
|
||||
asc_unexisting_field_disallow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
DISALLOW_TYPOS,
|
||||
vec![Asc(S("unexisting_field"))],
|
||||
vec![]
|
||||
vec![Asc(S("unexisting_field"))]
|
||||
);
|
||||
test_criterion!(
|
||||
desc_unexisting_field_allow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
ALLOW_TYPOS,
|
||||
vec![Desc(S("unexisting_field"))],
|
||||
vec![]
|
||||
vec![Desc(S("unexisting_field"))]
|
||||
);
|
||||
test_criterion!(
|
||||
desc_unexisting_field_disallow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
DISALLOW_TYPOS,
|
||||
vec![Desc(S("unexisting_field"))],
|
||||
vec![]
|
||||
);
|
||||
test_criterion!(empty_sort_by_allow_typo, DISALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, vec![Sort], vec![]);
|
||||
test_criterion!(
|
||||
empty_sort_by_disallow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
DISALLOW_TYPOS,
|
||||
vec![Sort],
|
||||
vec![]
|
||||
);
|
||||
test_criterion!(
|
||||
sort_by_asc_allow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
ALLOW_TYPOS,
|
||||
vec![Sort],
|
||||
vec![AscDesc::Asc(S("tag"))]
|
||||
);
|
||||
test_criterion!(
|
||||
sort_by_asc_disallow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
DISALLOW_TYPOS,
|
||||
vec![Sort],
|
||||
vec![AscDesc::Asc(S("tag"))]
|
||||
);
|
||||
test_criterion!(
|
||||
sort_by_desc_allow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
ALLOW_TYPOS,
|
||||
vec![Sort],
|
||||
vec![AscDesc::Desc(S("tag"))]
|
||||
);
|
||||
test_criterion!(
|
||||
sort_by_desc_disallow_typo,
|
||||
DISALLOW_OPTIONAL_WORDS,
|
||||
DISALLOW_TYPOS,
|
||||
vec![Sort],
|
||||
vec![AscDesc::Desc(S("tag"))]
|
||||
vec![Desc(S("unexisting_field"))]
|
||||
);
|
||||
test_criterion!(
|
||||
default_criteria_order,
|
||||
ALLOW_OPTIONAL_WORDS,
|
||||
ALLOW_TYPOS,
|
||||
vec![Words, Typo, Proximity, Attribute, Exactness],
|
||||
vec![]
|
||||
vec![Words, Typo, Proximity, Attribute, Exactness]
|
||||
);
|
||||
|
||||
#[test]
|
||||
@ -348,7 +262,7 @@ fn criteria_mixup() {
|
||||
let SearchResult { documents_ids, .. } = search.execute().unwrap();
|
||||
|
||||
let expected_external_ids: Vec<_> =
|
||||
search::expected_order(&criteria, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, &[])
|
||||
search::expected_order(&criteria, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS)
|
||||
.into_iter()
|
||||
.map(|d| d.id)
|
||||
.collect();
|
||||
|
Reference in New Issue
Block a user