mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 05:14:27 +01:00
Merge pull request #214 from meilisearch/add-customs-updates
Add customs updates
This commit is contained in:
commit
81bf6d583d
@ -3,8 +3,10 @@ use std::convert::TryInto;
|
|||||||
|
|
||||||
use meilidb_schema::Schema;
|
use meilidb_schema::Schema;
|
||||||
use rkv::Value;
|
use rkv::Value;
|
||||||
|
use serde::de;
|
||||||
use crate::{RankedMap, MResult};
|
use crate::{RankedMap, MResult};
|
||||||
|
|
||||||
|
const CUSTOMS_KEY: &str = "customs-key";
|
||||||
const NUMBER_OF_DOCUMENTS_KEY: &str = "number-of-documents";
|
const NUMBER_OF_DOCUMENTS_KEY: &str = "number-of-documents";
|
||||||
const RANKED_MAP_KEY: &str = "ranked-map";
|
const RANKED_MAP_KEY: &str = "ranked-map";
|
||||||
const SCHEMA_KEY: &str = "schema";
|
const SCHEMA_KEY: &str = "schema";
|
||||||
@ -63,7 +65,7 @@ impl Main {
|
|||||||
{
|
{
|
||||||
match self.main.get(reader, SCHEMA_KEY)? {
|
match self.main.get(reader, SCHEMA_KEY)? {
|
||||||
Some(Value::Blob(bytes)) => {
|
Some(Value::Blob(bytes)) => {
|
||||||
let schema = bincode::deserialize_from(bytes.as_ref())?;
|
let schema = bincode::deserialize_from(bytes)?;
|
||||||
Ok(Some(schema))
|
Ok(Some(schema))
|
||||||
},
|
},
|
||||||
Some(value) => panic!("invalid type {:?}", value),
|
Some(value) => panic!("invalid type {:?}", value),
|
||||||
@ -151,4 +153,17 @@ impl Main {
|
|||||||
None => Ok(0),
|
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 std::collections::HashSet;
|
||||||
use meilidb_schema::{Schema, SchemaAttr};
|
use meilidb_schema::{Schema, SchemaAttr};
|
||||||
use serde::de;
|
use serde::{ser, de};
|
||||||
use crate::criterion::Criteria;
|
use crate::criterion::Criteria;
|
||||||
use crate::serde::Deserializer;
|
use crate::serde::Deserializer;
|
||||||
use crate::{update, query_builder::QueryBuilder, DocumentId, MResult, Error};
|
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(());
|
let _ = self.updates_notifier.send(());
|
||||||
update::push_schema_update(writer, self.updates, self.updates_results, schema)?;
|
update::push_schema_update(writer, self.updates, self.updates_results, schema)
|
||||||
Ok(())
|
}
|
||||||
|
|
||||||
|
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> {
|
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_addition;
|
||||||
mod documents_deletion;
|
mod documents_deletion;
|
||||||
mod schema_update;
|
mod schema_update;
|
||||||
mod synonyms_addition;
|
mod synonyms_addition;
|
||||||
mod synonyms_deletion;
|
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_addition::{DocumentsAddition, apply_documents_addition};
|
||||||
pub use self::documents_deletion::{DocumentsDeletion, apply_documents_deletion};
|
pub use self::documents_deletion::{DocumentsDeletion, apply_documents_deletion};
|
||||||
pub use self::schema_update::{apply_schema_update, push_schema_update};
|
pub use self::schema_update::{apply_schema_update, push_schema_update};
|
||||||
@ -22,7 +24,8 @@ use meilidb_schema::Schema;
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub enum Update {
|
pub enum Update {
|
||||||
SchemaUpdate(Schema),
|
Schema(Schema),
|
||||||
|
Customs(Vec<u8>),
|
||||||
DocumentsAddition(Vec<rmpv::Value>),
|
DocumentsAddition(Vec<rmpv::Value>),
|
||||||
DocumentsDeletion(Vec<DocumentId>),
|
DocumentsDeletion(Vec<DocumentId>),
|
||||||
SynonymsAddition(BTreeMap<String, Vec<String>>),
|
SynonymsAddition(BTreeMap<String, Vec<String>>),
|
||||||
@ -31,7 +34,8 @@ pub enum Update {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub enum UpdateType {
|
pub enum UpdateType {
|
||||||
SchemaUpdate { schema: Schema },
|
Schema { schema: Schema },
|
||||||
|
Customs,
|
||||||
DocumentsAddition { number: usize },
|
DocumentsAddition { number: usize },
|
||||||
DocumentsDeletion { number: usize },
|
DocumentsDeletion { number: usize },
|
||||||
SynonymsAddition { number: usize },
|
SynonymsAddition { number: usize },
|
||||||
@ -104,14 +108,22 @@ pub fn update_task(writer: &mut rkv::Writer, index: store::Index) -> MResult<Opt
|
|||||||
debug!("Processing update number {}", update_id);
|
debug!("Processing update number {}", update_id);
|
||||||
|
|
||||||
let (update_type, result, duration) = match update {
|
let (update_type, result, duration) = match update {
|
||||||
Update::SchemaUpdate(schema) => {
|
Update::Schema(schema) => {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
|
||||||
let update_type = UpdateType::SchemaUpdate { schema: schema.clone() };
|
let update_type = UpdateType::Schema { schema: schema.clone() };
|
||||||
let result = apply_schema_update(writer, index.main, &schema);
|
let result = apply_schema_update(writer, index.main, &schema);
|
||||||
|
|
||||||
(update_type, result, start.elapsed())
|
(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) => {
|
Update::DocumentsAddition(documents) => {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ pub fn push_schema_update(
|
|||||||
{
|
{
|
||||||
let last_update_id = next_update_id(writer, updates_store, updates_results_store)?;
|
let last_update_id = next_update_id(writer, updates_store, updates_results_store)?;
|
||||||
|
|
||||||
let update = Update::SchemaUpdate(schema);
|
let update = Update::Schema(schema);
|
||||||
updates_store.put_update(writer, last_update_id, &update)?;
|
updates_store.put_update(writer, last_update_id, &update)?;
|
||||||
|
|
||||||
Ok(last_update_id)
|
Ok(last_update_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user