1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#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) override {
(void) docId;
}
virtual void doUnpack(uint32_t docId) override {
_unpackDocId = docId;
_tfmd.appendPosition(TermFieldMatchDataPosition(0, 0, _termWeight, 1));
}
virtual const PostingInfo *getPostingInfo() const override {
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(); }
|