mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-11-04 01:46:28 +00:00 
			
		
		
		
	add typo integration tests
This commit is contained in:
		@@ -16,6 +16,7 @@ mod distinct;
 | 
			
		||||
mod filters;
 | 
			
		||||
mod query_criteria;
 | 
			
		||||
mod sort;
 | 
			
		||||
mod typo_tolerance;
 | 
			
		||||
 | 
			
		||||
pub const TEST_QUERY: &'static str = "hello world america";
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										97
									
								
								milli/tests/search/typo_tolerance.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								milli/tests/search/typo_tolerance.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,97 @@
 | 
			
		||||
use milli::{
 | 
			
		||||
    update::{IndexerConfig, Settings},
 | 
			
		||||
    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);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user