mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-02 17:45:46 +01:00
96 lines
2.8 KiB
Rust
96 lines
2.8 KiB
Rust
use milli::update::{IndexerConfig, Settings};
|
|
use milli::{Criterion, Search};
|
|
use Criterion::*;
|
|
|
|
#[test]
|
|
fn test_typo_tolerance_one_typo() {
|
|
let criteria = [Typo];
|
|
let index = super::setup_search_index_with_criteria(&criteria);
|
|
|
|
// basic typo search with default typo settings
|
|
{
|
|
let txn = index.read_txn().unwrap();
|
|
|
|
let mut search = Search::new(&txn, &index);
|
|
search.query("zeal");
|
|
search.limit(10);
|
|
search.authorize_typos(true);
|
|
search.optional_words(true);
|
|
|
|
let result = search.execute().unwrap();
|
|
assert_eq!(result.documents_ids.len(), 1);
|
|
|
|
let mut search = Search::new(&txn, &index);
|
|
search.query("zean");
|
|
search.limit(10);
|
|
search.authorize_typos(true);
|
|
search.optional_words(true);
|
|
|
|
let result = search.execute().unwrap();
|
|
assert_eq!(result.documents_ids.len(), 0);
|
|
}
|
|
|
|
let mut txn = index.write_txn().unwrap();
|
|
|
|
let config = IndexerConfig::default();
|
|
let mut builder = Settings::new(&mut txn, &index, &config);
|
|
builder.set_min_word_len_one_typo(4);
|
|
builder.execute(|_| ()).unwrap();
|
|
|
|
// typo is now supported for 4 letters words
|
|
let mut search = Search::new(&txn, &index);
|
|
search.query("zean");
|
|
search.limit(10);
|
|
search.authorize_typos(true);
|
|
search.optional_words(true);
|
|
|
|
let result = search.execute().unwrap();
|
|
assert_eq!(result.documents_ids.len(), 1);
|
|
}
|
|
|
|
#[test]
|
|
fn test_typo_tolerance_two_typo() {
|
|
let criteria = [Typo];
|
|
let index = super::setup_search_index_with_criteria(&criteria);
|
|
|
|
// basic typo search with default typo settings
|
|
{
|
|
let txn = index.read_txn().unwrap();
|
|
|
|
let mut search = Search::new(&txn, &index);
|
|
search.query("zealand");
|
|
search.limit(10);
|
|
search.authorize_typos(true);
|
|
search.optional_words(true);
|
|
|
|
let result = search.execute().unwrap();
|
|
assert_eq!(result.documents_ids.len(), 1);
|
|
|
|
let mut search = Search::new(&txn, &index);
|
|
search.query("zealemd");
|
|
search.limit(10);
|
|
search.authorize_typos(true);
|
|
search.optional_words(true);
|
|
|
|
let result = search.execute().unwrap();
|
|
assert_eq!(result.documents_ids.len(), 0);
|
|
}
|
|
|
|
let mut txn = index.write_txn().unwrap();
|
|
|
|
let config = IndexerConfig::default();
|
|
let mut builder = Settings::new(&mut txn, &index, &config);
|
|
builder.set_min_word_len_two_typos(7);
|
|
builder.execute(|_| ()).unwrap();
|
|
|
|
// typo is now supported for 4 letters words
|
|
let mut search = Search::new(&txn, &index);
|
|
search.query("zealemd");
|
|
search.limit(10);
|
|
search.authorize_typos(true);
|
|
search.optional_words(true);
|
|
|
|
let result = search.execute().unwrap();
|
|
assert_eq!(result.documents_ids.len(), 1);
|
|
}
|