mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-21 12:16:26 +00:00
Add more search tests
This commit is contained in:
68
milli/src/search/new/tests/proximity_typo.rs
Normal file
68
milli/src/search/new/tests/proximity_typo.rs
Normal file
@ -0,0 +1,68 @@
|
||||
/*!
|
||||
This module tests the interactions between the proximity and typo ranking rules.
|
||||
|
||||
The proximity ranking rule should transform the query graph such that it
|
||||
only contains the word pairs that it used to compute its bucket.
|
||||
*/
|
||||
|
||||
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!["text".to_owned()]);
|
||||
s.set_criteria(vec![Criterion::Words, Criterion::Proximity, Criterion::Typo]);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
index
|
||||
.add_documents(documents!([
|
||||
// Basic trap.
|
||||
//
|
||||
// We have one document with the perfect word pair: `sommer - holiday`
|
||||
// and another with the perfect word pair: `sommer holidty`.
|
||||
//
|
||||
// The proximity ranking rule will put them both in the same bucket, and it
|
||||
// should minify the query graph to make it represent:
|
||||
// EITHER:
|
||||
// sommer + holiday
|
||||
// OR:
|
||||
// sommer + holidty
|
||||
//
|
||||
// Such that the child typo ranking rule does not find any match
|
||||
// for its zero-typo bucket `summer + holiday`, even though both documents
|
||||
// contain these two exact words.
|
||||
{
|
||||
"id": 0,
|
||||
"text": "summer. holiday. sommer holidty"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"text": "summer. holiday. sommer holiday"
|
||||
},
|
||||
|
||||
]))
|
||||
.unwrap();
|
||||
index
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trap_basic() {
|
||||
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("summer holiday");
|
||||
let SearchResult { documents_ids, .. } = s.execute().unwrap();
|
||||
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[1, 0, 3, 2]");
|
||||
let texts = collect_field_values(&index, &txn, "text", &documents_ids);
|
||||
insta::assert_debug_snapshot!(texts, @r###"
|
||||
"###);
|
||||
}
|
Reference in New Issue
Block a user