fix search

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

View File

@ -109,11 +109,12 @@ impl Data {
let index = self.indexes let index = self.indexes
.get(index)? .get(index)?
.ok_or_else(|| Error::OpenIndex(format!("Index {} doesn't exists.", index.as_ref())))?; .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, Some(fields) => fields,
None => fields_ids_map.iter().map(|(id, _)| id).collect(), None => fields_ids_map.iter().map(|(id, _)| id).collect(),
}; };
@ -126,7 +127,7 @@ impl Data {
let stop_words = fst::Set::default(); let stop_words = fst::Set::default();
let highlighter = Highlighter::new(&stop_words); let highlighter = Highlighter::new(&stop_words);
let mut documents = Vec::new(); 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(); let mut object = obkv_to_json(&displayed_fields, &fields_ids_map, obkv).unwrap();
highlighter.highlight_record(&mut object, &found_words, &attributes_to_highlight); highlighter.highlight_record(&mut object, &found_words, &attributes_to_highlight);
documents.push(object); documents.push(object);

View File

@ -8,7 +8,7 @@ use chrono::{DateTime, Utc};
use dashmap::DashMap; use dashmap::DashMap;
use heed::types::{Str, SerdeBincode}; use heed::types::{Str, SerdeBincode};
use heed::{EnvOpenOptions, Env, Database}; use heed::{EnvOpenOptions, Env, Database};
use milli::Index; use milli::{Index, FieldsIdsMap};
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use crate::data::{SearchQuery, SearchResult}; use crate::data::{SearchQuery, SearchResult};
@ -113,6 +113,18 @@ impl<'a, U: UpdateStore> IndexView<'a, U> {
Ok(search.execute()?) Ok(search.execute()?)
} }
pub fn fields_ids_map(&self) -> Result<FieldsIdsMap> {
self.index.fields_ids_map(self.txn)
}
pub fn fields_displayed_fields_ids(&self) -> Result<FieldsIdsMap> {
self.index.fields_displayed_fields_ids(self.txn)
}
pub fn documents(&self, ids: &[u32]) -> Result<Vec<()>> {
self.index.documents(self.txn, ids)
}
} }
impl<U: UpdateStore> IndexController<U> { impl<U: UpdateStore> IndexController<U> {