Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/index/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ impl IndexReader {
} else {
sq.offset.saturating_add(sq.limit)
};
let (top_docs, _) =
searcher.search(&combined, &(TopDocs::with_limit(fetch_count), Count))?;
let (top_docs, _) = if fetch_count == 0 {
(vec![], 0)
} else {
searcher.search(&combined, &(TopDocs::with_limit(fetch_count), Count))?
};

let mut all_results: Vec<SearchResult> = top_docs
.into_iter()
Expand Down Expand Up @@ -181,10 +184,14 @@ impl IndexReader {
(sliced, pre_filter_count)
} else {
// Search mode: let Tantivy handle offset/limit with relevance ranking
let (top_docs, total_count) = searcher.search(
&combined,
&(TopDocs::with_limit(sq.limit).and_offset(sq.offset), Count),
)?;
let (top_docs, total_count) = if sq.limit == 0 {
(vec![], searcher.search(&combined, &Count)?)
} else {
searcher.search(
&combined,
&(TopDocs::with_limit(sq.limit).and_offset(sq.offset), Count),
)?
};
let results: Vec<SearchResult> = top_docs
.into_iter()
.map(|(_score, addr)| {
Expand Down Expand Up @@ -332,6 +339,9 @@ impl IndexReader {
};

let total = searcher.search(&query, &Count)?;
if total == 0 {
return Ok((vec![], matched_gavs));
}
let top_docs = searcher.search(&query, &TopDocs::with_limit(total))?;

let mut pkg_counts: BTreeMap<String, usize> = BTreeMap::new();
Expand Down Expand Up @@ -374,6 +384,9 @@ impl IndexReader {

let query = BooleanQuery::new(clauses);
let total = searcher.search(&query, &Count)?;
if total == 0 {
return Ok((vec![], vec![]));
}
let top_docs = searcher.search(&query, &TopDocs::with_limit(total))?;

let mut pkg_counts: BTreeMap<String, usize> = BTreeMap::new();
Expand Down