From c9c3cfcee9433f56e16bbd64712ad32663fa1ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sun, 17 Nov 2019 11:53:47 +0100 Subject: [PATCH] Move the main types to a separate library --- Cargo.lock | 9 +++++ Cargo.toml | 1 + meilidb-core/Cargo.toml | 1 + meilidb-core/src/lib.rs | 74 +--------------------------------------- meilidb-types/Cargo.toml | 9 +++++ meilidb-types/src/lib.rs | 72 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 93 insertions(+), 73 deletions(-) create mode 100644 meilidb-types/Cargo.toml create mode 100644 meilidb-types/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 3c9d29cba..5a881485f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -876,6 +876,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "meilidb-schema 0.6.0", "meilidb-tokenizer 0.6.1", + "meilidb-types 0.1.0", "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustyline 5.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -944,6 +945,14 @@ dependencies = [ "slice-group-by 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "meilidb-types" +version = "0.1.0" +dependencies = [ + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "zerocopy 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "memchr" version = "2.2.1" diff --git a/Cargo.toml b/Cargo.toml index bd461dff0..6b1f79c6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "meilidb-http", "meilidb-schema", "meilidb-tokenizer", + "meilidb-types", ] [profile.release] diff --git a/meilidb-core/Cargo.toml b/meilidb-core/Cargo.toml index 0b34be89c..3d2411d83 100644 --- a/meilidb-core/Cargo.toml +++ b/meilidb-core/Cargo.toml @@ -19,6 +19,7 @@ levenshtein_automata = { version = "0.1.1", features = ["fst_automaton"] } log = "0.4.8" meilidb-schema = { path = "../meilidb-schema", version = "0.6.0" } meilidb-tokenizer = { path = "../meilidb-tokenizer", version = "0.6.0" } +meilidb-types = { path = "../meilidb-types", version = "0.1.0" } once_cell = "1.2.0" ordered-float = { version = "1.0.2", features = ["serde"] } sdset = "0.3.3" diff --git a/meilidb-core/src/lib.rs b/meilidb-core/src/lib.rs index f2cc31db4..1c4aaf2f9 100644 --- a/meilidb-core/src/lib.rs +++ b/meilidb-core/src/lib.rs @@ -25,79 +25,7 @@ pub use self::ranked_map::RankedMap; pub use self::raw_document::RawDocument; pub use self::store::Index; pub use self::update::{EnqueuedUpdateResult, ProcessedUpdateResult, UpdateStatus, UpdateType}; - -use ::serde::{Deserialize, Serialize}; -use zerocopy::{AsBytes, FromBytes}; - -/// Represent an internally generated document unique identifier. -/// -/// It is used to inform the database the document you want to deserialize. -/// Helpful for custom ranking. -#[derive( - Debug, - Copy, - Clone, - Eq, - PartialEq, - PartialOrd, - Ord, - Hash, - Serialize, - Deserialize, - AsBytes, - FromBytes, -)] -#[repr(C)] -pub struct DocumentId(pub u64); - -/// This structure represent the position of a word -/// in a document and its attributes. -/// -/// This is stored in the map, generated at index time, -/// extracted and interpreted at search time. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, AsBytes, FromBytes)] -#[repr(C)] -pub struct DocIndex { - /// The document identifier where the word was found. - pub document_id: DocumentId, - - /// The attribute in the document where the word was found - /// along with the index in it. - pub attribute: u16, - pub word_index: u16, - - /// The position in bytes where the word was found - /// along with the length of it. - /// - /// It informs on the original word area in the text indexed - /// without needing to run the tokenizer again. - pub char_index: u16, - pub char_length: u16, -} - -/// This structure represent a matching word with informations -/// on the location of the word in the document. -/// -/// The order of the field is important because it defines -/// the way these structures are ordered between themselves. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct Highlight { - /// The attribute in the document where the word was found - /// along with the index in it. - pub attribute: u16, - - /// The position in bytes where the word was found. - /// - /// It informs on the original word area in the text indexed - /// without needing to run the tokenizer again. - pub char_index: u16, - - /// The length in bytes of the found word. - /// - /// It informs on the original word area in the text indexed - /// without needing to run the tokenizer again. - pub char_length: u16, -} +pub use meilidb_types::{DocIndex, DocumentId, Highlight}; #[doc(hidden)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/meilidb-types/Cargo.toml b/meilidb-types/Cargo.toml new file mode 100644 index 000000000..67764d3c5 --- /dev/null +++ b/meilidb-types/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "meilidb-types" +version = "0.1.0" +authors = ["Clément Renault "] +edition = "2018" + +[dependencies] +serde = { version = "1.0.101", features = ["derive"] } +zerocopy = "0.2.8" diff --git a/meilidb-types/src/lib.rs b/meilidb-types/src/lib.rs new file mode 100644 index 000000000..9a4b9e978 --- /dev/null +++ b/meilidb-types/src/lib.rs @@ -0,0 +1,72 @@ +use serde::{Deserialize, Serialize}; +use zerocopy::{AsBytes, FromBytes}; + +/// Represent an internally generated document unique identifier. +/// +/// It is used to inform the database the document you want to deserialize. +/// Helpful for custom ranking. +#[derive( + Debug, + Copy, + Clone, + Eq, + PartialEq, + PartialOrd, + Ord, + Hash, + Serialize, + Deserialize, + AsBytes, + FromBytes, +)] +#[repr(C)] +pub struct DocumentId(pub u64); + +/// This structure represent the position of a word +/// in a document and its attributes. +/// +/// This is stored in the map, generated at index time, +/// extracted and interpreted at search time. +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, AsBytes, FromBytes)] +#[repr(C)] +pub struct DocIndex { + /// The document identifier where the word was found. + pub document_id: DocumentId, + + /// The attribute in the document where the word was found + /// along with the index in it. + pub attribute: u16, + pub word_index: u16, + + /// The position in bytes where the word was found + /// along with the length of it. + /// + /// It informs on the original word area in the text indexed + /// without needing to run the tokenizer again. + pub char_index: u16, + pub char_length: u16, +} + +/// This structure represent a matching word with informations +/// on the location of the word in the document. +/// +/// The order of the field is important because it defines +/// the way these structures are ordered between themselves. +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Highlight { + /// The attribute in the document where the word was found + /// along with the index in it. + pub attribute: u16, + + /// The position in bytes where the word was found. + /// + /// It informs on the original word area in the text indexed + /// without needing to run the tokenizer again. + pub char_index: u16, + + /// The length in bytes of the found word. + /// + /// It informs on the original word area in the text indexed + /// without needing to run the tokenizer again. + pub char_length: u16, +}