mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
Remove unused heed codec files
This commit is contained in:
parent
5a904cf29d
commit
6cc91824c1
@ -1,114 +0,0 @@
|
|||||||
use std::borrow::Cow;
|
|
||||||
use std::convert::TryInto;
|
|
||||||
use std::{marker, str};
|
|
||||||
|
|
||||||
use super::try_split_at;
|
|
||||||
|
|
||||||
/// A codec that optionally encodes two strings in front of the value.
|
|
||||||
///
|
|
||||||
/// The usecase is for the facet string levels algorithm where we must
|
|
||||||
/// know the origin of a group, the group left and right bounds are stored
|
|
||||||
/// in the value to not break the lexicographical ordering of the LMDB keys.
|
|
||||||
pub struct FacetStringZeroBoundsValueCodec<C>(marker::PhantomData<C>);
|
|
||||||
|
|
||||||
impl<'a, C> heed::BytesDecode<'a> for FacetStringZeroBoundsValueCodec<C>
|
|
||||||
where
|
|
||||||
C: heed::BytesDecode<'a>,
|
|
||||||
{
|
|
||||||
type DItem = (Option<(&'a str, &'a str)>, C::DItem);
|
|
||||||
|
|
||||||
fn bytes_decode(bytes: &'a [u8]) -> Option<Self::DItem> {
|
|
||||||
let (contains_bounds, bytes) = bytes.split_first()?;
|
|
||||||
|
|
||||||
if *contains_bounds != 0 {
|
|
||||||
let (left_len, bytes) = try_split_at(bytes, 2)?;
|
|
||||||
let (right_len, bytes) = try_split_at(bytes, 2)?;
|
|
||||||
|
|
||||||
let left_len = left_len.try_into().ok().map(u16::from_be_bytes)?;
|
|
||||||
let right_len = right_len.try_into().ok().map(u16::from_be_bytes)?;
|
|
||||||
|
|
||||||
let (left, bytes) = try_split_at(bytes, left_len as usize)?;
|
|
||||||
let (right, bytes) = try_split_at(bytes, right_len as usize)?;
|
|
||||||
|
|
||||||
let left = str::from_utf8(left).ok()?;
|
|
||||||
let right = str::from_utf8(right).ok()?;
|
|
||||||
|
|
||||||
C::bytes_decode(bytes).map(|item| (Some((left, right)), item))
|
|
||||||
} else {
|
|
||||||
C::bytes_decode(bytes).map(|item| (None, item))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, C> heed::BytesEncode<'a> for FacetStringZeroBoundsValueCodec<C>
|
|
||||||
where
|
|
||||||
C: heed::BytesEncode<'a>,
|
|
||||||
{
|
|
||||||
type EItem = (Option<(&'a str, &'a str)>, C::EItem);
|
|
||||||
|
|
||||||
fn bytes_encode((bounds, value): &'a Self::EItem) -> Option<Cow<[u8]>> {
|
|
||||||
let mut bytes = Vec::new();
|
|
||||||
|
|
||||||
match bounds {
|
|
||||||
Some((left, right)) => {
|
|
||||||
bytes.push(u8::max_value());
|
|
||||||
|
|
||||||
if left.is_empty() || right.is_empty() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let left_len: u16 = left.len().try_into().ok()?;
|
|
||||||
let right_len: u16 = right.len().try_into().ok()?;
|
|
||||||
|
|
||||||
bytes.extend_from_slice(&left_len.to_be_bytes());
|
|
||||||
bytes.extend_from_slice(&right_len.to_be_bytes());
|
|
||||||
|
|
||||||
bytes.extend_from_slice(left.as_bytes());
|
|
||||||
bytes.extend_from_slice(right.as_bytes());
|
|
||||||
|
|
||||||
let value_bytes = C::bytes_encode(&value)?;
|
|
||||||
bytes.extend_from_slice(&value_bytes[..]);
|
|
||||||
|
|
||||||
Some(Cow::Owned(bytes))
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
bytes.push(0);
|
|
||||||
let value_bytes = C::bytes_encode(&value)?;
|
|
||||||
bytes.extend_from_slice(&value_bytes[..]);
|
|
||||||
Some(Cow::Owned(bytes))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use heed::types::Unit;
|
|
||||||
use heed::{BytesDecode, BytesEncode};
|
|
||||||
use roaring::RoaringBitmap;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
use crate::CboRoaringBitmapCodec;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn deserialize_roaring_bitmaps() {
|
|
||||||
let bounds = Some(("abc", "def"));
|
|
||||||
let docids: RoaringBitmap = (0..100).chain(3500..4398).collect();
|
|
||||||
let key = (bounds, docids.clone());
|
|
||||||
let bytes =
|
|
||||||
FacetStringZeroBoundsValueCodec::<CboRoaringBitmapCodec>::bytes_encode(&key).unwrap();
|
|
||||||
let (out_bounds, out_docids) =
|
|
||||||
FacetStringZeroBoundsValueCodec::<CboRoaringBitmapCodec>::bytes_decode(&bytes).unwrap();
|
|
||||||
assert_eq!((out_bounds, out_docids), (bounds, docids));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn deserialize_unit() {
|
|
||||||
let bounds = Some(("abc", "def"));
|
|
||||||
let key = (bounds, ());
|
|
||||||
let bytes = FacetStringZeroBoundsValueCodec::<Unit>::bytes_encode(&key).unwrap();
|
|
||||||
let (out_bounds, out_unit) =
|
|
||||||
FacetStringZeroBoundsValueCodec::<Unit>::bytes_decode(&bytes).unwrap();
|
|
||||||
assert_eq!((out_bounds, out_unit), (bounds, ()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
use std::borrow::Cow;
|
|
||||||
use std::str;
|
|
||||||
|
|
||||||
use crate::{try_split_array_at, FieldId};
|
|
||||||
|
|
||||||
pub struct FacetValueStringCodec;
|
|
||||||
|
|
||||||
impl FacetValueStringCodec {
|
|
||||||
pub fn serialize_into(field_id: FieldId, value: &str, out: &mut Vec<u8>) {
|
|
||||||
out.reserve(value.len() + 2);
|
|
||||||
out.extend_from_slice(&field_id.to_be_bytes());
|
|
||||||
out.extend_from_slice(value.as_bytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> heed::BytesDecode<'a> for FacetValueStringCodec {
|
|
||||||
type DItem = (FieldId, &'a str);
|
|
||||||
|
|
||||||
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 value = str::from_utf8(bytes).ok()?;
|
|
||||||
Some((field_id, value))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> heed::BytesEncode<'a> for FacetValueStringCodec {
|
|
||||||
type EItem = (FieldId, &'a str);
|
|
||||||
|
|
||||||
fn bytes_encode((field_id, value): &Self::EItem) -> Option<Cow<[u8]>> {
|
|
||||||
let mut bytes = Vec::new();
|
|
||||||
FacetValueStringCodec::serialize_into(*field_id, value, &mut bytes);
|
|
||||||
Some(Cow::Owned(bytes))
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,7 @@
|
|||||||
// mod facet_level_value_u32_codec;
|
// mod facet_level_value_u32_codec;
|
||||||
// mod facet_string_level_zero_codec;
|
// mod facet_string_level_zero_codec;
|
||||||
// mod facet_string_level_zero_value_codec;
|
// mod facet_string_level_zero_value_codec;
|
||||||
mod facet_string_zero_bounds_value_codec;
|
// mod facet_string_zero_bounds_value_codec;
|
||||||
mod field_doc_id_facet_f64_codec;
|
mod field_doc_id_facet_f64_codec;
|
||||||
mod field_doc_id_facet_string_codec;
|
mod field_doc_id_facet_string_codec;
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ use heed::types::OwnedType;
|
|||||||
// pub use self::facet_string_level_zero_value_codec::{
|
// pub use self::facet_string_level_zero_value_codec::{
|
||||||
// decode_prefix_string, encode_prefix_string, FacetStringLevelZeroValueCodec,
|
// decode_prefix_string, encode_prefix_string, FacetStringLevelZeroValueCodec,
|
||||||
// };
|
// };
|
||||||
pub use self::facet_string_zero_bounds_value_codec::FacetStringZeroBoundsValueCodec;
|
// pub use self::facet_string_zero_bounds_value_codec::FacetStringZeroBoundsValueCodec;
|
||||||
pub use self::field_doc_id_facet_f64_codec::FieldDocIdFacetF64Codec;
|
pub use self::field_doc_id_facet_f64_codec::FieldDocIdFacetF64Codec;
|
||||||
pub use self::field_doc_id_facet_string_codec::FieldDocIdFacetStringCodec;
|
pub use self::field_doc_id_facet_string_codec::FieldDocIdFacetStringCodec;
|
||||||
use crate::BEU16;
|
use crate::BEU16;
|
||||||
|
@ -10,7 +10,7 @@ use time::OffsetDateTime;
|
|||||||
|
|
||||||
use super::ClearDocuments;
|
use super::ClearDocuments;
|
||||||
use crate::error::{InternalError, SerializationError, UserError};
|
use crate::error::{InternalError, SerializationError, UserError};
|
||||||
use crate::heed_codec::facet::FacetStringZeroBoundsValueCodec;
|
// use crate::heed_codec::facet::FacetStringZeroBoundsValueCodec;
|
||||||
use crate::heed_codec::CboRoaringBitmapCodec;
|
use crate::heed_codec::CboRoaringBitmapCodec;
|
||||||
use crate::index::{db_name, main_key};
|
use crate::index::{db_name, main_key};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
Loading…
Reference in New Issue
Block a user