mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-24 05:36:28 +00:00
Introduce the MResult type
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
use rkv::Value;
|
||||
use crate::DocumentId;
|
||||
use crate::{DocumentId, MResult};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct DocsWords {
|
||||
@ -34,14 +34,14 @@ impl DocsWords {
|
||||
&self,
|
||||
reader: &T,
|
||||
document_id: DocumentId,
|
||||
) -> Result<Option<fst::Set>, rkv::StoreError>
|
||||
) -> MResult<Option<fst::Set>>
|
||||
{
|
||||
let document_id_bytes = document_id.0.to_be_bytes();
|
||||
match self.docs_words.get(reader, document_id_bytes)? {
|
||||
Some(Value::Blob(bytes)) => {
|
||||
let len = bytes.len();
|
||||
let bytes = Arc::from(bytes);
|
||||
let fst = fst::raw::Fst::from_shared_bytes(bytes, 0, len).unwrap();
|
||||
let fst = fst::raw::Fst::from_shared_bytes(bytes, 0, len)?;
|
||||
Ok(Some(fst::Set::from(fst)))
|
||||
},
|
||||
Some(value) => panic!("invalid type {:?}", value),
|
||||
|
@ -103,8 +103,8 @@ impl<'r, T: rkv::Readable + 'r> Iterator for DocumentFieldsIter<'r, T> {
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.iter.next() {
|
||||
Some(Ok((key, Some(rkv::Value::Blob(bytes))))) => {
|
||||
let bytes = key.get(8..8+2).unwrap();
|
||||
let array = TryFrom::try_from(bytes).unwrap();
|
||||
let key_bytes = key.get(8..8+2).unwrap();
|
||||
let array = TryFrom::try_from(key_bytes).unwrap();
|
||||
let attr = u16::from_be_bytes(array);
|
||||
let attr = SchemaAttr::new(attr);
|
||||
Some(Ok((attr, bytes)))
|
||||
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||
use std::convert::TryInto;
|
||||
|
||||
use rkv::Value;
|
||||
use crate::RankedMap;
|
||||
use crate::{RankedMap, MResult};
|
||||
|
||||
const NUMBER_OF_DOCUMENTS_KEY: &str = "number-of-documents";
|
||||
const RANKED_MAP_KEY: &str = "ranked-map";
|
||||
@ -29,13 +29,13 @@ impl Main {
|
||||
pub fn words_fst<T: rkv::Readable>(
|
||||
&self,
|
||||
reader: &T,
|
||||
) -> Result<Option<fst::Set>, rkv::StoreError>
|
||||
) -> MResult<Option<fst::Set>>
|
||||
{
|
||||
match self.main.get(reader, WORDS_KEY)? {
|
||||
Some(Value::Blob(bytes)) => {
|
||||
let len = bytes.len();
|
||||
let bytes = Arc::from(bytes);
|
||||
let fst = fst::raw::Fst::from_shared_bytes(bytes, 0, len).unwrap();
|
||||
let fst = fst::raw::Fst::from_shared_bytes(bytes, 0, len)?;
|
||||
Ok(Some(fst::Set::from(fst)))
|
||||
},
|
||||
Some(value) => panic!("invalid type {:?}", value),
|
||||
@ -47,22 +47,23 @@ impl Main {
|
||||
&self,
|
||||
writer: &mut rkv::Writer,
|
||||
ranked_map: &RankedMap,
|
||||
) -> Result<(), rkv::StoreError>
|
||||
) -> MResult<()>
|
||||
{
|
||||
let mut bytes = Vec::new();
|
||||
ranked_map.write_to_bin(&mut bytes).unwrap();
|
||||
ranked_map.write_to_bin(&mut bytes)?;
|
||||
let blob = Value::Blob(&bytes[..]);
|
||||
self.main.put(writer, RANKED_MAP_KEY, &blob)
|
||||
self.main.put(writer, RANKED_MAP_KEY, &blob)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn ranked_map<T: rkv::Readable>(
|
||||
&self,
|
||||
reader: &T,
|
||||
) -> Result<Option<RankedMap>, rkv::StoreError>
|
||||
) -> MResult<Option<RankedMap>>
|
||||
{
|
||||
match self.main.get(reader, RANKED_MAP_KEY)? {
|
||||
Some(Value::Blob(bytes)) => {
|
||||
let ranked_map = RankedMap::read_from_bin(bytes).unwrap();
|
||||
let ranked_map = RankedMap::read_from_bin(bytes)?;
|
||||
Ok(Some(ranked_map))
|
||||
},
|
||||
Some(value) => panic!("invalid type {:?}", value),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::convert::TryInto;
|
||||
use rkv::Value;
|
||||
use crate::update::Update;
|
||||
use crate::{update::Update, MResult};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Updates {
|
||||
@ -47,13 +47,13 @@ impl Updates {
|
||||
&self,
|
||||
writer: &mut rkv::Writer,
|
||||
update: &Update,
|
||||
) -> Result<u64, rkv::StoreError>
|
||||
) -> MResult<u64>
|
||||
{
|
||||
let last_update_id = self.last_update_id(writer)?;
|
||||
let last_update_id = last_update_id.map_or(0, |(n, _)| n + 1);
|
||||
let last_update_id_bytes = last_update_id.to_be_bytes();
|
||||
|
||||
let update = rmp_serde::to_vec_named(&update).unwrap();
|
||||
let update = rmp_serde::to_vec_named(&update)?;
|
||||
let blob = Value::Blob(&update);
|
||||
self.updates.put(writer, last_update_id_bytes, &blob)?;
|
||||
|
||||
@ -63,7 +63,7 @@ impl Updates {
|
||||
pub fn pop_back(
|
||||
&self,
|
||||
writer: &mut rkv::Writer,
|
||||
) -> Result<Option<(u64, Update)>, rkv::StoreError>
|
||||
) -> MResult<Option<(u64, Update)>>
|
||||
{
|
||||
let (last_id, last_data) = match self.last_update_id(writer)? {
|
||||
Some(entry) => entry,
|
||||
@ -72,7 +72,7 @@ impl Updates {
|
||||
|
||||
match last_data {
|
||||
Some(Value::Blob(bytes)) => {
|
||||
let update = rmp_serde::from_read_ref(&bytes).unwrap();
|
||||
let update = rmp_serde::from_read_ref(&bytes)?;
|
||||
Ok(Some((last_id, update)))
|
||||
},
|
||||
Some(value) => panic!("invalid type {:?}", value),
|
||||
|
@ -1,5 +1,5 @@
|
||||
use rkv::Value;
|
||||
use crate::update::UpdateResult;
|
||||
use crate::{update::UpdateResult, MResult};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct UpdatesResults {
|
||||
@ -12,25 +12,26 @@ impl UpdatesResults {
|
||||
writer: &mut rkv::Writer,
|
||||
update_id: u64,
|
||||
update_result: &UpdateResult,
|
||||
) -> Result<(), rkv::StoreError>
|
||||
) -> MResult<()>
|
||||
{
|
||||
let update_id_bytes = update_id.to_be_bytes();
|
||||
let update_result = bincode::serialize(&update_result).unwrap();
|
||||
let update_result = bincode::serialize(&update_result)?;
|
||||
let blob = Value::Blob(&update_result);
|
||||
self.updates_results.put(writer, update_id_bytes, &blob)
|
||||
self.updates_results.put(writer, update_id_bytes, &blob)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_result<T: rkv::Readable>(
|
||||
&self,
|
||||
reader: &T,
|
||||
update_id: u64,
|
||||
) -> Result<Option<UpdateResult>, rkv::StoreError>
|
||||
) -> MResult<Option<UpdateResult>>
|
||||
{
|
||||
let update_id_bytes = update_id.to_be_bytes();
|
||||
|
||||
match self.updates_results.get(reader, update_id_bytes)? {
|
||||
Some(Value::Blob(bytes)) => {
|
||||
let update_result = bincode::deserialize(&bytes).unwrap();
|
||||
let update_result = bincode::deserialize(&bytes)?;
|
||||
Ok(Some(update_result))
|
||||
},
|
||||
Some(value) => panic!("invalid type {:?}", value),
|
||||
|
Reference in New Issue
Block a user