From 334933b874d811599f2e893ca561c81e32729b0a Mon Sep 17 00:00:00 2001 From: mpostma Date: Wed, 13 Jan 2021 18:29:17 +0100 Subject: [PATCH] fix search --- src/data/search.rs | 9 +++++---- src/index_controller/mod.rs | 14 +++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/data/search.rs b/src/data/search.rs index 44e0a54e6..8c8e0da69 100644 --- a/src/data/search.rs +++ b/src/data/search.rs @@ -109,11 +109,12 @@ impl Data { let index = self.indexes .get(index)? .ok_or_else(|| Error::OpenIndex(format!("Index {} doesn't exists.", index.as_ref())))?; - let Results { found_words, documents_ids, nb_hits, .. } = index.search(search_query)?; - let fields_ids_map = index.fields_ids_map(&rtxn).unwrap(); + let Results { found_words, documents_ids, nb_hits, limit, .. } = index.search(search_query)?; - let displayed_fields = match index.displayed_fields_ids(&rtxn).unwrap() { + let fields_ids_map = index.fields_ids_map()?; + + let displayed_fields = match index.displayed_fields_ids()? { Some(fields) => fields, None => fields_ids_map.iter().map(|(id, _)| id).collect(), }; @@ -126,7 +127,7 @@ impl Data { let stop_words = fst::Set::default(); let highlighter = Highlighter::new(&stop_words); let mut documents = Vec::new(); - for (_id, obkv) in index.documents(&rtxn, documents_ids).unwrap() { + for (_id, obkv) in index.documents(&documents_ids)? { let mut object = obkv_to_json(&displayed_fields, &fields_ids_map, obkv).unwrap(); highlighter.highlight_record(&mut object, &found_words, &attributes_to_highlight); documents.push(object); diff --git a/src/index_controller/mod.rs b/src/index_controller/mod.rs index 0c6a95c1f..25e5d4787 100644 --- a/src/index_controller/mod.rs +++ b/src/index_controller/mod.rs @@ -8,7 +8,7 @@ use chrono::{DateTime, Utc}; use dashmap::DashMap; use heed::types::{Str, SerdeBincode}; use heed::{EnvOpenOptions, Env, Database}; -use milli::Index; +use milli::{Index, FieldsIdsMap}; use serde::{Serialize, Deserialize}; use crate::data::{SearchQuery, SearchResult}; @@ -113,6 +113,18 @@ impl<'a, U: UpdateStore> IndexView<'a, U> { Ok(search.execute()?) } + + pub fn fields_ids_map(&self) -> Result { + self.index.fields_ids_map(self.txn) + } + + pub fn fields_displayed_fields_ids(&self) -> Result { + self.index.fields_displayed_fields_ids(self.txn) + } + + pub fn documents(&self, ids: &[u32]) -> Result> { + self.index.documents(self.txn, ids) + } } impl IndexController {