picker search is adding more if we are at the end
This commit is contained in:
2
client
2
client
Submodule client updated: 8fc2b22baa...abb8180e1e
@@ -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<Vec<Hit>, 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::<Vec<_>>();
|
||||
|
||||
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)))?;
|
||||
|
||||
Reference in New Issue
Block a user