rewrite indexed_pos -> field_id for hightligths

This commit is contained in:
qdequele 2020-01-13 19:34:49 +01:00
parent 130fb74928
commit 21d122a870
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
3 changed files with 33 additions and 2 deletions

View File

@ -330,6 +330,7 @@ where
// once we classified the documents related to the current // once we classified the documents related to the current
// automatons we save that as the next valid result // automatons we save that as the next valid result
let mut seen = BufferedDistinctMap::new(&mut distinct_map); let mut seen = BufferedDistinctMap::new(&mut distinct_map);
let schema = main_store.schema(reader)?.unwrap();
let mut documents = Vec::with_capacity(range.len()); let mut documents = Vec::with_capacity(range.len());
for raw_document in raw_documents.into_iter().skip(distinct_raw_offset) { for raw_document in raw_documents.into_iter().skip(distinct_raw_offset) {

View File

@ -16,7 +16,6 @@ mod ranked_map;
mod raw_document; mod raw_document;
mod reordered_attrs; mod reordered_attrs;
mod update; mod update;
// mod fields_map;
pub mod settings; pub mod settings;
pub mod criterion; pub mod criterion;
pub mod raw_indexer; pub mod raw_indexer;
@ -27,7 +26,6 @@ pub use self::database::{BoxUpdateFn, Database, MainT, UpdateT};
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::ranked_map::RankedMap; pub use self::ranked_map::RankedMap;
// pub use self::fields_map::FieldsMap;
pub use self::raw_document::RawDocument; pub use self::raw_document::RawDocument;
pub use self::store::Index; pub use self::store::Index;
pub use self::update::{EnqueuedUpdateResult, ProcessedUpdateResult, UpdateStatus, UpdateType}; pub use self::update::{EnqueuedUpdateResult, ProcessedUpdateResult, UpdateStatus, UpdateType};
@ -57,6 +55,7 @@ fn highlights_from_raw_document<'a, 'tag, 'txn>(
queries_kinds: &HashMap<QueryId, &QueryKind>, queries_kinds: &HashMap<QueryId, &QueryKind>,
arena: &SmallArena<'tag, PostingsListView<'txn>>, arena: &SmallArena<'tag, PostingsListView<'txn>>,
searchable_attrs: Option<&ReorderedAttrs>, searchable_attrs: Option<&ReorderedAttrs>,
schema: &Schema,
) -> Vec<Highlight> ) -> Vec<Highlight>
{ {
let mut highlights = Vec::new(); let mut highlights = Vec::new();
@ -83,6 +82,15 @@ fn highlights_from_raw_document<'a, 'tag, 'txn>(
.and_then(|sa| sa.reverse(di.attribute)) .and_then(|sa| sa.reverse(di.attribute))
.unwrap_or(di.attribute); .unwrap_or(di.attribute);
let attribute = match schema.indexed_pos_to_field_id(attribute) {
Some(field_id) => field_id.0,
None => {
error!("Cannot convert indexed_pos {} to field_id", attribute);
trace!("Schema is compronized; {:?}", schema);
continue
}
};
let highlight = Highlight { let highlight = Highlight {
attribute: attribute, attribute: attribute,
char_index: di.char_index, char_index: di.char_index,
@ -113,6 +121,7 @@ impl Document {
queries_kinds: &HashMap<QueryId, &QueryKind>, queries_kinds: &HashMap<QueryId, &QueryKind>,
arena: &SmallArena<'tag, PostingsListView<'txn>>, arena: &SmallArena<'tag, PostingsListView<'txn>>,
searchable_attrs: Option<&ReorderedAttrs>, searchable_attrs: Option<&ReorderedAttrs>,
schema: &Schema,
) -> Document ) -> Document
{ {
let highlights = highlights_from_raw_document( let highlights = highlights_from_raw_document(
@ -120,6 +129,7 @@ impl Document {
queries_kinds, queries_kinds,
arena, arena,
searchable_attrs, searchable_attrs,
schema,
); );
Document { id: raw_document.id, highlights } Document { id: raw_document.id, highlights }
@ -131,6 +141,7 @@ impl Document {
queries_kinds: &HashMap<QueryId, &QueryKind>, queries_kinds: &HashMap<QueryId, &QueryKind>,
arena: &SmallArena<'tag, PostingsListView<'txn>>, arena: &SmallArena<'tag, PostingsListView<'txn>>,
searchable_attrs: Option<&ReorderedAttrs>, searchable_attrs: Option<&ReorderedAttrs>,
schema: &Schema,
) -> Document ) -> Document
{ {
use crate::bucket_sort::SimpleMatch; use crate::bucket_sort::SimpleMatch;
@ -140,6 +151,7 @@ impl Document {
queries_kinds, queries_kinds,
arena, arena,
searchable_attrs, searchable_attrs,
schema,
); );
let mut matches = Vec::new(); let mut matches = Vec::new();
@ -148,6 +160,15 @@ impl Document {
.and_then(|sa| sa.reverse(sm.attribute)) .and_then(|sa| sa.reverse(sm.attribute))
.unwrap_or(sm.attribute); .unwrap_or(sm.attribute);
let attribute = match schema.indexed_pos_to_field_id(attribute) {
Some(field_id) => field_id.0,
None => {
error!("Cannot convert indexed_pos {} to field_id", attribute);
trace!("Schema is compronized; {:?}", schema);
continue
}
};
matches.push(SimpleMatch { attribute, ..sm }); matches.push(SimpleMatch { attribute, ..sm });
} }
matches.sort_unstable(); matches.sort_unstable();

View File

@ -167,6 +167,15 @@ impl Schema {
self.indexed_map.get(&id) self.indexed_map.get(&id)
} }
pub fn indexed_pos_to_field_id<I: Into<IndexedPos>>(&self, pos: I) -> Option<FieldId> {
let indexed_pos = pos.into().0 as usize;
if indexed_pos < self.indexed.len() {
Some(self.indexed[indexed_pos as usize])
} else {
None
}
}
pub fn update_ranked<S: Into<String>>(&mut self, data: impl IntoIterator<Item = S>) -> SResult<()> { pub fn update_ranked<S: Into<String>>(&mut self, data: impl IntoIterator<Item = S>) -> SResult<()> {
self.ranked = HashSet::new(); self.ranked = HashSet::new();
for name in data { for name in data {