2022-10-13 15:43:40 +02:00
|
|
|
use milli::update::{IndexerConfig, Settings};
|
2022-10-20 15:11:37 +02:00
|
|
|
use milli::{Criterion, Index, Search, TermsMatchingStrategy};
|
2022-10-13 15:43:40 +02:00
|
|
|
|
2022-10-20 15:38:21 +02:00
|
|
|
use crate::search::Criterion::{Attribute, Exactness, Proximity};
|
|
|
|
|
2022-10-13 15:43:40 +02:00
|
|
|
fn set_stop_words(index: &Index, stop_words: &[&str]) {
|
|
|
|
let mut wtxn = index.write_txn().unwrap();
|
|
|
|
let config = IndexerConfig::default();
|
|
|
|
|
2023-01-17 18:01:26 +01:00
|
|
|
let mut builder = Settings::new(&mut wtxn, index, &config);
|
|
|
|
let stop_words = stop_words.iter().map(|s| s.to_string()).collect();
|
2022-10-13 15:43:40 +02:00
|
|
|
builder.set_stop_words(stop_words);
|
2022-10-26 19:37:20 +02:00
|
|
|
builder.execute(|_| (), || false).unwrap();
|
2022-10-13 15:43:40 +02:00
|
|
|
wtxn.commit().unwrap();
|
|
|
|
}
|
|
|
|
|
2022-10-20 15:11:37 +02:00
|
|
|
fn test_phrase_search_with_stop_words_given_criteria(criteria: &[Criterion]) {
|
2023-01-17 18:01:26 +01:00
|
|
|
let index = super::setup_search_index_with_criteria(criteria);
|
2022-10-13 15:43:40 +02:00
|
|
|
|
|
|
|
// Add stop_words
|
|
|
|
set_stop_words(&index, &["a", "an", "the", "of"]);
|
|
|
|
|
|
|
|
// Phrase search containing stop words
|
|
|
|
let txn = index.read_txn().unwrap();
|
|
|
|
|
|
|
|
let mut search = Search::new(&txn, &index);
|
|
|
|
search.query("\"the use of force\"");
|
|
|
|
search.limit(10);
|
|
|
|
search.terms_matching_strategy(TermsMatchingStrategy::All);
|
|
|
|
|
|
|
|
let result = search.execute().unwrap();
|
|
|
|
// 1 document should match
|
|
|
|
assert_eq!(result.documents_ids.len(), 1);
|
|
|
|
}
|
2022-10-20 15:11:37 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_phrase_search_with_stop_words_no_criteria() {
|
|
|
|
let criteria = [];
|
|
|
|
test_phrase_search_with_stop_words_given_criteria(&criteria);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_phrase_search_with_stop_words_all_criteria() {
|
|
|
|
let criteria = [Proximity, Attribute, Exactness];
|
|
|
|
test_phrase_search_with_stop_words_given_criteria(&criteria);
|
|
|
|
}
|