aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2017-09-01 14:09:20 +0000
committerHåvard Pettersen <havardpe@oath.com>2017-09-01 14:27:48 +0000
commit4f6705537beea82533d19e35d032f24a89897b8a (patch)
tree5afd9ddcd14d295561b4ef8f055c3683b3686fed
parentabeb3febf928c011247dcd83d521d9ae00f68515 (diff)
use 0.0 rank score for results when not ranking
-rw-r--r--searchcore/src/tests/proton/matching/matching_test.cpp6
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_params.h1
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp9
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_thread.h6
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_tools.h2
-rw-r--r--searchlib/src/vespa/searchlib/common/hitrank.h1
-rw-r--r--searchlib/src/vespa/searchlib/common/rankedhit.h4
-rw-r--r--searchlib/src/vespa/searchlib/common/resultset.cpp8
-rw-r--r--searchlib/src/vespa/searchlib/common/resultset.h2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/hitcollector.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/hitcollector.h3
11 files changed, 28 insertions, 20 deletions
diff --git a/searchcore/src/tests/proton/matching/matching_test.cpp b/searchcore/src/tests/proton/matching/matching_test.cpp
index 679108ba872..fefc6f361a9 100644
--- a/searchcore/src/tests/proton/matching/matching_test.cpp
+++ b/searchcore/src/tests/proton/matching/matching_test.cpp
@@ -494,11 +494,11 @@ TEST("require that sortspec can be used (multi-threaded)") {
SearchReply::UP reply = world.performSearch(request, threads);
ASSERT_EQUAL(9u, reply->hits.size());
EXPECT_EQUAL(document::DocumentId("doc::100").getGlobalId(), reply->hits[0].gid);
- EXPECT_EQUAL(default_rank_value, reply->hits[0].metric);
+ EXPECT_EQUAL(zero_rank_value, reply->hits[0].metric);
EXPECT_EQUAL(document::DocumentId("doc::200").getGlobalId(), reply->hits[1].gid);
- EXPECT_EQUAL(default_rank_value, reply->hits[1].metric);
+ EXPECT_EQUAL(zero_rank_value, reply->hits[1].metric);
EXPECT_EQUAL(document::DocumentId("doc::300").getGlobalId(), reply->hits[2].gid);
- EXPECT_EQUAL(default_rank_value, reply->hits[2].metric);
+ EXPECT_EQUAL(zero_rank_value, reply->hits[2].metric);
}
}
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_params.h b/searchcore/src/vespa/searchcore/proton/matching/match_params.h
index 1426f942dfd..50787516144 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_params.h
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_params.h
@@ -27,6 +27,7 @@ struct MatchParams {
uint32_t hits_in,
bool hasFinalRank,
bool needRanking=true);
+ bool save_rank_scores() const { return ((heapSize + arraySize) != 0); }
};
} // namespace proton::matching
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp
index 1d5abcc2929..3a9f59680f9 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp
@@ -250,7 +250,7 @@ MatchThread::findMatches(MatchTools &matchTools)
LOG(debug, "SearchIterator after MultiBitVectorIteratorBase::optimize(): %s", search->asString().c_str());
}
HitCollector hits(matchParams.numDocs, matchParams.arraySize, matchParams.heapSize);
- if (matchTools.has_first_phase_rank() && ((matchParams.arraySize + matchParams.heapSize) != 0)) {
+ if (match_with_ranking) {
match_loop_helper<SearchIterator::UP, true>(matchTools, std::move(search), *ranking, hits);
} else {
if ((dynamic_cast<const OptimizedAndNotForBlackListing *>(search.get()) != 0) &&
@@ -283,7 +283,7 @@ MatchThread::findMatches(MatchTools &matchTools)
hits.setRanges(ranges);
}
}
- return hits.getResultSet();
+ return hits.getResultSet(fallback_rank_value());
}
void
@@ -294,7 +294,7 @@ MatchThread::processResult(const Doom & hardDoom,
if (hardDoom.doom()) return;
bool hasGrouping = (context.grouping.get() != 0);
if (context.sort->hasSortData() || hasGrouping) {
- result->mergeWithBitOverflow();
+ result->mergeWithBitOverflow(fallback_rank_value());
}
if (hardDoom.doom()) return;
size_t totalHits = result->getNumHits();
@@ -369,7 +369,8 @@ MatchThread::MatchThread(size_t thread_id_in,
thread_stats(),
total_time_s(0.0),
match_time_s(0.0),
- wait_time_s(0.0)
+ wait_time_s(0.0),
+ match_with_ranking(mtf.has_first_phase_rank() && mp.save_rank_scores())
{
}
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_thread.h b/searchcore/src/vespa/searchcore/proton/matching/match_thread.h
index 2d056d0e761..a279e83f032 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_thread.h
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_thread.h
@@ -47,13 +47,14 @@ private:
double total_time_s;
double match_time_s;
double wait_time_s;
+ bool match_with_ranking;
class Context {
public:
Context(double rankDropLimit, MatchTools &matchTools, RankProgram & ranking, HitCollector & hits,
uint32_t num_threads) __attribute__((noinline));
void rankHit(uint32_t docId);
- void addHit(uint32_t docId) { _hits.addHit(docId, search::default_rank_value); }
+ void addHit(uint32_t docId) { _hits.addHit(docId, search::zero_rank_value); }
bool isBelowLimit() const { return matches < _matches_limit; }
bool isAtLimit() const { return matches == _matches_limit; }
bool atSoftDoom() const { return _softDoom.doom(); }
@@ -94,6 +95,9 @@ private:
void processResult(const Doom & hardDoom, search::ResultSet::UP result, ResultProcessor::Context &context);
bool isFirstThread() const { return thread_id == 0; }
+
+ search::HitRank fallback_rank_value() const { return match_with_ranking ? search::default_rank_value : search::zero_rank_value; }
+
public:
MatchThread(size_t thread_id_in,
size_t num_threads_in,
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_tools.h b/searchcore/src/vespa/searchcore/proton/matching/match_tools.h
index 1c0d9aff497..b4f1f997d32 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_tools.h
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_tools.h
@@ -55,7 +55,6 @@ public:
createSearch(search::fef::MatchData &matchData) const {
return _query.createSearch(matchData);
}
- bool has_first_phase_rank() const { return !_rankSetup.getFirstPhaseRank().empty(); }
bool has_second_phase_rank() const { return !_rankSetup.getSecondPhaseRank().empty(); }
search::fef::RankProgram::UP first_phase_program() const;
search::fef::RankProgram::UP second_phase_program() const;
@@ -97,6 +96,7 @@ public:
const MaybeMatchPhaseLimiter &match_limiter() const { return *_match_limiter; }
MatchTools::UP createMatchTools() const;
search::queryeval::Blueprint::HitEstimate estimate() const { return _query.estimate(); }
+ bool has_first_phase_rank() const { return !_rankSetup.getFirstPhaseRank().empty(); }
};
}
diff --git a/searchlib/src/vespa/searchlib/common/hitrank.h b/searchlib/src/vespa/searchlib/common/hitrank.h
index 9f40cf9277c..824c01f9f9e 100644
--- a/searchlib/src/vespa/searchlib/common/hitrank.h
+++ b/searchlib/src/vespa/searchlib/common/hitrank.h
@@ -9,6 +9,7 @@ namespace search {
typedef double HitRank;
typedef double SignedHitRank;
constexpr HitRank default_rank_value = -HUGE_VAL;
+constexpr HitRank zero_rank_value = 0.0;
} // namespace search
diff --git a/searchlib/src/vespa/searchlib/common/rankedhit.h b/searchlib/src/vespa/searchlib/common/rankedhit.h
index d56fa92442f..ed8860e0038 100644
--- a/searchlib/src/vespa/searchlib/common/rankedhit.h
+++ b/searchlib/src/vespa/searchlib/common/rankedhit.h
@@ -11,8 +11,8 @@
namespace search {
struct RankedHit {
- RankedHit() : _docId(0), _rankValue(default_rank_value) { }
- RankedHit(unsigned int docId, HitRank rank = default_rank_value) : _docId(docId), _rankValue(rank) { }
+ RankedHit() : _docId(0), _rankValue(zero_rank_value) { }
+ RankedHit(unsigned int docId, HitRank rank = zero_rank_value) : _docId(docId), _rankValue(rank) { }
unsigned int getDocId() const { return _docId & 0x7fffffff; }
bool hasMore() const { return _docId & 0x80000000; }
HitRank getRank() const { return _rankValue; }
diff --git a/searchlib/src/vespa/searchlib/common/resultset.cpp b/searchlib/src/vespa/searchlib/common/resultset.cpp
index 5ad89bf49d7..44e70886956 100644
--- a/searchlib/src/vespa/searchlib/common/resultset.cpp
+++ b/searchlib/src/vespa/searchlib/common/resultset.cpp
@@ -85,7 +85,7 @@ ResultSet::getNumHits() const
void
-ResultSet::mergeWithBitOverflow()
+ResultSet::mergeWithBitOverflow(HitRank default_value)
{
if ( ! _bitOverflow) {
return;
@@ -111,7 +111,7 @@ ResultSet::mergeWithBitOverflow()
// bitvector hits before array hits
while (bidx < firstArrayHit) {
tgtA->_docId = bidx;
- tgtA->_rankValue = default_rank_value;
+ tgtA->_rankValue = default_value;
tgtA++;
bidx = bitVector->getNextTrueBit(bidx + 1);
}
@@ -123,7 +123,7 @@ ResultSet::mergeWithBitOverflow()
tgtA->_rankValue = oldA->_rankValue;
oldA++;
} else {
- tgtA->_rankValue = default_rank_value;
+ tgtA->_rankValue = default_value;
}
tgtA++;
bidx = bitVector->getNextTrueBit(bidx + 1);
@@ -134,7 +134,7 @@ ResultSet::mergeWithBitOverflow()
// bitvector hits after array hits
while (tgtA < tgtAEnd) {
tgtA->_docId = bidx;
- tgtA->_rankValue = default_rank_value;
+ tgtA->_rankValue = default_value;
tgtA++;
bidx = bitVector->getNextTrueBit(bidx + 1);
}
diff --git a/searchlib/src/vespa/searchlib/common/resultset.h b/searchlib/src/vespa/searchlib/common/resultset.h
index e5ae98fe334..c647ed82238 100644
--- a/searchlib/src/vespa/searchlib/common/resultset.h
+++ b/searchlib/src/vespa/searchlib/common/resultset.h
@@ -38,7 +38,7 @@ public:
const BitVector * getBitOverflow() const { return _bitOverflow.get(); }
BitVector * getBitOverflow() { return _bitOverflow.get(); }
unsigned int getNumHits() const;
- void mergeWithBitOverflow();
+ void mergeWithBitOverflow(HitRank default_value = default_rank_value);
/* isEmpty() is allowed to return false even if bitmap has no hits */
bool isEmpty() const { return (_bitOverflow == NULL && _elemsUsedInRankedHitsArray == 0); }
diff --git a/searchlib/src/vespa/searchlib/queryeval/hitcollector.cpp b/searchlib/src/vespa/searchlib/queryeval/hitcollector.cpp
index 7d79d0f659e..f9196bdaef7 100644
--- a/searchlib/src/vespa/searchlib/queryeval/hitcollector.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/hitcollector.cpp
@@ -252,7 +252,7 @@ mergeHitsIntoResultSet(const std::vector<HitCollector::Hit> &hits, ResultSet &re
}
std::unique_ptr<ResultSet>
-HitCollector::getResultSet()
+HitCollector::getResultSet(HitRank default_value)
{
Scores &initHeapScores = _ranges.first;
Scores &finalHeapScores = _ranges.second;
@@ -306,7 +306,7 @@ HitCollector::getResultSet()
rh[j]._rankValue = getReScore(_hits[i].second);
++i;
} else {
- rh[j]._rankValue = default_rank_value;
+ rh[j]._rankValue = default_value;
}
}
} else {
@@ -317,7 +317,7 @@ HitCollector::getResultSet()
rh[j]._rankValue = _hits[i].second;
++i;
} else {
- rh[j]._rankValue = default_rank_value;
+ rh[j]._rankValue = default_value;
}
}
}
diff --git a/searchlib/src/vespa/searchlib/queryeval/hitcollector.h b/searchlib/src/vespa/searchlib/queryeval/hitcollector.h
index ed2372e3553..1bf2bc21e95 100644
--- a/searchlib/src/vespa/searchlib/queryeval/hitcollector.h
+++ b/searchlib/src/vespa/searchlib/queryeval/hitcollector.h
@@ -191,8 +191,9 @@ public:
* 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
**/
- std::unique_ptr<ResultSet> getResultSet();
+ std::unique_ptr<ResultSet> getResultSet(HitRank default_value = default_rank_value);
private:
HitCollector(const HitCollector &); // Not implemented