mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-30 08:44:27 +01:00
Get ride of rust messagepack (rmp)
This commit is contained in:
parent
81bf6d583d
commit
710ab2386c
@ -20,21 +20,12 @@ once_cell = "1.2.0"
|
|||||||
ordered-float = { version = "1.0.2", features = ["serde"] }
|
ordered-float = { version = "1.0.2", features = ["serde"] }
|
||||||
rkv = "0.10.2"
|
rkv = "0.10.2"
|
||||||
sdset = "0.3.2"
|
sdset = "0.3.2"
|
||||||
serde = { version = "1.0.99", features = ["derive"] }
|
serde = { version = "1.0.101", features = ["derive"] }
|
||||||
serde_json = "1.0.40"
|
serde_json = "1.0.41"
|
||||||
siphasher = "0.3.0"
|
siphasher = "0.3.0"
|
||||||
slice-group-by = "0.2.6"
|
slice-group-by = "0.2.6"
|
||||||
zerocopy = "0.2.8"
|
zerocopy = "0.2.8"
|
||||||
|
|
||||||
[dependencies.rmp-serde]
|
|
||||||
git = "https://github.com/3Hren/msgpack-rust.git"
|
|
||||||
rev = "40b3d48"
|
|
||||||
|
|
||||||
[dependencies.rmpv]
|
|
||||||
git = "https://github.com/3Hren/msgpack-rust.git"
|
|
||||||
rev = "40b3d48"
|
|
||||||
features = ["with-serde"]
|
|
||||||
|
|
||||||
[dependencies.levenshtein_automata]
|
[dependencies.levenshtein_automata]
|
||||||
git = "https://github.com/Kerollmops/levenshtein-automata.git"
|
git = "https://github.com/Kerollmops/levenshtein-automata.git"
|
||||||
branch = "arc-byte-slice"
|
branch = "arc-byte-slice"
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use std::{error, fmt, io};
|
use std::{error, fmt, io};
|
||||||
|
use serde_json::Error as SerdeJsonError;
|
||||||
use crate::serde::{SerializerError, DeserializerError};
|
use crate::serde::{SerializerError, DeserializerError};
|
||||||
|
|
||||||
pub type MResult<T> = Result<T, Error>;
|
pub type MResult<T> = Result<T, Error>;
|
||||||
@ -13,8 +14,7 @@ pub enum Error {
|
|||||||
MissingDocumentId,
|
MissingDocumentId,
|
||||||
Rkv(rkv::StoreError),
|
Rkv(rkv::StoreError),
|
||||||
Fst(fst::Error),
|
Fst(fst::Error),
|
||||||
RmpDecode(rmp_serde::decode::Error),
|
SerdeJson(SerdeJsonError),
|
||||||
RmpEncode(rmp_serde::encode::Error),
|
|
||||||
Bincode(bincode::Error),
|
Bincode(bincode::Error),
|
||||||
Serializer(SerializerError),
|
Serializer(SerializerError),
|
||||||
Deserializer(DeserializerError),
|
Deserializer(DeserializerError),
|
||||||
@ -39,15 +39,9 @@ impl From<fst::Error> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<rmp_serde::decode::Error> for Error {
|
impl From<SerdeJsonError> for Error {
|
||||||
fn from(error: rmp_serde::decode::Error) -> Error {
|
fn from(error: SerdeJsonError) -> Error {
|
||||||
Error::RmpDecode(error)
|
Error::SerdeJson(error)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<rmp_serde::encode::Error> for Error {
|
|
||||||
fn from(error: rmp_serde::encode::Error) -> Error {
|
|
||||||
Error::RmpEncode(error)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,8 +81,7 @@ impl fmt::Display for Error {
|
|||||||
MissingDocumentId => write!(f, "document id is missing"),
|
MissingDocumentId => write!(f, "document id is missing"),
|
||||||
Rkv(e) => write!(f, "rkv error; {}", e),
|
Rkv(e) => write!(f, "rkv error; {}", e),
|
||||||
Fst(e) => write!(f, "fst error; {}", e),
|
Fst(e) => write!(f, "fst error; {}", e),
|
||||||
RmpDecode(e) => write!(f, "rmp decode error; {}", e),
|
SerdeJson(e) => write!(f, "serde json error; {}", e),
|
||||||
RmpEncode(e) => write!(f, "rmp encode error; {}", e),
|
|
||||||
Bincode(e) => write!(f, "bincode error; {}", e),
|
Bincode(e) => write!(f, "bincode error; {}", e),
|
||||||
Serializer(e) => write!(f, "serializer error; {}", e),
|
Serializer(e) => write!(f, "serializer error; {}", e),
|
||||||
Deserializer(e) => write!(f, "deserializer error; {}", e),
|
Deserializer(e) => write!(f, "deserializer error; {}", e),
|
||||||
|
@ -3,8 +3,9 @@ use std::io::Cursor;
|
|||||||
use std::{fmt, error::Error};
|
use std::{fmt, error::Error};
|
||||||
|
|
||||||
use meilidb_schema::{Schema, SchemaAttr};
|
use meilidb_schema::{Schema, SchemaAttr};
|
||||||
use rmp_serde::decode::{Deserializer as RmpDeserializer, ReadReader};
|
use serde_json::Error as SerdeJsonError;
|
||||||
use rmp_serde::decode::{Error as RmpError};
|
use serde_json::Deserializer as SerdeJsonDeserializer;
|
||||||
|
use serde_json::de::IoRead as SerdeJsonIoRead;
|
||||||
use serde::{de, forward_to_deserialize_any};
|
use serde::{de, forward_to_deserialize_any};
|
||||||
|
|
||||||
use crate::store::DocumentsFields;
|
use crate::store::DocumentsFields;
|
||||||
@ -12,8 +13,8 @@ use crate::DocumentId;
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DeserializerError {
|
pub enum DeserializerError {
|
||||||
RmpError(RmpError),
|
SerdeJson(SerdeJsonError),
|
||||||
RkvError(rkv::StoreError),
|
Rkv(rkv::StoreError),
|
||||||
Custom(String),
|
Custom(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,8 +27,8 @@ impl de::Error for DeserializerError {
|
|||||||
impl fmt::Display for DeserializerError {
|
impl fmt::Display for DeserializerError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
DeserializerError::RmpError(e) => write!(f, "rmp serde related error: {}", e),
|
DeserializerError::SerdeJson(e) => write!(f, "serde json related error: {}", e),
|
||||||
DeserializerError::RkvError(e) => write!(f, "rkv related error: {}", e),
|
DeserializerError::Rkv(e) => write!(f, "rkv related error: {}", e),
|
||||||
DeserializerError::Custom(s) => f.write_str(s),
|
DeserializerError::Custom(s) => f.write_str(s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,15 +36,15 @@ impl fmt::Display for DeserializerError {
|
|||||||
|
|
||||||
impl Error for DeserializerError {}
|
impl Error for DeserializerError {}
|
||||||
|
|
||||||
impl From<RmpError> for DeserializerError {
|
impl From<SerdeJsonError> for DeserializerError {
|
||||||
fn from(error: RmpError) -> DeserializerError {
|
fn from(error: SerdeJsonError) -> DeserializerError {
|
||||||
DeserializerError::RmpError(error)
|
DeserializerError::SerdeJson(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<rkv::StoreError> for DeserializerError {
|
impl From<rkv::StoreError> for DeserializerError {
|
||||||
fn from(error: rkv::StoreError) -> DeserializerError {
|
fn from(error: rkv::StoreError) -> DeserializerError {
|
||||||
DeserializerError::RkvError(error)
|
DeserializerError::Rkv(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +89,12 @@ where R: rkv::Readable,
|
|||||||
let is_displayed = self.schema.props(attr).is_displayed();
|
let is_displayed = self.schema.props(attr).is_displayed();
|
||||||
if is_displayed && self.attributes.map_or(true, |f| f.contains(&attr)) {
|
if is_displayed && self.attributes.map_or(true, |f| f.contains(&attr)) {
|
||||||
let attribute_name = self.schema.attribute_name(attr);
|
let attribute_name = self.schema.attribute_name(attr);
|
||||||
Some((attribute_name, Value::new(value)))
|
|
||||||
|
let cursor = Cursor::new(value.to_owned());
|
||||||
|
let ioread = SerdeJsonIoRead::new(cursor);
|
||||||
|
let value = Value(SerdeJsonDeserializer::new(ioread));
|
||||||
|
|
||||||
|
Some((attribute_name, value))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -104,18 +110,9 @@ where R: rkv::Readable,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Value<A>(RmpDeserializer<ReadReader<Cursor<A>>>) where A: AsRef<[u8]>;
|
struct Value(SerdeJsonDeserializer<SerdeJsonIoRead<Cursor<Vec<u8>>>>);
|
||||||
|
|
||||||
impl<A> Value<A> where A: AsRef<[u8]>
|
impl<'de> de::IntoDeserializer<'de, SerdeJsonError> for Value {
|
||||||
{
|
|
||||||
fn new(value: A) -> Value<A> {
|
|
||||||
Value(RmpDeserializer::new(Cursor::new(value)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de, A> de::IntoDeserializer<'de, RmpError> for Value<A>
|
|
||||||
where A: AsRef<[u8]>,
|
|
||||||
{
|
|
||||||
type Deserializer = Self;
|
type Deserializer = Self;
|
||||||
|
|
||||||
fn into_deserializer(self) -> Self::Deserializer {
|
fn into_deserializer(self) -> Self::Deserializer {
|
||||||
@ -123,10 +120,8 @@ where A: AsRef<[u8]>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de, 'a, A> de::Deserializer<'de> for Value<A>
|
impl<'de> de::Deserializer<'de> for Value {
|
||||||
where A: AsRef<[u8]>,
|
type Error = SerdeJsonError;
|
||||||
{
|
|
||||||
type Error = RmpError;
|
|
||||||
|
|
||||||
fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where V: de::Visitor<'de>
|
where V: de::Visitor<'de>
|
||||||
|
@ -26,7 +26,6 @@ use std::collections::BTreeMap;
|
|||||||
use std::{fmt, error::Error};
|
use std::{fmt, error::Error};
|
||||||
|
|
||||||
use meilidb_schema::SchemaAttr;
|
use meilidb_schema::SchemaAttr;
|
||||||
use rmp_serde::encode::Error as RmpError;
|
|
||||||
use serde_json::Error as SerdeJsonError;
|
use serde_json::Error as SerdeJsonError;
|
||||||
use serde::ser;
|
use serde::ser;
|
||||||
|
|
||||||
@ -36,10 +35,9 @@ use crate::{DocumentId, ParseNumberError};
|
|||||||
pub enum SerializerError {
|
pub enum SerializerError {
|
||||||
DocumentIdNotFound,
|
DocumentIdNotFound,
|
||||||
InvalidDocumentIdType,
|
InvalidDocumentIdType,
|
||||||
RmpError(RmpError),
|
|
||||||
RkvError(rkv::StoreError),
|
RkvError(rkv::StoreError),
|
||||||
SerdeJsonError(SerdeJsonError),
|
SerdeJson(SerdeJsonError),
|
||||||
ParseNumberError(ParseNumberError),
|
ParseNumber(ParseNumberError),
|
||||||
UnserializableType { type_name: &'static str },
|
UnserializableType { type_name: &'static str },
|
||||||
UnindexableType { type_name: &'static str },
|
UnindexableType { type_name: &'static str },
|
||||||
UnrankableType { type_name: &'static str },
|
UnrankableType { type_name: &'static str },
|
||||||
@ -56,15 +54,14 @@ impl fmt::Display for SerializerError {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
SerializerError::DocumentIdNotFound => {
|
SerializerError::DocumentIdNotFound => {
|
||||||
write!(f, "serialized document does not have an id according to the schema")
|
f.write_str("serialized document does not have an id according to the schema")
|
||||||
},
|
},
|
||||||
SerializerError::InvalidDocumentIdType => {
|
SerializerError::InvalidDocumentIdType => {
|
||||||
write!(f, "document identifier can only be of type string or number")
|
f.write_str("document identifier can only be of type string or number")
|
||||||
},
|
},
|
||||||
SerializerError::RmpError(e) => write!(f, "rmp serde related error: {}", e),
|
|
||||||
SerializerError::RkvError(e) => write!(f, "rkv related error: {}", e),
|
SerializerError::RkvError(e) => write!(f, "rkv related error: {}", e),
|
||||||
SerializerError::SerdeJsonError(e) => write!(f, "serde json error: {}", e),
|
SerializerError::SerdeJson(e) => write!(f, "serde json error: {}", e),
|
||||||
SerializerError::ParseNumberError(e) => {
|
SerializerError::ParseNumber(e) => {
|
||||||
write!(f, "error while trying to parse a number: {}", e)
|
write!(f, "error while trying to parse a number: {}", e)
|
||||||
},
|
},
|
||||||
SerializerError::UnserializableType { type_name } => {
|
SerializerError::UnserializableType { type_name } => {
|
||||||
@ -89,15 +86,9 @@ impl From<String> for SerializerError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<RmpError> for SerializerError {
|
|
||||||
fn from(error: RmpError) -> SerializerError {
|
|
||||||
SerializerError::RmpError(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<SerdeJsonError> for SerializerError {
|
impl From<SerdeJsonError> for SerializerError {
|
||||||
fn from(error: SerdeJsonError) -> SerializerError {
|
fn from(error: SerdeJsonError) -> SerializerError {
|
||||||
SerializerError::SerdeJsonError(error)
|
SerializerError::SerdeJson(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +100,7 @@ impl From<rkv::StoreError> for SerializerError {
|
|||||||
|
|
||||||
impl From<ParseNumberError> for SerializerError {
|
impl From<ParseNumberError> for SerializerError {
|
||||||
fn from(error: ParseNumberError) -> SerializerError {
|
fn from(error: ParseNumberError) -> SerializerError {
|
||||||
SerializerError::ParseNumberError(error)
|
SerializerError::ParseNumber(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ where T: ser::Serialize,
|
|||||||
if let Some(attribute) = schema.attribute(key) {
|
if let Some(attribute) = schema.attribute(key) {
|
||||||
let props = schema.props(attribute);
|
let props = schema.props(attribute);
|
||||||
|
|
||||||
let serialized = rmp_serde::to_vec_named(value)?;
|
let serialized = serde_json::to_vec(value)?;
|
||||||
document_store.set_document_field(document_id, attribute, serialized);
|
document_store.set_document_field(document_id, attribute, serialized);
|
||||||
|
|
||||||
if props.is_indexed() {
|
if props.is_indexed() {
|
||||||
|
@ -104,7 +104,7 @@ impl Index {
|
|||||||
{
|
{
|
||||||
let bytes = self.documents_fields.document_attribute(reader, document_id, attribute)?;
|
let bytes = self.documents_fields.document_attribute(reader, document_id, attribute)?;
|
||||||
match bytes {
|
match bytes {
|
||||||
Some(bytes) => Ok(Some(rmp_serde::from_read_ref(bytes)?)),
|
Some(bytes) => Ok(Some(serde_json::from_slice(bytes)?)),
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ impl Updates {
|
|||||||
) -> MResult<()>
|
) -> MResult<()>
|
||||||
{
|
{
|
||||||
let update_id_bytes = update_id.to_be_bytes();
|
let update_id_bytes = update_id.to_be_bytes();
|
||||||
let update = rmp_serde::to_vec_named(&update)?;
|
let update = serde_json::to_vec(&update)?;
|
||||||
let blob = Value::Blob(&update);
|
let blob = Value::Blob(&update);
|
||||||
self.updates.put(writer, update_id_bytes, &blob)?;
|
self.updates.put(writer, update_id_bytes, &blob)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -86,8 +86,7 @@ impl Updates {
|
|||||||
|
|
||||||
match first_data {
|
match first_data {
|
||||||
Some(Value::Blob(bytes)) => {
|
Some(Value::Blob(bytes)) => {
|
||||||
let update = rmp_serde::from_read_ref(&bytes)?;
|
let update = serde_json::from_slice(&bytes)?;
|
||||||
|
|
||||||
// remove it from the database now
|
// remove it from the database now
|
||||||
let first_id_bytes = first_id.to_be_bytes();
|
let first_id_bytes = first_id.to_be_bytes();
|
||||||
self.updates.delete(writer, first_id_bytes)?;
|
self.updates.delete(writer, first_id_bytes)?;
|
||||||
|
@ -65,8 +65,8 @@ pub fn push_documents_addition<D: serde::Serialize>(
|
|||||||
{
|
{
|
||||||
let mut values = Vec::with_capacity(addition.len());
|
let mut values = Vec::with_capacity(addition.len());
|
||||||
for add in addition {
|
for add in addition {
|
||||||
let vec = rmp_serde::to_vec_named(&add)?;
|
let vec = serde_json::to_vec(&add)?;
|
||||||
let add = rmp_serde::from_read(&vec[..])?;
|
let add = serde_json::from_slice(&vec)?;
|
||||||
values.push(add);
|
values.push(add);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ pub fn apply_documents_addition(
|
|||||||
postings_lists_store: store::PostingsLists,
|
postings_lists_store: store::PostingsLists,
|
||||||
docs_words_store: store::DocsWords,
|
docs_words_store: store::DocsWords,
|
||||||
mut ranked_map: RankedMap,
|
mut ranked_map: RankedMap,
|
||||||
addition: Vec<rmpv::Value>,
|
addition: Vec<serde_json::Value>,
|
||||||
) -> MResult<()>
|
) -> MResult<()>
|
||||||
{
|
{
|
||||||
let mut document_ids = HashSet::new();
|
let mut document_ids = HashSet::new();
|
||||||
|
@ -26,7 +26,7 @@ use meilidb_schema::Schema;
|
|||||||
pub enum Update {
|
pub enum Update {
|
||||||
Schema(Schema),
|
Schema(Schema),
|
||||||
Customs(Vec<u8>),
|
Customs(Vec<u8>),
|
||||||
DocumentsAddition(Vec<rmpv::Value>),
|
DocumentsAddition(Vec<serde_json::Value>),
|
||||||
DocumentsDeletion(Vec<DocumentId>),
|
DocumentsDeletion(Vec<DocumentId>),
|
||||||
SynonymsAddition(BTreeMap<String, Vec<String>>),
|
SynonymsAddition(BTreeMap<String, Vec<String>>),
|
||||||
SynonymsDeletion(BTreeMap<String, Option<Vec<String>>>),
|
SynonymsDeletion(BTreeMap<String, Option<Vec<String>>>),
|
||||||
|
Loading…
Reference in New Issue
Block a user