implement open index

This commit is contained in:
mpostma 2021-01-13 18:18:52 +01:00
parent ddd7789713
commit d22fab5bae
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
2 changed files with 17 additions and 5 deletions

13
Cargo.lock generated
View File

@ -1710,6 +1710,7 @@ dependencies = [
"bstr", "bstr",
"byte-unit", "byte-unit",
"byteorder", "byteorder",
"chrono",
"crossbeam-channel", "crossbeam-channel",
"csv", "csv",
"either", "either",
@ -1724,13 +1725,13 @@ dependencies = [
"levenshtein_automata", "levenshtein_automata",
"linked-hash-map", "linked-hash-map",
"log", "log",
"meilisearch-tokenizer",
"memmap", "memmap",
"near-proximity", "near-proximity",
"num-traits", "num-traits",
"obkv", "obkv",
"once_cell", "once_cell",
"ordered-float", "ordered-float",
"page_size",
"pest 2.1.3 (git+https://github.com/pest-parser/pest.git?rev=51fd1d49f1041f7839975664ef71fe15c7dcaf67)", "pest 2.1.3 (git+https://github.com/pest-parser/pest.git?rev=51fd1d49f1041f7839975664ef71fe15c7dcaf67)",
"pest_derive", "pest_derive",
"rayon", "rayon",
@ -1739,6 +1740,7 @@ dependencies = [
"roaring", "roaring",
"serde", "serde",
"serde_json", "serde_json",
"serde_millis",
"slice-group-by", "slice-group-by",
"smallstr", "smallstr",
"smallvec", "smallvec",
@ -2605,6 +2607,15 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_millis"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e2dc780ca5ee2c369d1d01d100270203c4ff923d2a4264812d723766434d00"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "serde_qs" name = "serde_qs"
version = "0.8.2" version = "0.8.2"

View File

@ -67,8 +67,9 @@ struct IndexMetadata {
} }
impl IndexMetadata { impl IndexMetadata {
fn open_index(&self) -> Result<Self> { fn open_index(&self, path: impl AsRef<Path>) -> Result<Self> {
todo!() let path = path.as_ref().to_path_buf().push("indexes").push(&self.id);
Ok(Index::new(self.options, path)?)
} }
} }
@ -79,7 +80,7 @@ struct IndexView<'a, U> {
} }
struct IndexViewMut<'a, U> { struct IndexViewMut<'a, U> {
txn: heed::RwTxn<'a>, txn: heed::RwTxn<'a, 'a>,
index: &'a Index, index: &'a Index,
update_store: &'a U, update_store: &'a U,
} }
@ -97,7 +98,7 @@ impl<'a, U> Deref for IndexViewMut<'a, U> {
} }
impl<'a, U: UpdateStore> IndexView<'a, U> { impl<'a, U: UpdateStore> IndexView<'a, U> {
fn search(&self, search_query: SearchQuery) -> Result<SearchResult> { pub fn search(&self, search_query: SearchQuery) -> Result<SearchResult> {
let mut search = self.index.search(self.txn); let mut search = self.index.search(self.txn);
if let Some(query) = &search_query.q { if let Some(query) = &search_query.q {
search.query(query); search.query(query);