diff --git a/meilidb-core/src/lib.rs b/meilidb-core/src/lib.rs index a8bc6d428..efc6ffee8 100644 --- a/meilidb-core/src/lib.rs +++ b/meilidb-core/src/lib.rs @@ -15,7 +15,6 @@ pub mod store; pub use self::database::Database; pub use self::error::{Error, MResult}; pub use self::number::{Number, ParseNumberError}; -pub use self::query_builder::QueryBuilder; pub use self::ranked_map::RankedMap; pub use self::raw_document::RawDocument; pub use self::store::Index; diff --git a/meilidb-core/src/main.rs b/meilidb-core/src/main.rs index 90ff2723a..18c570a83 100644 --- a/meilidb-core/src/main.rs +++ b/meilidb-core/src/main.rs @@ -3,7 +3,7 @@ use std::{fs, path::Path}; use serde_json::json; use rkv::{Manager, Rkv, SingleStore, Value, StoreOptions}; -use meilidb_core::{Database, MResult, QueryBuilder}; +use meilidb_core::{Database, MResult}; use meilidb_schema::{SchemaBuilder, DISPLAYED, INDEXED}; fn main() -> MResult<()> { @@ -11,6 +11,7 @@ fn main() -> MResult<()> { let path = Path::new("test.rkv"); let database = Database::open_or_create(path)?; + let rkv = database.rkv.read().unwrap(); println!("{:?}", database.indexes_names()); let hello = database.open_index("hello")?; @@ -23,20 +24,18 @@ fn main() -> MResult<()> { builder.new_attribute("gamma", INDEXED); let schema = builder.build(); - let rkv = database.rkv.read().unwrap(); let writer = rkv.write()?; hello.schema_update(writer, schema)?; let object = json!({ "id": 23, - "alpha": "hello", + "beta": "hello", }); let mut additions = hello.documents_addition(); additions.extend(vec![object]); - let rkv = database.rkv.read().unwrap(); let writer = rkv.write()?; additions.finalize(writer)?; @@ -67,11 +66,11 @@ fn main() -> MResult<()> { // 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(); + let builder = hello.query_builder(); + let reader = rkv.read().unwrap(); + let documents = builder.query(&reader, "hello", 0..20).unwrap(); - // println!("{:?}", documents); + println!("{:?}", documents); std::thread::sleep(std::time::Duration::from_secs(2)); diff --git a/meilidb-core/src/store/mod.rs b/meilidb-core/src/store/mod.rs index 8b596edd9..799f27681 100644 --- a/meilidb-core/src/store/mod.rs +++ b/meilidb-core/src/store/mod.rs @@ -15,7 +15,7 @@ pub use self::updates::Updates; pub use self::updates_results::UpdatesResults; use meilidb_schema::Schema; -use crate::{update, MResult}; +use crate::{update, query_builder::QueryBuilder, MResult}; fn aligned_to(bytes: &[u8], align: usize) -> bool { (bytes as *const _ as *const () as usize) % align == 0 @@ -85,6 +85,10 @@ impl Index { self.updates_notifier.clone(), ) } + + pub fn query_builder(&self) -> QueryBuilder { + QueryBuilder::new(self.main, self.postings_lists, self.synonyms) + } } pub fn create(