From fd2bb5ed6791986cb25cbdf6dd68d02ed5c65fe9 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Fri, 31 May 2024 14:43:04 +0200 Subject: Deduce default value in hit collector. --- searchcore/src/vespa/searchcore/proton/matching/match_params.h | 2 +- searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp | 4 ++-- searchlib/src/vespa/searchlib/queryeval/hitcollector.cpp | 8 +++++++- searchlib/src/vespa/searchlib/queryeval/hitcollector.h | 7 ++++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_params.h b/searchcore/src/vespa/searchcore/proton/matching/match_params.h index 5b58c11b7e1..f9dd55e7bb1 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_params.h +++ b/searchcore/src/vespa/searchcore/proton/matching/match_params.h @@ -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; }; diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp index 211e67f1e2b..6b443231c0a 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp @@ -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. @@ -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 diff --git a/searchlib/src/vespa/searchlib/queryeval/hitcollector.cpp b/searchlib/src/vespa/searchlib/queryeval/hitcollector.cpp index c1d59463ad9..698593cfd8e 100644 --- a/searchlib/src/vespa/searchlib/queryeval/hitcollector.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/hitcollector.cpp @@ -269,8 +269,14 @@ mixin_rescored_hits(ResultSet& rs, const std::vector& hits, c } std::unique_ptr -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); diff --git a/searchlib/src/vespa/searchlib/queryeval/hitcollector.h b/searchlib/src/vespa/searchlib/queryeval/hitcollector.h index 903c2ab5b13..fe1d486ff2a 100644 --- a/searchlib/src/vespa/searchlib/queryeval/hitcollector.h +++ b/searchlib/src/vespa/searchlib/queryeval/hitcollector.h @@ -121,6 +121,8 @@ private: 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; @@ -169,10 +171,9 @@ public: * 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 getResultSet(HitRank default_value = default_rank_value); + std::unique_ptr getResultSet(); }; } -- cgit v1.2.3