mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
Merge #4858
4858: also intersect the universe for searchOnAttributes r=irevoire a=dureuill # Pull Request ## Related issue Fixes #4857 ## What does this PR do? - intersect with the universe (which does not contain the filtered out ids) when looking up documents for words, even when using `searchOnAttributes` Co-authored-by: Louis Dureuil <louis@meilisearch.com>
This commit is contained in:
commit
b44e17c4c3
@ -110,18 +110,18 @@ impl<'ctx> DatabaseCache<'ctx> {
|
|||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_value_from_keys<'v, K1, KC, DC>(
|
fn get_value_from_keys<'v, K1, KC>(
|
||||||
txn: &'ctx RoTxn<'_>,
|
txn: &'ctx RoTxn<'_>,
|
||||||
cache_key: K1,
|
cache_key: K1,
|
||||||
db_keys: &'v [KC::EItem],
|
db_keys: &'v [KC::EItem],
|
||||||
cache: &mut FxHashMap<K1, Option<Cow<'ctx, [u8]>>>,
|
cache: &mut FxHashMap<K1, Option<Cow<'ctx, [u8]>>>,
|
||||||
db: Database<KC, Bytes>,
|
db: Database<KC, Bytes>,
|
||||||
|
universe: Option<&RoaringBitmap>,
|
||||||
merger: MergeFn,
|
merger: MergeFn,
|
||||||
) -> Result<Option<DC::DItem>>
|
) -> Result<Option<RoaringBitmap>>
|
||||||
where
|
where
|
||||||
K1: Copy + Eq + Hash,
|
K1: Copy + Eq + Hash,
|
||||||
KC: BytesEncode<'v>,
|
KC: BytesEncode<'v>,
|
||||||
DC: BytesDecodeOwned,
|
|
||||||
KC::EItem: Sized,
|
KC::EItem: Sized,
|
||||||
{
|
{
|
||||||
if let Entry::Vacant(entry) = cache.entry(cache_key) {
|
if let Entry::Vacant(entry) = cache.entry(cache_key) {
|
||||||
@ -146,16 +146,22 @@ impl<'ctx> DatabaseCache<'ctx> {
|
|||||||
entry.insert(bitmap_ptr);
|
entry.insert(bitmap_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
match cache.get(&cache_key).unwrap() {
|
let bitmap_bytes = match cache.get(&cache_key).unwrap() {
|
||||||
Some(Cow::Borrowed(bytes)) => DC::bytes_decode_owned(bytes)
|
Some(Cow::Borrowed(bytes)) => bytes,
|
||||||
|
Some(Cow::Owned(bytes)) => bytes.as_slice(),
|
||||||
|
None => return Ok(None),
|
||||||
|
};
|
||||||
|
|
||||||
|
match (bitmap_bytes, universe) {
|
||||||
|
(bytes, Some(universe)) => {
|
||||||
|
CboRoaringBitmapCodec::intersection_with_serialized(bytes, universe)
|
||||||
|
.map(Some)
|
||||||
|
.map_err(Into::into)
|
||||||
|
}
|
||||||
|
(bytes, None) => CboRoaringBitmapCodec::bytes_decode_owned(bytes)
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(heed::Error::Decoding)
|
.map_err(heed::Error::Decoding)
|
||||||
.map_err(Into::into),
|
.map_err(Into::into),
|
||||||
Some(Cow::Owned(bytes)) => DC::bytes_decode_owned(bytes)
|
|
||||||
.map(Some)
|
|
||||||
.map_err(heed::Error::Decoding)
|
|
||||||
.map_err(Into::into),
|
|
||||||
None => Ok(None),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,12 +213,13 @@ impl<'ctx> SearchContext<'ctx> {
|
|||||||
let keys: Vec<_> =
|
let keys: Vec<_> =
|
||||||
restricted_fids.tolerant.iter().map(|(fid, _)| (interned, *fid)).collect();
|
restricted_fids.tolerant.iter().map(|(fid, _)| (interned, *fid)).collect();
|
||||||
|
|
||||||
DatabaseCache::get_value_from_keys::<_, _, CboRoaringBitmapCodec>(
|
DatabaseCache::get_value_from_keys::<_, _>(
|
||||||
self.txn,
|
self.txn,
|
||||||
word,
|
word,
|
||||||
&keys[..],
|
&keys[..],
|
||||||
&mut self.db_cache.word_docids,
|
&mut self.db_cache.word_docids,
|
||||||
self.index.word_fid_docids.remap_data_type::<Bytes>(),
|
self.index.word_fid_docids.remap_data_type::<Bytes>(),
|
||||||
|
universe,
|
||||||
merge_cbo_roaring_bitmaps,
|
merge_cbo_roaring_bitmaps,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -238,12 +245,13 @@ impl<'ctx> SearchContext<'ctx> {
|
|||||||
let keys: Vec<_> =
|
let keys: Vec<_> =
|
||||||
restricted_fids.exact.iter().map(|(fid, _)| (interned, *fid)).collect();
|
restricted_fids.exact.iter().map(|(fid, _)| (interned, *fid)).collect();
|
||||||
|
|
||||||
DatabaseCache::get_value_from_keys::<_, _, CboRoaringBitmapCodec>(
|
DatabaseCache::get_value_from_keys::<_, _>(
|
||||||
self.txn,
|
self.txn,
|
||||||
word,
|
word,
|
||||||
&keys[..],
|
&keys[..],
|
||||||
&mut self.db_cache.exact_word_docids,
|
&mut self.db_cache.exact_word_docids,
|
||||||
self.index.word_fid_docids.remap_data_type::<Bytes>(),
|
self.index.word_fid_docids.remap_data_type::<Bytes>(),
|
||||||
|
universe,
|
||||||
merge_cbo_roaring_bitmaps,
|
merge_cbo_roaring_bitmaps,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -294,12 +302,13 @@ impl<'ctx> SearchContext<'ctx> {
|
|||||||
let keys: Vec<_> =
|
let keys: Vec<_> =
|
||||||
restricted_fids.tolerant.iter().map(|(fid, _)| (interned, *fid)).collect();
|
restricted_fids.tolerant.iter().map(|(fid, _)| (interned, *fid)).collect();
|
||||||
|
|
||||||
DatabaseCache::get_value_from_keys::<_, _, CboRoaringBitmapCodec>(
|
DatabaseCache::get_value_from_keys::<_, _>(
|
||||||
self.txn,
|
self.txn,
|
||||||
prefix,
|
prefix,
|
||||||
&keys[..],
|
&keys[..],
|
||||||
&mut self.db_cache.word_prefix_docids,
|
&mut self.db_cache.word_prefix_docids,
|
||||||
self.index.word_prefix_fid_docids.remap_data_type::<Bytes>(),
|
self.index.word_prefix_fid_docids.remap_data_type::<Bytes>(),
|
||||||
|
universe,
|
||||||
merge_cbo_roaring_bitmaps,
|
merge_cbo_roaring_bitmaps,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -325,12 +334,13 @@ impl<'ctx> SearchContext<'ctx> {
|
|||||||
let keys: Vec<_> =
|
let keys: Vec<_> =
|
||||||
restricted_fids.exact.iter().map(|(fid, _)| (interned, *fid)).collect();
|
restricted_fids.exact.iter().map(|(fid, _)| (interned, *fid)).collect();
|
||||||
|
|
||||||
DatabaseCache::get_value_from_keys::<_, _, CboRoaringBitmapCodec>(
|
DatabaseCache::get_value_from_keys::<_, _>(
|
||||||
self.txn,
|
self.txn,
|
||||||
prefix,
|
prefix,
|
||||||
&keys[..],
|
&keys[..],
|
||||||
&mut self.db_cache.exact_word_prefix_docids,
|
&mut self.db_cache.exact_word_prefix_docids,
|
||||||
self.index.word_prefix_fid_docids.remap_data_type::<Bytes>(),
|
self.index.word_prefix_fid_docids.remap_data_type::<Bytes>(),
|
||||||
|
universe,
|
||||||
merge_cbo_roaring_bitmaps,
|
merge_cbo_roaring_bitmaps,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user