2019-10-08 21:22:36 +08:00
|
|
|
#[cfg(test)]
|
2019-10-18 19:05:28 +08:00
|
|
|
#[macro_use]
|
|
|
|
extern crate assert_matches;
|
2019-10-08 21:22:36 +08:00
|
|
|
|
2019-10-02 23:34:32 +08:00
|
|
|
mod automaton;
|
2019-10-18 19:05:28 +08:00
|
|
|
pub mod criterion;
|
2019-10-04 22:49:17 +08:00
|
|
|
mod database;
|
2019-10-09 19:44:18 +08:00
|
|
|
mod distinct_map;
|
2019-10-03 21:04:11 +08:00
|
|
|
mod error;
|
2019-10-31 00:25:42 +08:00
|
|
|
mod levenshtein;
|
2019-10-03 17:49:13 +08:00
|
|
|
mod number;
|
2019-10-02 23:34:32 +08:00
|
|
|
mod query_builder;
|
2019-10-03 21:04:11 +08:00
|
|
|
mod ranked_map;
|
2019-10-02 23:34:32 +08:00
|
|
|
mod raw_document;
|
|
|
|
pub mod raw_indexer;
|
2019-10-18 19:05:28 +08:00
|
|
|
mod reordered_attrs;
|
2019-10-03 17:49:13 +08:00
|
|
|
pub mod serde;
|
2019-10-02 23:34:32 +08:00
|
|
|
pub mod store;
|
2019-10-18 19:05:28 +08:00
|
|
|
mod update;
|
2019-10-02 23:34:32 +08:00
|
|
|
|
2019-10-18 19:05:28 +08:00
|
|
|
pub use self::database::{BoxUpdateFn, Database};
|
2019-10-03 23:33:15 +08:00
|
|
|
pub use self::error::{Error, MResult};
|
2019-10-04 19:26:33 +08:00
|
|
|
pub use self::number::{Number, ParseNumberError};
|
|
|
|
pub use self::ranked_map::RankedMap;
|
2019-10-04 22:49:17 +08:00
|
|
|
pub use self::raw_document::RawDocument;
|
2019-10-04 19:26:33 +08:00
|
|
|
pub use self::store::Index;
|
2019-10-31 18:13:37 +08:00
|
|
|
pub use self::update::{EnqueuedUpdateResult, ProcessedUpdateResult, UpdateStatus, UpdateType};
|
2019-11-17 18:53:47 +08:00
|
|
|
pub use meilidb_types::{DocIndex, DocumentId, Highlight};
|
2019-10-02 23:34:32 +08:00
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
|
|
pub struct TmpMatch {
|
|
|
|
pub query_index: u32,
|
|
|
|
pub distance: u8,
|
|
|
|
pub attribute: u16,
|
|
|
|
pub word_index: u16,
|
|
|
|
pub is_exact: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
|
|
pub struct Document {
|
|
|
|
pub id: DocumentId,
|
|
|
|
pub highlights: Vec<Highlight>,
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
pub matches: Vec<TmpMatch>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Document {
|
|
|
|
#[cfg(not(test))]
|
|
|
|
fn from_raw(raw: RawDocument) -> Document {
|
2019-10-18 19:05:28 +08:00
|
|
|
Document {
|
|
|
|
id: raw.id,
|
|
|
|
highlights: raw.highlights,
|
|
|
|
}
|
2019-10-02 23:34:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
fn from_raw(raw: RawDocument) -> Document {
|
|
|
|
let len = raw.query_index().len();
|
|
|
|
let mut matches = Vec::with_capacity(len);
|
|
|
|
|
|
|
|
let query_index = raw.query_index();
|
|
|
|
let distance = raw.distance();
|
|
|
|
let attribute = raw.attribute();
|
|
|
|
let word_index = raw.word_index();
|
|
|
|
let is_exact = raw.is_exact();
|
|
|
|
|
|
|
|
for i in 0..len {
|
|
|
|
let match_ = TmpMatch {
|
|
|
|
query_index: query_index[i],
|
|
|
|
distance: distance[i],
|
|
|
|
attribute: attribute[i],
|
|
|
|
word_index: word_index[i],
|
|
|
|
is_exact: is_exact[i],
|
|
|
|
};
|
|
|
|
matches.push(match_);
|
|
|
|
}
|
|
|
|
|
2019-10-18 19:05:28 +08:00
|
|
|
Document {
|
|
|
|
id: raw.id,
|
|
|
|
matches,
|
|
|
|
highlights: raw.highlights,
|
|
|
|
}
|
2019-10-02 23:34:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn docindex_mem_size() {
|
|
|
|
assert_eq!(mem::size_of::<DocIndex>(), 16);
|
|
|
|
}
|
|
|
|
}
|