simplify bucket sort signature

This commit is contained in:
mpostma 2020-06-27 11:36:59 +02:00
parent 641d12fb2d
commit 8e9296c66f
2 changed files with 20 additions and 45 deletions

View File

@ -19,7 +19,7 @@ use crate::criterion::{Criteria, Context, ContextMut};
use crate::distinct_map::{BufferedDistinctMap, DistinctMap}; use crate::distinct_map::{BufferedDistinctMap, DistinctMap};
use crate::raw_document::RawDocument; use crate::raw_document::RawDocument;
use crate::{database::MainT, reordered_attrs::ReorderedAttrs}; use crate::{database::MainT, reordered_attrs::ReorderedAttrs};
use crate::{store, Document, DocumentId, MResult}; use crate::{Document, DocumentId, MResult, Index};
use crate::query_tree::{create_query_tree, traverse_query_tree}; use crate::query_tree::{create_query_tree, traverse_query_tree};
use crate::query_tree::{Operation, QueryResult, QueryKind, QueryId, PostingsKey}; use crate::query_tree::{Operation, QueryResult, QueryKind, QueryId, PostingsKey};
use crate::query_tree::Context as QTContext; use crate::query_tree::Context as QTContext;
@ -42,12 +42,7 @@ pub fn bucket_sort<'c, FI>(
filter: Option<FI>, filter: Option<FI>,
criteria: Criteria<'c>, criteria: Criteria<'c>,
searchable_attrs: Option<ReorderedAttrs>, searchable_attrs: Option<ReorderedAttrs>,
main_store: store::Main, index: &Index,
postings_lists_store: store::PostingsLists,
documents_fields_counts_store: store::DocumentsFieldsCounts,
synonyms_store: store::Synonyms,
prefix_documents_cache_store: store::PrefixDocumentsCache,
prefix_postings_lists_cache_store: store::PrefixPostingsListsCache,
) -> MResult<SortResult> ) -> MResult<SortResult>
where where
FI: Fn(DocumentId) -> bool, FI: Fn(DocumentId) -> bool,
@ -68,26 +63,21 @@ where
distinct_size, distinct_size,
criteria, criteria,
searchable_attrs, searchable_attrs,
main_store, index,
postings_lists_store,
documents_fields_counts_store,
synonyms_store,
prefix_documents_cache_store,
prefix_postings_lists_cache_store,
); );
} }
let mut result = SortResult::default(); let mut result = SortResult::default();
let words_set = main_store.words_fst(reader)?; let words_set = index.main.words_fst(reader)?;
let stop_words = main_store.stop_words_fst(reader)?; let stop_words = index.main.stop_words_fst(reader)?;
let context = QTContext { let context = QTContext {
words_set, words_set,
stop_words, stop_words,
synonyms: synonyms_store, synonyms: index.synonyms,
postings_lists: postings_lists_store, postings_lists: index.postings_lists,
prefix_postings_lists: prefix_postings_lists_cache_store, prefix_postings_lists: index.prefix_postings_lists_cache,
}; };
let (operation, mapping) = create_query_tree(reader, &context, query)?; let (operation, mapping) = create_query_tree(reader, &context, query)?;
@ -156,7 +146,7 @@ where
reader, reader,
postings_lists: &mut arena, postings_lists: &mut arena,
query_mapping: &mapping, query_mapping: &mapping,
documents_fields_counts_store, documents_fields_counts_store: index.documents_fields_counts,
}; };
criterion.prepare(ctx, &mut group)?; criterion.prepare(ctx, &mut group)?;
@ -189,7 +179,7 @@ where
debug!("criterion loop took {:.02?}", before_criterion_loop.elapsed()); debug!("criterion loop took {:.02?}", before_criterion_loop.elapsed());
debug!("proximity evaluation called {} times", proximity_count.load(Ordering::Relaxed)); debug!("proximity evaluation called {} times", proximity_count.load(Ordering::Relaxed));
let schema = main_store.schema(reader)?.ok_or(Error::SchemaMissing)?; let schema = index.main.schema(reader)?.ok_or(Error::SchemaMissing)?;
let iter = raw_documents.into_iter().skip(range.start).take(range.len()); let iter = raw_documents.into_iter().skip(range.start).take(range.len());
let iter = iter.map(|rd| Document::from_raw(rd, &queries_kinds, &arena, searchable_attrs.as_ref(), &schema)); let iter = iter.map(|rd| Document::from_raw(rd, &queries_kinds, &arena, searchable_attrs.as_ref(), &schema));
let documents = iter.collect(); let documents = iter.collect();
@ -213,12 +203,7 @@ pub fn bucket_sort_with_distinct<'c, FI, FD>(
distinct_size: usize, distinct_size: usize,
criteria: Criteria<'c>, criteria: Criteria<'c>,
searchable_attrs: Option<ReorderedAttrs>, searchable_attrs: Option<ReorderedAttrs>,
main_store: store::Main, index: &Index,
postings_lists_store: store::PostingsLists,
documents_fields_counts_store: store::DocumentsFieldsCounts,
synonyms_store: store::Synonyms,
_prefix_documents_cache_store: store::PrefixDocumentsCache,
prefix_postings_lists_cache_store: store::PrefixPostingsListsCache,
) -> MResult<SortResult> ) -> MResult<SortResult>
where where
FI: Fn(DocumentId) -> bool, FI: Fn(DocumentId) -> bool,
@ -226,15 +211,15 @@ where
{ {
let mut result = SortResult::default(); let mut result = SortResult::default();
let words_set = main_store.words_fst(reader)?; let words_set = index.main.words_fst(reader)?;
let stop_words = main_store.stop_words_fst(reader)?; let stop_words = index.main.stop_words_fst(reader)?;
let context = QTContext { let context = QTContext {
words_set, words_set,
stop_words, stop_words,
synonyms: synonyms_store, synonyms: index.synonyms,
postings_lists: postings_lists_store, postings_lists: index.postings_lists,
prefix_postings_lists: prefix_postings_lists_cache_store, prefix_postings_lists: index.prefix_postings_lists_cache,
}; };
let (operation, mapping) = create_query_tree(reader, &context, query)?; let (operation, mapping) = create_query_tree(reader, &context, query)?;
@ -313,7 +298,7 @@ where
reader, reader,
postings_lists: &mut arena, postings_lists: &mut arena,
query_mapping: &mapping, query_mapping: &mapping,
documents_fields_counts_store, documents_fields_counts_store: index.documents_fields_counts,
}; };
let before_criterion_preparation = Instant::now(); let before_criterion_preparation = Instant::now();
@ -378,7 +363,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)?.ok_or(Error::SchemaMissing)?; let schema = index.main.schema(reader)?.ok_or(Error::SchemaMissing)?;
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

@ -152,12 +152,7 @@ impl<'c, 'f, 'd, 'i> QueryBuilder<'c, 'f, 'd, 'i> {
distinct_size, distinct_size,
self.criteria, self.criteria,
self.searchable_attrs, self.searchable_attrs,
self.index.main, self.index,
self.index.postings_lists,
self.index.documents_fields_counts,
self.index.synonyms,
self.index.prefix_documents_cache,
self.index.prefix_postings_lists_cache,
), ),
None => bucket_sort( None => bucket_sort(
reader, reader,
@ -168,12 +163,7 @@ impl<'c, 'f, 'd, 'i> QueryBuilder<'c, 'f, 'd, 'i> {
self.filter, self.filter,
self.criteria, self.criteria,
self.searchable_attrs, self.searchable_attrs,
self.index.main, self.index,
self.index.postings_lists,
self.index.documents_fields_counts,
self.index.synonyms,
self.index.prefix_documents_cache,
self.index.prefix_postings_lists_cache,
), ),
} }
} }