2018-10-11 22:09:28 +08:00
|
|
|
#![feature(range_contains)]
|
|
|
|
|
2018-09-09 17:13:58 +08:00
|
|
|
#[macro_use] extern crate lazy_static;
|
2018-04-22 21:54:34 +08:00
|
|
|
|
2018-10-28 21:24:04 +08:00
|
|
|
pub mod index;
|
|
|
|
pub mod blob;
|
2018-11-08 19:05:59 +08:00
|
|
|
pub mod data;
|
2018-05-27 21:23:43 +08:00
|
|
|
pub mod rank;
|
2018-09-09 19:35:12 +08:00
|
|
|
pub mod vec_read_only;
|
2018-09-09 17:13:58 +08:00
|
|
|
pub mod automaton;
|
2018-09-27 22:32:17 +08:00
|
|
|
pub mod tokenizer;
|
2018-10-10 00:23:35 +08:00
|
|
|
mod common_words;
|
2018-07-11 03:29:17 +08:00
|
|
|
|
2018-09-27 22:59:41 +08:00
|
|
|
pub use self::tokenizer::Tokenizer;
|
2018-10-10 00:23:35 +08:00
|
|
|
pub use self::common_words::CommonWords;
|
2018-05-13 21:12:15 +08:00
|
|
|
|
2018-05-27 21:23:43 +08:00
|
|
|
pub type DocumentId = u64;
|
|
|
|
|
2018-05-27 17:15:05 +08:00
|
|
|
/// 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.
|
2018-07-11 03:29:17 +08:00
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
|
|
|
#[repr(C)]
|
2018-05-27 17:15:05 +08:00
|
|
|
pub struct DocIndex {
|
|
|
|
/// The document identifier where the word was found.
|
2018-10-17 19:35:34 +08:00
|
|
|
pub document_id: DocumentId,
|
2018-05-27 17:15:05 +08:00
|
|
|
|
|
|
|
/// The attribute identifier in the document
|
|
|
|
/// where the word was found.
|
|
|
|
///
|
|
|
|
/// This is an `u8` therefore a document
|
|
|
|
/// can not have more than `2^8` attributes.
|
|
|
|
pub attribute: u8,
|
|
|
|
|
|
|
|
/// The index where the word was found in the attribute.
|
|
|
|
///
|
|
|
|
/// Only the first 1000 words are indexed.
|
|
|
|
pub attribute_index: u32,
|
2018-05-13 21:12:15 +08:00
|
|
|
}
|
|
|
|
|
2018-05-27 17:15:05 +08:00
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
/// The word in itself is not important.
|
2018-05-27 21:23:43 +08:00
|
|
|
// TODO do data oriented programming ? very arrays ?
|
2018-05-27 17:15:05 +08:00
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
|
|
|
pub struct Match {
|
2018-05-27 21:23:43 +08:00
|
|
|
/// The word index in the query sentence.
|
|
|
|
/// Same as the `attribute_index` but for the query words.
|
|
|
|
///
|
|
|
|
/// Used to retrieve the automaton that match this word.
|
|
|
|
pub query_index: u32,
|
|
|
|
|
2018-05-27 17:15:05 +08:00
|
|
|
/// The distance the word has with the query word
|
|
|
|
/// (i.e. the Levenshtein distance).
|
|
|
|
pub distance: u8,
|
|
|
|
|
|
|
|
/// The attribute in which the word is located
|
|
|
|
/// (i.e. Title is 0, Description is 1).
|
|
|
|
///
|
|
|
|
/// This is an `u8` therefore a document
|
|
|
|
/// can not have more than `2^8` attributes.
|
2018-05-13 21:12:15 +08:00
|
|
|
pub attribute: u8,
|
2018-05-27 17:15:05 +08:00
|
|
|
|
|
|
|
/// Where does this word is located in the attribute string
|
|
|
|
/// (i.e. at the start or the end of the attribute).
|
|
|
|
///
|
|
|
|
/// The index in the attribute is limited to a maximum of `2^32`
|
2018-08-25 18:35:29 +08:00
|
|
|
/// this is because we index only the first 1000 words
|
|
|
|
/// in an attribute.
|
2018-05-27 17:15:05 +08:00
|
|
|
pub attribute_index: u32,
|
2018-07-07 02:58:06 +08:00
|
|
|
|
|
|
|
/// Whether the word that match is an exact match or a prefix.
|
|
|
|
pub is_exact: bool,
|
2018-05-13 21:12:15 +08:00
|
|
|
}
|
2018-05-27 21:23:43 +08:00
|
|
|
|
|
|
|
impl Match {
|
|
|
|
pub fn zero() -> Self {
|
|
|
|
Match {
|
|
|
|
query_index: 0,
|
|
|
|
distance: 0,
|
|
|
|
attribute: 0,
|
|
|
|
attribute_index: 0,
|
2018-07-07 02:58:06 +08:00
|
|
|
is_exact: false,
|
2018-05-27 21:23:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn max() -> Self {
|
|
|
|
Match {
|
|
|
|
query_index: u32::max_value(),
|
|
|
|
distance: u8::max_value(),
|
|
|
|
attribute: u8::max_value(),
|
|
|
|
attribute_index: u32::max_value(),
|
2018-07-07 02:58:06 +08:00
|
|
|
is_exact: true,
|
2018-05-27 21:23:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|