diff --git a/meilisearch-core/src/bucket_sort.rs b/meilisearch-core/src/bucket_sort.rs index 15ab54991..113359501 100644 --- a/meilisearch-core/src/bucket_sort.rs +++ b/meilisearch-core/src/bucket_sort.rs @@ -70,11 +70,12 @@ where println!("number of postings {:?}", queries.len()); let before = Instant::now(); - for (query, matches) in queries { + for ((query, input), matches) in queries { let op = sdset::duo::IntersectionByKey::new(&matches, &docids, |d| d.document_id, Clone::clone); let buf: SetBuf = op.into_set_buf(); if !buf.is_empty() { - println!("{:?} gives {} matches", query, buf.len()); + let input = std::str::from_utf8(&input); + println!("({:?}, {:?}) gives {} matches", query, input, buf.len()); } } diff --git a/meilisearch-core/src/query_tree.rs b/meilisearch-core/src/query_tree.rs index 085c525a6..aa8467629 100644 --- a/meilisearch-core/src/query_tree.rs +++ b/meilisearch-core/src/query_tree.rs @@ -213,14 +213,14 @@ pub fn create_query_tree(reader: &heed::RoTxn, ctx: &Context, query: &str Ok(create_operation(ngrams, Operation::Or)) } +pub type Postings<'o, 'txn> = HashMap<(&'o Query, Vec), Cow<'txn, Set>>; +pub type Cache<'o, 'txn> = HashMap<&'o Operation, Cow<'txn, Set>>; + pub struct QueryResult<'o, 'txn> { pub docids: Cow<'txn, Set>, - pub queries: HashMap<&'o Query, Cow<'txn, Set>>, + pub queries: Postings<'o, 'txn>, } -pub type Postings<'o, 'txn> = HashMap<&'o Query, Cow<'txn, Set>>; -pub type Cache<'o, 'txn> = HashMap<&'o Operation, Cow<'txn, Set>>; - pub fn traverse_query_tree<'o, 'txn>( reader: &'txn heed::RoTxn, ctx: &Context, @@ -318,8 +318,9 @@ pub fn traverse_query_tree<'o, 'txn>( QueryKind::Tolerant(word) => { if *prefix && word.len() == 1 { let prefix = [word.as_bytes()[0], 0, 0, 0]; - let matches = ctx.prefix_postings_lists.prefix_postings_list(reader, prefix)?.unwrap_or_default(); - matches.docids + let result = ctx.prefix_postings_lists.prefix_postings_list(reader, prefix)?.unwrap_or_default(); + postings.insert((query, word.clone().into_bytes()), result.matches); + result.docids } else { let dfa = if *prefix { build_prefix_dfa(word) } else { build_dfa(word) }; @@ -333,8 +334,9 @@ pub fn traverse_query_tree<'o, 'txn>( let before = Instant::now(); let mut docids = Vec::new(); while let Some(input) = stream.next() { - if let Some(postings) = ctx.postings_lists.postings_list(reader, input)? { - docids.extend_from_slice(&postings.docids); + if let Some(result) = ctx.postings_lists.postings_list(reader, input)? { + docids.extend_from_slice(&result.docids); + postings.insert((query, input.to_owned()), result.matches); } } println!("{:3$}docids extend ({:?}) took {:.02?}", "", docids.len(), before.elapsed(), depth * 2); @@ -359,8 +361,9 @@ pub fn traverse_query_tree<'o, 'txn>( let mut docids = Vec::new(); while let Some(input) = stream.next() { - if let Some(postings) = ctx.postings_lists.postings_list(reader, input)? { - docids.extend_from_slice(&postings.docids); + if let Some(result) = ctx.postings_lists.postings_list(reader, input)? { + docids.extend_from_slice(&result.docids); + postings.insert((query, input.to_owned()), result.matches); } } @@ -388,6 +391,10 @@ pub fn traverse_query_tree<'o, 'txn>( docids.dedup(); let docids = SetBuf::new(docids).unwrap(); println!("{:2$}docids construction took {:.02?}", "", before.elapsed(), depth * 2); + + let matches = Cow::Owned(SetBuf::new(matches).unwrap()); + postings.insert((query, vec![]), matches); + Cow::Owned(docids) } else { println!("{:2$}{:?} skipped", "", words, depth * 2); @@ -397,8 +404,6 @@ pub fn traverse_query_tree<'o, 'txn>( }; println!("{:4$}{:?} fetched {:?} documents in {:.02?}", "", query, docids.len(), before.elapsed(), depth * 2); - - // postings.insert(query, matches); Ok(docids) }