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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Unit tests for predicate_interval_posting_list.
#include <vespa/log/log.h>
LOG_SETUP("predicate_interval_posting_list_test");
#include <vespa/fastos/fastos.h>
#include <vespa/searchlib/predicate/predicate_tree_annotator.h>
#include <vespa/searchlib/predicate/predicate_interval_posting_list.h>
#include <vespa/vespalib/testkit/testapp.h>
using namespace search;
using namespace search::predicate;
namespace {
struct DummyDocIdLimitProvider : public DocIdLimitProvider {
virtual uint32_t getDocIdLimit() const { return 10000; }
virtual uint32_t getCommittedDocIdLimit() const { return 10000; }
};
vespalib::GenerationHandler generation_handler;
vespalib::GenerationHolder generation_holder;
DummyDocIdLimitProvider limit_provider;
SimpleIndexConfig config;
const uint64_t hash = 0x123;
TEST("require that empty posting list starts at 0.") {
PredicateIndex index(generation_handler, generation_holder, limit_provider, config, 8);
btree::EntryRef ref;
PredicateIntervalPostingList<PredicateIndex::BTreeIterator>
posting_list(index.getIntervalStore(), index.getIntervalIndex().getBTreePostingList(ref));
EXPECT_EQUAL(0u, posting_list.getDocId());
EXPECT_EQUAL(0u, posting_list.getInterval());
EXPECT_FALSE(posting_list.next(0));
}
TEST("require that posting list can iterate.") {
PredicateIndex index(generation_handler, generation_holder, limit_provider, config, 8);
const auto &interval_index = index.getIntervalIndex();
for (uint32_t id = 1; id < 100; ++id) {
PredicateTreeAnnotations annotations(id);
auto &vec = annotations.interval_map[hash];
for (uint32_t i = 0; i < id; ++i) {
vec.push_back(Interval{(i + 1) << 16 | 0xffff});
}
index.indexDocument(id, annotations);
}
index.commit();
auto it = interval_index.lookup(hash);
ASSERT_TRUE(it.valid());
auto ref = it.getData();
PredicateIntervalPostingList<PredicateIndex::BTreeIterator>
posting_list(index.getIntervalStore(), interval_index.getBTreePostingList(ref));
EXPECT_EQUAL(0u, posting_list.getDocId());
EXPECT_EQUAL(0u, posting_list.getInterval());
EXPECT_TRUE(posting_list.next(0));
EXPECT_EQUAL(1u, posting_list.getDocId());
EXPECT_EQUAL(0x0001ffffu, posting_list.getInterval());
ASSERT_FALSE(posting_list.nextInterval());
ASSERT_TRUE(posting_list.next(1));
EXPECT_EQUAL(2u, posting_list.getDocId());
EXPECT_EQUAL(0x0001ffffu, posting_list.getInterval());
ASSERT_TRUE(posting_list.nextInterval());
EXPECT_EQUAL(0x0002ffffu, posting_list.getInterval());
ASSERT_FALSE(posting_list.nextInterval());
ASSERT_TRUE(posting_list.next(50));
EXPECT_EQUAL(51u, posting_list.getDocId());
for (uint32_t i = 0; i < 50; ++i) {
EXPECT_EQUAL((i + 1) << 16 | 0xffff, posting_list.getInterval());
ASSERT_TRUE(posting_list.nextInterval());
}
EXPECT_EQUAL(0x0033ffffu, posting_list.getInterval());
ASSERT_FALSE(posting_list.nextInterval());
}
} // namespace
TEST_MAIN() { TEST_RUN_ALL(); }
|