mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-30 00:34:26 +01:00
Change consecutive phrase search grouping logic
Co-authored-by: ManyTheFish <many@meilisearch.com>
This commit is contained in:
parent
752d031010
commit
d35afa0cf5
@ -4,6 +4,7 @@ use std::mem::take;
|
|||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use roaring::RoaringBitmap;
|
use roaring::RoaringBitmap;
|
||||||
|
use slice_group_by::GroupBy;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
query_docids, query_pair_proximity_docids, resolve_phrase, resolve_query_tree, Context,
|
query_docids, query_pair_proximity_docids, resolve_phrase, resolve_query_tree, Context,
|
||||||
@ -478,29 +479,30 @@ fn resolve_plane_sweep_candidates(
|
|||||||
}
|
}
|
||||||
Phrase(words) => {
|
Phrase(words) => {
|
||||||
let mut groups_positions = Vec::with_capacity(words.len());
|
let mut groups_positions = Vec::with_capacity(words.len());
|
||||||
let mut consecutive = true;
|
|
||||||
let mut was_last_word_a_stop_word = false;
|
// group stop_words together.
|
||||||
for word in words.iter() {
|
for words in words.linear_group_by_key(Option::is_none) {
|
||||||
if let Some(word) = word {
|
// skip if it's a group of stop words.
|
||||||
let positions = match words_positions.get(word) {
|
if matches!(words.first(), None | Some(None)) {
|
||||||
Some(positions) => positions.iter().map(|p| (p, 0, p)).collect(),
|
continue;
|
||||||
|
}
|
||||||
|
// make a consecutive plane-sweep on the subgroup of words.
|
||||||
|
let mut subgroup = Vec::with_capacity(words.len());
|
||||||
|
for word in words.into_iter().map(|w| w.as_deref().unwrap()) {
|
||||||
|
match words_positions.get(word) {
|
||||||
|
Some(positions) => {
|
||||||
|
subgroup.push(positions.iter().map(|p| (p, 0, p)).collect())
|
||||||
|
}
|
||||||
None => return Ok(vec![]),
|
None => return Ok(vec![]),
|
||||||
};
|
|
||||||
groups_positions.push(positions);
|
|
||||||
|
|
||||||
if was_last_word_a_stop_word {
|
|
||||||
consecutive = false;
|
|
||||||
}
|
|
||||||
was_last_word_a_stop_word = false;
|
|
||||||
} else {
|
|
||||||
if !was_last_word_a_stop_word {
|
|
||||||
consecutive = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
was_last_word_a_stop_word = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
plane_sweep(groups_positions, consecutive)?
|
groups_positions.push(plane_sweep(subgroup, true)?);
|
||||||
|
}
|
||||||
|
match groups_positions.len() {
|
||||||
|
0 => vec![],
|
||||||
|
1 => groups_positions.pop().unwrap(),
|
||||||
|
_ => plane_sweep(groups_positions, false)?,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Or(_, ops) => {
|
Or(_, ops) => {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user