Introduce a query_builder method on Index

This commit is contained in:
Clément Renault 2019-10-07 17:55:46 +02:00
parent a57a64823e
commit 0bfba3e4ba
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
3 changed files with 12 additions and 10 deletions

View File

@ -15,7 +15,6 @@ pub mod store;
pub use self::database::Database; pub use self::database::Database;
pub use self::error::{Error, MResult}; pub use self::error::{Error, MResult};
pub use self::number::{Number, ParseNumberError}; pub use self::number::{Number, ParseNumberError};
pub use self::query_builder::QueryBuilder;
pub use self::ranked_map::RankedMap; pub use self::ranked_map::RankedMap;
pub use self::raw_document::RawDocument; pub use self::raw_document::RawDocument;
pub use self::store::Index; pub use self::store::Index;

View File

@ -3,7 +3,7 @@ use std::{fs, path::Path};
use serde_json::json; use serde_json::json;
use rkv::{Manager, Rkv, SingleStore, Value, StoreOptions}; use rkv::{Manager, Rkv, SingleStore, Value, StoreOptions};
use meilidb_core::{Database, MResult, QueryBuilder}; use meilidb_core::{Database, MResult};
use meilidb_schema::{SchemaBuilder, DISPLAYED, INDEXED}; use meilidb_schema::{SchemaBuilder, DISPLAYED, INDEXED};
fn main() -> MResult<()> { fn main() -> MResult<()> {
@ -11,6 +11,7 @@ fn main() -> MResult<()> {
let path = Path::new("test.rkv"); let path = Path::new("test.rkv");
let database = Database::open_or_create(path)?; let database = Database::open_or_create(path)?;
let rkv = database.rkv.read().unwrap();
println!("{:?}", database.indexes_names()); println!("{:?}", database.indexes_names());
let hello = database.open_index("hello")?; let hello = database.open_index("hello")?;
@ -23,20 +24,18 @@ fn main() -> MResult<()> {
builder.new_attribute("gamma", INDEXED); builder.new_attribute("gamma", INDEXED);
let schema = builder.build(); let schema = builder.build();
let rkv = database.rkv.read().unwrap();
let writer = rkv.write()?; let writer = rkv.write()?;
hello.schema_update(writer, schema)?; hello.schema_update(writer, schema)?;
let object = json!({ let object = json!({
"id": 23, "id": 23,
"alpha": "hello", "beta": "hello",
}); });
let mut additions = hello.documents_addition(); let mut additions = hello.documents_addition();
additions.extend(vec![object]); additions.extend(vec![object]);
let rkv = database.rkv.read().unwrap();
let writer = rkv.write()?; let writer = rkv.write()?;
additions.finalize(writer)?; additions.finalize(writer)?;
@ -67,11 +66,11 @@ fn main() -> MResult<()> {
// writer.commit().unwrap(); // writer.commit().unwrap();
// } // }
// let reader = env.read().unwrap(); let builder = hello.query_builder();
// let builder = QueryBuilder::new(index.main, index.postings_lists, index.synonyms); let reader = rkv.read().unwrap();
// let documents = builder.query(&reader, "oubli", 0..20).unwrap(); let documents = builder.query(&reader, "hello", 0..20).unwrap();
// println!("{:?}", documents); println!("{:?}", documents);
std::thread::sleep(std::time::Duration::from_secs(2)); std::thread::sleep(std::time::Duration::from_secs(2));

View File

@ -15,7 +15,7 @@ pub use self::updates::Updates;
pub use self::updates_results::UpdatesResults; pub use self::updates_results::UpdatesResults;
use meilidb_schema::Schema; use meilidb_schema::Schema;
use crate::{update, MResult}; use crate::{update, query_builder::QueryBuilder, MResult};
fn aligned_to(bytes: &[u8], align: usize) -> bool { fn aligned_to(bytes: &[u8], align: usize) -> bool {
(bytes as *const _ as *const () as usize) % align == 0 (bytes as *const _ as *const () as usize) % align == 0
@ -85,6 +85,10 @@ impl Index {
self.updates_notifier.clone(), self.updates_notifier.clone(),
) )
} }
pub fn query_builder(&self) -> QueryBuilder {
QueryBuilder::new(self.main, self.postings_lists, self.synonyms)
}
} }
pub fn create( pub fn create(