mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-23 13:10:06 +01:00
Introduce customs updates
This commit is contained in:
parent
da6ab2753e
commit
02575a2ef6
@ -3,8 +3,10 @@ use std::convert::TryInto;
|
||||
|
||||
use meilidb_schema::Schema;
|
||||
use rkv::Value;
|
||||
use serde::de;
|
||||
use crate::{RankedMap, MResult};
|
||||
|
||||
const CUSTOMS_KEY: &str = "customs-key";
|
||||
const NUMBER_OF_DOCUMENTS_KEY: &str = "number-of-documents";
|
||||
const RANKED_MAP_KEY: &str = "ranked-map";
|
||||
const SCHEMA_KEY: &str = "schema";
|
||||
@ -63,7 +65,7 @@ impl Main {
|
||||
{
|
||||
match self.main.get(reader, SCHEMA_KEY)? {
|
||||
Some(Value::Blob(bytes)) => {
|
||||
let schema = bincode::deserialize_from(bytes.as_ref())?;
|
||||
let schema = bincode::deserialize_from(bytes)?;
|
||||
Ok(Some(schema))
|
||||
},
|
||||
Some(value) => panic!("invalid type {:?}", value),
|
||||
@ -151,4 +153,17 @@ impl Main {
|
||||
None => Ok(0),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn put_customs(&self, writer: &mut rkv::Writer, customs: &[u8]) -> MResult<()> {
|
||||
self.main.put(writer, CUSTOMS_KEY, &Value::Blob(customs))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn customs<'t>(&self, reader: &'t impl rkv::Readable) -> MResult<Option<&'t [u8]>> {
|
||||
match self.main.get(reader, CUSTOMS_KEY)? {
|
||||
Some(Value::Blob(bytes)) => Ok(Some(bytes)),
|
||||
Some(value) => panic!("invalid type {:?}", value),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ pub use self::updates_results::UpdatesResults;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use meilidb_schema::{Schema, SchemaAttr};
|
||||
use serde::de;
|
||||
use serde::{ser, de};
|
||||
use crate::criterion::Criteria;
|
||||
use crate::serde::Deserializer;
|
||||
use crate::{update, query_builder::QueryBuilder, DocumentId, MResult, Error};
|
||||
@ -109,10 +109,14 @@ impl Index {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn schema_update(&self, writer: &mut rkv::Writer, schema: Schema) -> MResult<()> {
|
||||
pub fn schema_update(&self, writer: &mut rkv::Writer, schema: Schema) -> MResult<u64> {
|
||||
let _ = self.updates_notifier.send(());
|
||||
update::push_schema_update(writer, self.updates, self.updates_results, schema)?;
|
||||
Ok(())
|
||||
update::push_schema_update(writer, self.updates, self.updates_results, schema)
|
||||
}
|
||||
|
||||
pub fn customs_update(&self, writer: &mut rkv::Writer, customs: Vec<u8>) -> MResult<u64> {
|
||||
let _ = self.updates_notifier.send(());
|
||||
update::push_customs_update(writer, self.updates, self.updates_results, customs)
|
||||
}
|
||||
|
||||
pub fn documents_addition<D>(&self) -> update::DocumentsAddition<D> {
|
||||
|
26
meilidb-core/src/update/customs_update.rs
Normal file
26
meilidb-core/src/update/customs_update.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use crate::{store, error::UnsupportedOperation, MResult};
|
||||
use crate::update::{Update, next_update_id};
|
||||
|
||||
pub fn apply_customs_update(
|
||||
writer: &mut rkv::Writer,
|
||||
main_store: store::Main,
|
||||
customs: &[u8],
|
||||
) -> MResult<()>
|
||||
{
|
||||
main_store.put_customs(writer, customs)
|
||||
}
|
||||
|
||||
pub fn push_customs_update(
|
||||
writer: &mut rkv::Writer,
|
||||
updates_store: store::Updates,
|
||||
updates_results_store: store::UpdatesResults,
|
||||
customs: Vec<u8>,
|
||||
) -> MResult<u64>
|
||||
{
|
||||
let last_update_id = next_update_id(writer, updates_store, updates_results_store)?;
|
||||
|
||||
let update = Update::Customs(customs);
|
||||
updates_store.put_update(writer, last_update_id, &update)?;
|
||||
|
||||
Ok(last_update_id)
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
mod customs_update;
|
||||
mod documents_addition;
|
||||
mod documents_deletion;
|
||||
mod schema_update;
|
||||
mod synonyms_addition;
|
||||
mod synonyms_deletion;
|
||||
|
||||
pub use self::customs_update::{apply_customs_update, push_customs_update};
|
||||
pub use self::documents_addition::{DocumentsAddition, apply_documents_addition};
|
||||
pub use self::documents_deletion::{DocumentsDeletion, apply_documents_deletion};
|
||||
pub use self::schema_update::{apply_schema_update, push_schema_update};
|
||||
@ -23,6 +25,7 @@ use meilidb_schema::Schema;
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum Update {
|
||||
Schema(Schema),
|
||||
Customs(Vec<u8>),
|
||||
DocumentsAddition(Vec<rmpv::Value>),
|
||||
DocumentsDeletion(Vec<DocumentId>),
|
||||
SynonymsAddition(BTreeMap<String, Vec<String>>),
|
||||
@ -32,6 +35,7 @@ pub enum Update {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum UpdateType {
|
||||
Schema { schema: Schema },
|
||||
Customs,
|
||||
DocumentsAddition { number: usize },
|
||||
DocumentsDeletion { number: usize },
|
||||
SynonymsAddition { number: usize },
|
||||
@ -112,6 +116,14 @@ pub fn update_task(writer: &mut rkv::Writer, index: store::Index) -> MResult<Opt
|
||||
|
||||
(update_type, result, start.elapsed())
|
||||
},
|
||||
Update::Customs(customs) => {
|
||||
let start = Instant::now();
|
||||
|
||||
let update_type = UpdateType::Customs;
|
||||
let result = apply_customs_update(writer, index.main, &customs);
|
||||
|
||||
(update_type, result, start.elapsed())
|
||||
}
|
||||
Update::DocumentsAddition(documents) => {
|
||||
let start = Instant::now();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user