mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 06:44:27 +01:00
Fix panic when phrase contains only one stop word and nothing else
This commit is contained in:
parent
bb9ce3c5c5
commit
2aa11afb87
@ -422,6 +422,11 @@ pub fn resolve_phrase(ctx: &dyn Context, phrase: &[Option<String>]) -> Result<Ro
|
|||||||
let mut candidates = RoaringBitmap::new();
|
let mut candidates = RoaringBitmap::new();
|
||||||
let mut first_iter = true;
|
let mut first_iter = true;
|
||||||
let winsize = phrase.len().min(3);
|
let winsize = phrase.len().min(3);
|
||||||
|
|
||||||
|
if phrase.is_empty() {
|
||||||
|
return Ok(candidates);
|
||||||
|
}
|
||||||
|
|
||||||
for win in phrase.windows(winsize) {
|
for win in phrase.windows(winsize) {
|
||||||
// Get all the documents with the matching distance for each word pairs.
|
// Get all the documents with the matching distance for each word pairs.
|
||||||
let mut bitmaps = Vec::with_capacity(winsize.pow(2));
|
let mut bitmaps = Vec::with_capacity(winsize.pow(2));
|
||||||
|
@ -32,4 +32,13 @@ fn test_phrase_search_with_stop_words() {
|
|||||||
let result = search.execute().unwrap();
|
let result = search.execute().unwrap();
|
||||||
// 1 document should match
|
// 1 document should match
|
||||||
assert_eq!(result.documents_ids.len(), 1);
|
assert_eq!(result.documents_ids.len(), 1);
|
||||||
|
|
||||||
|
// test for a single stop word only, no other search terms
|
||||||
|
let mut search = Search::new(&txn, &index);
|
||||||
|
search.query("\"the\"");
|
||||||
|
search.limit(10);
|
||||||
|
search.authorize_typos(false);
|
||||||
|
search.terms_matching_strategy(TermsMatchingStrategy::All);
|
||||||
|
let result = search.execute().unwrap();
|
||||||
|
assert_eq!(result.documents_ids.len(), 0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user