mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Add a database containing the docids where each field exists
This commit is contained in:
parent
5704235521
commit
453d593ce8
10 changed files with 350 additions and 22 deletions
|
@ -25,3 +25,43 @@ pub fn try_split_at(slice: &[u8], mid: usize) -> Option<(&[u8], &[u8])> {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
use crate::{try_split_array_at, DocumentId, FieldId};
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
|
||||
pub struct FieldIdCodec;
|
||||
|
||||
impl<'a> heed::BytesDecode<'a> for FieldIdCodec {
|
||||
type DItem = FieldId;
|
||||
|
||||
fn bytes_decode(bytes: &'a [u8]) -> Option<Self::DItem> {
|
||||
let (field_id_bytes, _) = try_split_array_at(bytes)?;
|
||||
let field_id = u16::from_be_bytes(field_id_bytes);
|
||||
Some(field_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> heed::BytesEncode<'a> for FieldIdCodec {
|
||||
type EItem = FieldId;
|
||||
|
||||
fn bytes_encode(field_id: &Self::EItem) -> Option<Cow<[u8]>> {
|
||||
Some(Cow::Owned(field_id.to_be_bytes().to_vec()))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FieldIdDocIdCodec;
|
||||
|
||||
impl<'a> heed::BytesDecode<'a> for FieldIdDocIdCodec {
|
||||
type DItem = (FieldId, DocumentId);
|
||||
|
||||
fn bytes_decode(bytes: &'a [u8]) -> Option<Self::DItem> {
|
||||
let (field_id_bytes, bytes) = try_split_array_at(bytes)?;
|
||||
let field_id = u16::from_be_bytes(field_id_bytes);
|
||||
|
||||
let document_id_bytes = bytes[..4].try_into().ok()?;
|
||||
let document_id = u32::from_be_bytes(document_id_bytes);
|
||||
|
||||
Some((field_id, document_id))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue