mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
feat: Introduce index events to update the WordIndex
This commit is contained in:
parent
25a4961453
commit
0104e93ba9
@ -6,6 +6,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bincode = "1.1.2"
|
||||
byteorder = "1.3.1"
|
||||
hashbrown = { version = "0.1.8", features = ["serde"] }
|
||||
linked-hash-map = { version = "0.5.2", features = ["serde_impl"] }
|
||||
meilidb-core = { path = "../meilidb-core", version = "0.1.0" }
|
||||
|
45
meilidb-data/src/index_event.rs
Normal file
45
meilidb-data/src/index_event.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use std::error::Error;
|
||||
|
||||
use byteorder::{ReadBytesExt, WriteBytesExt};
|
||||
|
||||
use meilidb_core::{Index as WordIndex};
|
||||
use meilidb_core::data::DocIds;
|
||||
use meilidb_core::write_to_bytes::WriteToBytes;
|
||||
use meilidb_core::shared_data_cursor::{SharedDataCursor, FromSharedDataCursor};
|
||||
|
||||
enum NewIndexEvent<'a> {
|
||||
RemovedDocuments(&'a DocIds),
|
||||
UpdatedDocuments(&'a WordIndex),
|
||||
}
|
||||
|
||||
impl<'a> WriteToBytes for NewIndexEvent<'a> {
|
||||
fn write_to_bytes(&self, bytes: &mut Vec<u8>) {
|
||||
match self {
|
||||
NewIndexEvent::RemovedDocuments(doc_ids) => {
|
||||
let _ = bytes.write_u8(0);
|
||||
doc_ids.write_to_bytes(bytes);
|
||||
},
|
||||
NewIndexEvent::UpdatedDocuments(index) => {
|
||||
let _ = bytes.write_u8(1);
|
||||
index.write_to_bytes(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum IndexEvent {
|
||||
RemovedDocuments(DocIds),
|
||||
UpdatedDocuments(WordIndex),
|
||||
}
|
||||
|
||||
impl FromSharedDataCursor for IndexEvent {
|
||||
type Error = Box<Error>;
|
||||
|
||||
fn from_shared_data_cursor(cursor: &mut SharedDataCursor) -> Result<Self, Self::Error> {
|
||||
match cursor.read_u8()? {
|
||||
0 => DocIds::from_shared_data_cursor(cursor).map(IndexEvent::RemovedDocuments),
|
||||
1 => WordIndex::from_shared_data_cursor(cursor).map(IndexEvent::UpdatedDocuments),
|
||||
_ => Err("invalid index event type".into()),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
mod database;
|
||||
mod index_event;
|
||||
mod indexer;
|
||||
mod number;
|
||||
mod ranked_map;
|
||||
@ -8,4 +9,3 @@ pub use self::database::{Database, Index};
|
||||
pub use self::number::Number;
|
||||
pub use self::ranked_map::RankedMap;
|
||||
pub use self::schema::{Schema, SchemaAttr};
|
||||
pub use self::indexer::Indexer;
|
||||
|
Loading…
Reference in New Issue
Block a user