From d4da06ff472e8f333570679baa49e111c80d7b89 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Mon, 9 Oct 2023 16:16:50 +0530 Subject: [PATCH] fix bug where distinct search with no ranking returns offset+limit hits --- milli/src/search/new/bucket_sort.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/milli/src/search/new/bucket_sort.rs b/milli/src/search/new/bucket_sort.rs index 03e613b37..cf2f08cce 100644 --- a/milli/src/search/new/bucket_sort.rs +++ b/milli/src/search/new/bucket_sort.rs @@ -46,18 +46,27 @@ pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>( if let Some(distinct_fid) = distinct_fid { let mut excluded = RoaringBitmap::new(); let mut results = vec![]; + let mut skip = 0; for docid in universe.iter() { - if results.len() >= from + length { + if results.len() >= length { break; } if excluded.contains(docid) { continue; } + distinct_single_docid(ctx.index, ctx.txn, distinct_fid, docid, &mut excluded)?; + skip += 1; + if skip <= from { + continue; + } + results.push(docid); } + let mut all_candidates = universe - excluded; all_candidates.extend(results.iter().copied()); + return Ok(BucketSortOutput { scores: vec![Default::default(); results.len()], docids: results,