aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/queryeval/weak_and
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib/src/tests/queryeval/weak_and')
-rw-r--r--searchlib/src/tests/queryeval/weak_and/rise_wand.h31
-rw-r--r--searchlib/src/tests/queryeval/weak_and/rise_wand.hpp35
2 files changed, 26 insertions, 40 deletions
diff --git a/searchlib/src/tests/queryeval/weak_and/rise_wand.h b/searchlib/src/tests/queryeval/weak_and/rise_wand.h
index d4e66ec1907..4c7be54a6f0 100644
--- a/searchlib/src/tests/queryeval/weak_and/rise_wand.h
+++ b/searchlib/src/tests/queryeval/weak_and/rise_wand.h
@@ -15,8 +15,12 @@ namespace rise {
struct TermFreqScorer
{
- static int64_t calculateMaxScore(const wand::Term &term) {
- return TermFrequencyScorer::calculateMaxScore(term);
+ [[no_unique_address]] TermFrequencyScorer _termFrequencyScorer;
+ TermFreqScorer() noexcept
+ : _termFrequencyScorer()
+ { }
+ int64_t calculateMaxScore(const wand::Term &term) const noexcept {
+ return _termFrequencyScorer.calculateMaxScore(term);
}
static int64_t calculateScore(const wand::Term &term, uint32_t docId) {
term.search->unpack(docId);
@@ -43,9 +47,13 @@ private:
//const addr_t *const *_streamPayloads;
public:
- StreamComparator(const docid_t *streamDocIds);
+ explicit StreamComparator(const docid_t *streamDocIds) noexcept
+ : _streamDocIds(streamDocIds)
+ { }
//const addr_t *const *streamPayloads);
- inline bool operator()(const uint16_t a, const uint16_t b);
+ bool operator()(const uint16_t a, const uint16_t b) const noexcept {
+ return (_streamDocIds[a] < _streamDocIds[b]);
+ }
};
// number of streams present in the query
@@ -66,6 +74,7 @@ private:
// comparator that compares two streams
StreamComparator _streamComparator;
+ [[no_unique_address]] Scorer _scorer;
//-------------------------------------------------------------------------
// variables used for scoring and pruning
@@ -86,7 +95,7 @@ private:
*
* @return whether a valid pivot index is found
*/
- bool _findPivotFeatureIdx(const score_t threshold, uint32_t &pivotIdx);
+ bool _findPivotFeatureIdx(score_t threshold, uint32_t &pivotIdx);
/**
* let the first numStreamsToMove streams in the stream
@@ -94,7 +103,7 @@ private:
*
* @param numStreamsToMove the number of streams that should move
*/
- void _moveStreamsAndSort(const uint32_t numStreamsToMove);
+ void _moveStreamsAndSort(uint32_t numStreamsToMove);
/**
* let the first numStreamsToMove streams in the stream
@@ -106,7 +115,7 @@ private:
* @param desiredDocId desired doc id
*
*/
- void _moveStreamsToDocAndSort(const uint32_t numStreamsToMove, const docid_t desiredDocId);
+ void _moveStreamsToDocAndSort(uint32_t numStreamsToMove, docid_t desiredDocId);
/**
* do sort and merge for WAND
@@ -115,18 +124,18 @@ private:
* be sorted and then merge sort with the rest
*
*/
- void _sortMerge(const uint32_t numStreamsToSort);
+ void _sortMerge(uint32_t numStreamsToSort);
public:
RiseWand(const Terms &terms, uint32_t n);
- ~RiseWand();
+ ~RiseWand() override;
void next();
void doSeek(uint32_t docid) override;
void doUnpack(uint32_t docid) override;
};
-using TermFrequencyRiseWand = RiseWand<TermFreqScorer, std::greater_equal<uint64_t> >;
-using DotProductRiseWand = RiseWand<DotProductScorer, std::greater<uint64_t> >;
+using TermFrequencyRiseWand = RiseWand<TermFreqScorer, std::greater_equal<> >;
+using DotProductRiseWand = RiseWand<DotProductScorer, std::greater<> >;
} // namespacve rise
diff --git a/searchlib/src/tests/queryeval/weak_and/rise_wand.hpp b/searchlib/src/tests/queryeval/weak_and/rise_wand.hpp
index 32e17014f98..c477be5cc62 100644
--- a/searchlib/src/tests/queryeval/weak_and/rise_wand.hpp
+++ b/searchlib/src/tests/queryeval/weak_and/rise_wand.hpp
@@ -19,6 +19,7 @@ RiseWand<Scorer, Cmp>::RiseWand(const Terms &terms, uint32_t n)
_streamIndices(new uint16_t[terms.size()]),
_streamIndicesAux(new uint16_t[terms.size()]),
_streamComparator(_streamDocIds),
+ _scorer(),
_n(n),
_limit(1),
_streamScores(new score_t[terms.size()]),
@@ -26,7 +27,7 @@ RiseWand<Scorer, Cmp>::RiseWand(const Terms &terms, uint32_t n)
_terms(terms)
{
for (size_t i = 0; i < terms.size(); ++i) {
- _terms[i].maxScore = Scorer::calculateMaxScore(terms[i]);
+ _terms[i].maxScore = _scorer.calculateMaxScore(terms[i]);
_streamScores[i] = _terms[i].maxScore;
_streams.push_back(terms[i].search);
}
@@ -46,8 +47,8 @@ RiseWand<Scorer, Cmp>::RiseWand(const Terms &terms, uint32_t n)
template <typename Scorer, typename Cmp>
RiseWand<Scorer, Cmp>::~RiseWand()
{
- for (size_t i = 0; i < _streams.size(); ++i) {
- delete _streams[i];
+ for (auto * stream : _streams) {
+ delete stream;
}
delete [] _streamScores;
delete [] _streamIndicesAux;
@@ -137,8 +138,7 @@ RiseWand<Scorer, Cmp>::_moveStreamsAndSort(const uint32_t numStreamsToMove)
template <typename Scorer, typename Cmp>
void
-RiseWand<Scorer, Cmp>::_moveStreamsToDocAndSort(const uint32_t numStreamsToMove,
- const docid_t desiredDocId)
+RiseWand<Scorer, Cmp>::_moveStreamsToDocAndSort(const uint32_t numStreamsToMove, const docid_t desiredDocId)
{
for (uint32_t i=0; i<numStreamsToMove; ++i) {
_streams[_streamIndices[i]]->seek(desiredDocId);
@@ -195,7 +195,7 @@ RiseWand<Scorer, Cmp>::doUnpack(uint32_t docid)
{
score_t score = 0;
for (size_t i = 0; i <= _lastPivotIdx; ++i) {
- score += Scorer::calculateScore(_terms[_streamIndices[i]], docid);
+ score += _scorer.calculateScore(_terms[_streamIndices[i]], docid);
}
if (_scores.size() < _n || _scores.front() < score) {
_scores.push(score);
@@ -208,28 +208,5 @@ RiseWand<Scorer, Cmp>::doUnpack(uint32_t docid)
}
}
-/**
- ************ BEGIN STREAM COMPARTOR *********************
- */
-template <typename Scorer, typename Cmp>
-RiseWand<Scorer, Cmp>::StreamComparator::StreamComparator(
- const docid_t *streamDocIds)
- : _streamDocIds(streamDocIds)
-{
-}
-
-template <typename Scorer, typename Cmp>
-inline bool
-RiseWand<Scorer, Cmp>::StreamComparator::operator()(const uint16_t a,
- const uint16_t b)
-{
- if (_streamDocIds[a] < _streamDocIds[b]) return true;
- return false;
-}
-
-/**
- ************ END STREAM COMPARTOR *********************
- */
-
} // namespace rise