MeiliSearch/meilidb-core/src/main.rs
2019-10-04 10:26:32 +02:00

53 lines
1.9 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use rkv::{Manager, Rkv, SingleStore, Value, StoreOptions};
use std::{fs, path::Path};
use meilidb_schema::SchemaAttr;
use meilidb_core::{store, QueryBuilder, DocumentId};
use meilidb_core::raw_indexer::{RawIndexer, Indexed};
fn main() {
let path = Path::new("test.rkv");
fs::create_dir_all(path).unwrap();
// The Manager enforces that each process opens the same environment
// at most once by caching a handle to each environment that it opens.
// Use it to retrieve the handle to an opened environment—or create one
// if it hasn't already been opened:
let created_arc = Manager::singleton().write().unwrap().get_or_create(path, Rkv::new).unwrap();
let env = created_arc.read().unwrap();
let index = store::create(&env, "test").unwrap();
// {
// let mut writer = env.write().unwrap();
// let mut raw_indexer = RawIndexer::new();
// let docid = DocumentId(0);
// let attr = SchemaAttr(0);
// let text = "Zut, laspirateur, jai oublié de léteindre !";
// raw_indexer.index_text(docid, attr, text);
// let Indexed { words_doc_indexes, .. } = raw_indexer.build();
// let mut fst_builder = fst::SetBuilder::memory();
// fst_builder.extend_iter(words_doc_indexes.keys()).unwrap();
// let bytes = fst_builder.into_inner().unwrap();
// let fst = fst::raw::Fst::from_bytes(bytes).unwrap();
// let fst = fst::Set::from(fst);
// words.put_words_fst(&mut writer, &fst).unwrap();
// for (word, indexes) in words_doc_indexes {
// words.put_words_indexes(&mut writer, &word, &indexes).unwrap();
// }
// writer.commit().unwrap();
// }
let reader = env.read().unwrap();
let builder = QueryBuilder::new(index.main, index.postings_lists, index.synonyms);
let documents = builder.query(&reader, "oubli", 0..20).unwrap();
println!("{:?}", documents);
}