MeiliSearch/meilidb-core/src/store/mod.rs

100 lines
3.0 KiB
Rust
Raw Normal View History

2019-10-03 15:04:11 +02:00
mod docs_words;
2019-10-03 11:49:13 +02:00
mod documents_fields;
2019-10-03 15:04:11 +02:00
mod main;
mod postings_lists;
mod synonyms;
2019-10-03 15:04:11 +02:00
mod updates;
2019-10-03 16:13:09 +02:00
mod updates_results;
2019-10-03 15:04:11 +02:00
pub use self::docs_words::DocsWords;
2019-10-03 11:49:13 +02:00
pub use self::documents_fields::{DocumentsFields, DocumentFieldsIter};
2019-10-03 15:04:11 +02:00
pub use self::main::Main;
pub use self::postings_lists::PostingsLists;
pub use self::synonyms::Synonyms;
2019-10-03 15:04:11 +02:00
pub use self::updates::Updates;
2019-10-03 16:13:09 +02:00
pub use self::updates_results::UpdatesResults;
fn aligned_to(bytes: &[u8], align: usize) -> bool {
(bytes as *const _ as *const () as usize) % align == 0
}
2019-10-03 15:04:11 +02:00
fn postings_lists_name(name: &str) -> String {
format!("{}-postings-lists", name)
}
fn documents_fields_name(name: &str) -> String {
format!("{}-documents-fields", name)
2019-10-03 11:49:13 +02:00
}
fn synonyms_name(name: &str) -> String {
format!("{}-synonyms", name)
}
2019-10-03 15:04:11 +02:00
fn docs_words_name(name: &str) -> String {
format!("{}-docs-words", name)
2019-10-03 11:49:13 +02:00
}
2019-10-03 15:04:11 +02:00
fn updates_name(name: &str) -> String {
format!("{}-updates", name)
}
2019-10-03 16:13:09 +02:00
fn updates_results_name(name: &str) -> String {
format!("{}-updates-results", name)
}
2019-10-03 15:04:11 +02:00
#[derive(Copy, Clone)]
pub struct Index {
pub main: Main,
pub postings_lists: PostingsLists,
pub documents_fields: DocumentsFields,
pub synonyms: Synonyms,
pub docs_words: DocsWords,
pub updates: Updates,
2019-10-03 16:13:09 +02:00
pub updates_results: UpdatesResults,
2019-10-03 15:04:11 +02:00
}
pub fn create(env: &rkv::Rkv, name: &str) -> Result<Index, rkv::StoreError> {
2019-10-03 11:49:13 +02:00
open_options(env, name, rkv::StoreOptions::create())
}
2019-10-03 15:04:11 +02:00
pub fn open(env: &rkv::Rkv, name: &str) -> Result<Index, rkv::StoreError> {
2019-10-03 11:49:13 +02:00
let mut options = rkv::StoreOptions::default();
options.create = false;
open_options(env, name, options)
}
fn open_options(
env: &rkv::Rkv,
name: &str,
options: rkv::StoreOptions,
2019-10-03 15:04:11 +02:00
) -> Result<Index, rkv::StoreError>
2019-10-03 11:49:13 +02:00
{
// create all the database names
let main_name = name;
2019-10-03 15:04:11 +02:00
let postings_lists_name = postings_lists_name(name);
2019-10-03 11:49:13 +02:00
let documents_fields_name = documents_fields_name(name);
2019-10-03 15:04:11 +02:00
let synonyms_name = synonyms_name(name);
let docs_words_name = docs_words_name(name);
let updates_name = updates_name(name);
2019-10-03 16:13:09 +02:00
let updates_results_name = updates_results_name(name);
2019-10-03 11:49:13 +02:00
// open all the database names
let main = env.open_single(main_name, options)?;
2019-10-03 15:04:11 +02:00
let postings_lists = env.open_single(postings_lists_name.as_str(), options)?;
2019-10-03 11:49:13 +02:00
let documents_fields = env.open_single(documents_fields_name.as_str(), options)?;
2019-10-03 15:04:11 +02:00
let synonyms = env.open_single(synonyms_name.as_str(), options)?;
let docs_words = env.open_single(docs_words_name.as_str(), options)?;
let updates = env.open_single(updates_name.as_str(), options)?;
2019-10-03 16:13:09 +02:00
let updates_results = env.open_single(updates_results_name.as_str(), options)?;
2019-10-03 15:04:11 +02:00
Ok(Index {
main: Main { main },
postings_lists: PostingsLists { postings_lists },
documents_fields: DocumentsFields { documents_fields },
synonyms: Synonyms { synonyms },
docs_words: DocsWords { docs_words },
updates: Updates { updates },
2019-10-03 16:13:09 +02:00
updates_results: UpdatesResults { updates_results },
2019-10-03 15:04:11 +02:00
})
}