From eb1691a432e6481db755d7534874c6d20b5ac241 Mon Sep 17 00:00:00 2001 From: Priec Date: Thu, 9 Jul 2026 19:48:06 +0200 Subject: [PATCH] picker search is adding more if we are at the end --- client | 2 +- search/src/lib.rs | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/client b/client index 8fc2b22..abb8180 160000 --- a/client +++ b/client @@ -1 +1 @@ -Subproject commit 8fc2b22baa16972fa4db23987a9c096266d957c3 +Subproject commit abb8180e1e92dfaa26ded87666d2b8c2b2c2a87f diff --git a/search/src/lib.rs b/search/src/lib.rs index a5fbbea..f9bdad4 100644 --- a/search/src/lib.rs +++ b/search/src/lib.rs @@ -22,6 +22,7 @@ const INDEX_ROOT: &str = "./tantivy_indexes"; const DEFAULT_RESULT_LIMIT: usize = 60; const HARD_RESULT_LIMIT: usize = 200; const DEFAULT_LIST_LIMIT: usize = 5; +const SEARCH_SCORE_RELATIVE_FLOOR: f32 = 0.25; pub struct SearcherService { pub pool: PgPool, @@ -102,6 +103,7 @@ impl SearcherService { &normalized.free_query, &resolved_must, normalized.limit.unwrap_or(DEFAULT_RESULT_LIMIT), + normalized.offset, ) .await?; @@ -520,6 +522,7 @@ async fn run_search( free_query: &str, must: &[SearchConstraint], limit: usize, + offset: usize, ) -> Result, Status> { let master_query = build_master_query( &profile.index, @@ -530,16 +533,30 @@ async fn run_search( )?; let searcher = profile.reader.searcher(); + let window_limit = offset.saturating_add(limit); let top_docs = searcher - .search(&*master_query, &TopDocs::with_limit(limit).order_by_score()) + .search(&*master_query, &TopDocs::with_limit(window_limit).order_by_score()) .map_err(|e| Status::internal(format!("Search failed: {}", e)))?; if top_docs.is_empty() { return Ok(vec![]); } - let mut candidates: Vec<(f32, i64, String)> = Vec::with_capacity(top_docs.len()); - for (score, doc_address) in top_docs { + let best_score = top_docs.first().map(|(score, _)| *score).unwrap_or_default(); + let score_floor = if best_score > 0.0 { + best_score * SEARCH_SCORE_RELATIVE_FLOOR + } else { + 0.0 + }; + let page_docs = top_docs + .into_iter() + .skip(offset) + .filter(|(score, _)| *score >= score_floor) + .take(limit) + .collect::>(); + + let mut candidates: Vec<(f32, i64, String)> = Vec::with_capacity(page_docs.len()); + for (score, doc_address) in page_docs { let doc: TantivyDocument = searcher .doc(doc_address) .map_err(|e| Status::internal(format!("Failed to retrieve document: {}", e)))?;