diff options
Diffstat (limited to 'searchlib/src/tests/queryeval/weak_and_scorers/weak_and_scorers_test.cpp')
-rw-r--r-- | searchlib/src/tests/queryeval/weak_and_scorers/weak_and_scorers_test.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/searchlib/src/tests/queryeval/weak_and_scorers/weak_and_scorers_test.cpp b/searchlib/src/tests/queryeval/weak_and_scorers/weak_and_scorers_test.cpp new file mode 100644 index 00000000000..2dec1762c27 --- /dev/null +++ b/searchlib/src/tests/queryeval/weak_and_scorers/weak_and_scorers_test.cpp @@ -0,0 +1,67 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/searchlib/fef/termfieldmatchdata.h> +#include <vespa/searchlib/queryeval/searchiterator.h> +#include <vespa/searchlib/queryeval/wand/wand_parts.h> + +using namespace search::queryeval; +using search::fef::TermFieldMatchData; +using search::fef::TermFieldMatchDataPosition; + +typedef wand::Term Term; + +struct TestIterator : public SearchIterator +{ + MinMaxPostingInfo _info; + int32_t _termWeight; + bool _useInfo; + TermFieldMatchData _tfmd; + uint32_t _unpackDocId; + + typedef std::unique_ptr<TestIterator> UP; + TestIterator(int32_t maxWeight, int32_t termWeight, bool useInfo) + : _info(0, maxWeight), + _termWeight(termWeight), + _useInfo(useInfo), + _unpackDocId(0) + {} + virtual void doSeek(uint32_t docId) { + (void) docId; + } + virtual void doUnpack(uint32_t docId) { + _unpackDocId = docId; + _tfmd.appendPosition(TermFieldMatchDataPosition(0, 0, _termWeight, 1)); + } + virtual const PostingInfo *getPostingInfo() const { + return (_useInfo ? &_info : NULL); + } + static UP create(int32_t maxWeight, int32_t termWeight, bool useInfo) { + return UP(new TestIterator(maxWeight, termWeight, useInfo)); + } +}; + +TEST("require that DotProductScorer calculates max score") +{ + TestIterator::UP itr = TestIterator::create(10, 0, true); + Term term(itr.get(), 5, 0); + EXPECT_EQUAL(50, wand::DotProductScorer::calculateMaxScore(term)); +} + +TEST("require that DotProductScorer uses default max weight when not available in search iterator") +{ + TestIterator::UP itr = TestIterator::create(10, 0, false); + Term term(itr.get(), 5, 0); + int64_t exp = (int64_t)5 * std::numeric_limits<int32_t>::max(); + EXPECT_EQUAL(exp, wand::DotProductScorer::calculateMaxScore(term)); +} + +TEST("require that DotProductScorer calculates term score") +{ + TestIterator::UP itr = TestIterator::create(0, 7, false); + Term term(itr.get(), 5, 0, &itr->_tfmd); + EXPECT_EQUAL(35, wand::DotProductScorer::calculateScore(term, 11)); + EXPECT_EQUAL(11u, itr->_unpackDocId); +} + +TEST_MAIN() { TEST_RUN_ALL(); } |