mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-28 01:01:00 +00:00
add test for exact words
This commit is contained in:
@ -584,6 +584,8 @@ mod test {
|
||||
struct TestContext {
|
||||
synonyms: HashMap<Vec<String>, Vec<Vec<String>>>,
|
||||
postings: HashMap<String, RoaringBitmap>,
|
||||
// Raw bytes for the exact word fst Set
|
||||
exact_words: Vec<u8>,
|
||||
}
|
||||
|
||||
impl TestContext {
|
||||
@ -620,9 +622,7 @@ mod test {
|
||||
}
|
||||
|
||||
fn exact_words(&self) -> crate::Result<fst::Set<Cow<[u8]>>> {
|
||||
let builder = fst::SetBuilder::new(Vec::new()).unwrap();
|
||||
let data = builder.into_inner().unwrap();
|
||||
Ok(fst::Set::new(Cow::Owned(data)).unwrap())
|
||||
Ok(fst::Set::new(Cow::Borrowed(self.exact_words.as_slice())).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@ -640,6 +640,8 @@ mod test {
|
||||
RoaringBitmap::from_sorted_iter(values.into_iter()).unwrap()
|
||||
}
|
||||
|
||||
let exact_words = fst::SetBuilder::new(Vec::new()).unwrap().into_inner().unwrap();
|
||||
|
||||
TestContext {
|
||||
synonyms: hashmap! {
|
||||
vec![String::from("hello")] => vec![
|
||||
@ -679,6 +681,7 @@ mod test {
|
||||
String::from("good") => random_postings(rng, 1250),
|
||||
String::from("morning") => random_postings(rng, 125),
|
||||
},
|
||||
exact_words,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1263,4 +1266,20 @@ mod test {
|
||||
QueryKind::Tolerant { typo: 2, word: "verylongword".to_string() }
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn disable_typo_on_word() {
|
||||
let query = "goodbye";
|
||||
let analyzer = Analyzer::new(AnalyzerConfig::<Vec<u8>>::default());
|
||||
let result = analyzer.analyze(query);
|
||||
|
||||
let tokens = result.tokens();
|
||||
let exact_words = fst::Set::from_iter(Some("goodbye")).unwrap().into_fst().into_inner();
|
||||
let context = TestContext { exact_words, ..Default::default() };
|
||||
let (query_tree, _) = context.build(false, true, Some(2), tokens).unwrap().unwrap();
|
||||
|
||||
assert!(matches!(
|
||||
query_tree,
|
||||
Operation::Query(Query { prefix: true, kind: QueryKind::Exact { .. } })
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user