Skip to content

Commit

Permalink
Merge pull request #31380 from vespa-engine/toregge/deduce-default-va…
Browse files Browse the repository at this point in the history
…lue-in-hit-collector

Deduce default value in hit collector.
  • Loading branch information
toregge authored May 31, 2024
2 parents c206180 + fd2bb5e commit a479163
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct MatchParams {
uint32_t hits_in,
bool hasFinalRank,
bool needRanking=true);
bool save_rank_scores() const { return ((heapSize + arraySize) != 0); }
bool save_rank_scores() const noexcept { return (arraySize != 0); }
bool has_rank_drop_limit() const;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ MatchThread::findMatches(MatchTools &tools)
tools.give_back_search(ProfiledIterator::profile(*match_profiler, tools.borrow_search()));
tools.tag_search_as_changed();
}
HitCollector hits(matchParams.numDocs, matchParams.arraySize);
HitCollector hits(matchParams.numDocs, match_with_ranking ? matchParams.arraySize : 0);
trace->addEvent(4, "Start match and first phase rank");
/**
* All, or none of the threads in the bundle must execute the match loop.
Expand All @@ -380,7 +380,7 @@ MatchThread::findMatches(MatchTools &tools)
secondPhase(tools, hits);
}
trace->addEvent(4, "Create result set");
return hits.getResultSet(fallback_rank_value());
return hits.getResultSet();
}

void
Expand Down
8 changes: 7 additions & 1 deletion searchlib/src/vespa/searchlib/queryeval/hitcollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,14 @@ mixin_rescored_hits(ResultSet& rs, const std::vector<HitCollector::Hit>& hits, c
}

std::unique_ptr<ResultSet>
HitCollector::getResultSet(HitRank default_value)
HitCollector::getResultSet()
{
/*
* Use default_rank_value (i.e. -HUGE_VAL) when hit collector saves
* rank scores, otherwise use zero_rank_value (i.e. 0.0).
*/
auto default_value = save_rank_scores() ? search::default_rank_value : search::zero_rank_value;

bool needReScore = FirstPhaseRescorer::need_rescore(_ranges);
FirstPhaseRescorer rescorer(_ranges);

Expand Down
7 changes: 4 additions & 3 deletions searchlib/src/vespa/searchlib/queryeval/hitcollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class HitCollector {
VESPA_DLL_LOCAL void sortHitsByScore(size_t topn);
VESPA_DLL_LOCAL void sortHitsByDocId();

bool save_rank_scores() const noexcept { return _maxHitsSize != 0; }

public:
HitCollector(const HitCollector &) = delete;
HitCollector &operator=(const HitCollector &) = delete;
Expand Down Expand Up @@ -169,10 +171,9 @@ class HitCollector {
* Invoking this method will destroy the heap property of the
* ranked hits and the match data heap.
*
* @param auto pointer to the result set
* @param default_value rank value to be used for results without rank value
* @return unique pointer to the result set
**/
std::unique_ptr<ResultSet> getResultSet(HitRank default_value = default_rank_value);
std::unique_ptr<ResultSet> getResultSet();
};

}

0 comments on commit a479163

Please sign in to comment.