mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
Resolve PR comments
This commit is contained in:
parent
1fcc5f73ac
commit
b64cd2a3e3
@ -52,13 +52,6 @@ pub fn setup_search_index_with_criteria(criteria: &[Criterion]) -> Index {
|
|||||||
index
|
index
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn external_to_internal_ids(index: &Index, external_ids: &[&str]) -> Vec<DocumentId> {
|
|
||||||
let mut rtxn = index.read_txn().unwrap();
|
|
||||||
let docid_map = index.external_documents_ids(&mut rtxn).unwrap();
|
|
||||||
external_ids.iter().map(|id| docid_map.get(id).unwrap()).collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn internal_to_external_ids(index: &Index, internal_ids: &[DocumentId]) -> Vec<String> {
|
pub fn internal_to_external_ids(index: &Index, internal_ids: &[DocumentId]) -> Vec<String> {
|
||||||
let mut rtxn = index.read_txn().unwrap();
|
let mut rtxn = index.read_txn().unwrap();
|
||||||
let docid_map = index.external_documents_ids(&mut rtxn).unwrap();
|
let docid_map = index.external_documents_ids(&mut rtxn).unwrap();
|
||||||
@ -70,7 +63,7 @@ fn fetch_dataset() -> Vec<TestDocument> {
|
|||||||
serde_json::Deserializer::from_str(CONTENT).into_iter().map(|r| r.unwrap()).collect()
|
serde_json::Deserializer::from_str(CONTENT).into_iter().map(|r| r.unwrap()).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expected_order(criteria: &[Criterion], autorize_typo: bool, optional_words: bool) -> Vec<TestDocument> {
|
pub fn expected_order(criteria: &[Criterion], authorize_typo: bool, optional_words: bool) -> Vec<TestDocument> {
|
||||||
let dataset = fetch_dataset();
|
let dataset = fetch_dataset();
|
||||||
let mut groups: Vec<Vec<TestDocument>> = vec![dataset];
|
let mut groups: Vec<Vec<TestDocument>> = vec![dataset];
|
||||||
|
|
||||||
@ -112,11 +105,11 @@ pub fn expected_order(criteria: &[Criterion], autorize_typo: bool, optional_word
|
|||||||
groups = std::mem::take(&mut new_groups);
|
groups = std::mem::take(&mut new_groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
if autorize_typo && optional_words {
|
if authorize_typo && optional_words {
|
||||||
groups.into_iter().flatten().collect()
|
groups.into_iter().flatten().collect()
|
||||||
} else if optional_words {
|
} else if optional_words {
|
||||||
groups.into_iter().flatten().filter(|d| d.typo_rank == 0).collect()
|
groups.into_iter().flatten().filter(|d| d.typo_rank == 0).collect()
|
||||||
} else if autorize_typo {
|
} else if authorize_typo {
|
||||||
groups.into_iter().flatten().filter(|d| d.word_rank == 0).collect()
|
groups.into_iter().flatten().filter(|d| d.word_rank == 0).collect()
|
||||||
} else {
|
} else {
|
||||||
groups.into_iter().flatten().filter(|d| d.word_rank == 0 && d.typo_rank == 0).collect()
|
groups.into_iter().flatten().filter(|d| d.word_rank == 0 && d.typo_rank == 0).collect()
|
||||||
|
@ -23,19 +23,17 @@ macro_rules! test_criterion {
|
|||||||
search.authorize_typos($authorize_typos);
|
search.authorize_typos($authorize_typos);
|
||||||
search.optional_words($optional_word);
|
search.optional_words($optional_word);
|
||||||
|
|
||||||
let SearchResult { matching_words: _matching_words, candidates: _candidates, documents_ids } = search.execute().unwrap();
|
let SearchResult { documents_ids, .. } = search.execute().unwrap();
|
||||||
|
|
||||||
let expected_external_ids: Vec<_> = search::expected_order(&criteria, $authorize_typos, $optional_word).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);
|
let documents_ids = search::internal_to_external_ids(&index, &documents_ids);
|
||||||
|
|
||||||
assert_eq!(documents_ids, expected_external_ids);
|
assert_eq!(documents_ids, expected_external_ids);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test_criterion!(none_allow_typo, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS);
|
test_criterion!(none_allow_typo, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS);
|
||||||
test_criterion!(none_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS);
|
test_criterion!(none_disallow_typo, DISALLOW_OPTIONAL_WORDS, DISALLOW_TYPOS);
|
||||||
test_criterion!(words_allow_typo, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, Words);
|
test_criterion!(words_allow_typo, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS, Words);
|
||||||
@ -61,6 +59,7 @@ fn criteria_mixup() {
|
|||||||
|
|
||||||
|
|
||||||
let criteria_mix = {
|
let criteria_mix = {
|
||||||
|
// Criterion doesn't implement Copy, we create a new Criterion using a closure
|
||||||
let desc = || Desc(S("asc_desc_rank"));
|
let desc = || Desc(S("asc_desc_rank"));
|
||||||
// all possible criteria order
|
// all possible criteria order
|
||||||
vec![
|
vec![
|
||||||
@ -199,12 +198,12 @@ fn criteria_mixup() {
|
|||||||
let mut search = Search::new(&mut rtxn, &index);
|
let mut search = Search::new(&mut rtxn, &index);
|
||||||
search.query(search::TEST_QUERY);
|
search.query(search::TEST_QUERY);
|
||||||
search.limit(EXTERNAL_DOCUMENTS_IDS.len());
|
search.limit(EXTERNAL_DOCUMENTS_IDS.len());
|
||||||
search.optional_words(true);
|
search.optional_words(ALLOW_OPTIONAL_WORDS);
|
||||||
search.authorize_typos(true);
|
search.authorize_typos(ALLOW_TYPOS);
|
||||||
|
|
||||||
let SearchResult { matching_words: _matching_words, candidates: _candidates, documents_ids } = search.execute().unwrap();
|
let SearchResult { documents_ids, .. } = search.execute().unwrap();
|
||||||
|
|
||||||
let expected_external_ids: Vec<_> = search::expected_order(&criteria, true, true).into_iter().map(|d| d.id).collect();
|
let expected_external_ids: Vec<_> = search::expected_order(&criteria, ALLOW_OPTIONAL_WORDS, ALLOW_TYPOS).into_iter().map(|d| d.id).collect();
|
||||||
let documents_ids = search::internal_to_external_ids(&index, &documents_ids);
|
let documents_ids = search::internal_to_external_ids(&index, &documents_ids);
|
||||||
|
|
||||||
assert_eq!(documents_ids, expected_external_ids);
|
assert_eq!(documents_ids, expected_external_ids);
|
||||||
|
Loading…
Reference in New Issue
Block a user