diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-10 09:48:37 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-10 09:48:37 +0000 |
commit | d839b8a1652ceecf091c41fcb9f4041fc5259d81 (patch) | |
tree | 9885923a86664729b17d4898d8111e132c3683a0 /searchlib | |
parent | f77006746634b570aac00847c2ebe426c5e40808 (diff) |
BitVectorSearchContext must implement the find iterface too. Even if itself will only produce a BitVectorIterator when invoked directly,
it has no control on how it is used when imported into a child.
Diffstat (limited to 'searchlib')
3 files changed, 37 insertions, 25 deletions
diff --git a/searchlib/src/tests/queryeval/getnodeweight/getnodeweight_test.cpp b/searchlib/src/tests/queryeval/getnodeweight/getnodeweight_test.cpp index 830093e7b5f..359a7f9c074 100644 --- a/searchlib/src/tests/queryeval/getnodeweight/getnodeweight_test.cpp +++ b/searchlib/src/tests/queryeval/getnodeweight/getnodeweight_test.cpp @@ -1,29 +1,24 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> -LOG_SETUP("getweight_test"); + #include <vespa/vespalib/testkit/testapp.h> #include <vespa/searchlib/query/tree/simplequery.h> #include <vespa/searchlib/queryeval/get_weight_from_node.h> +#include <vespa/log/log.h> +LOG_SETUP("getweight_test"); using namespace search::query; using namespace search::queryeval; -class Test : public vespalib::TestApp { -public: - int32_t getWeight(const Node &node); - int Main() override; -}; - -int32_t -Test::getWeight(const Node &node) { - return getWeightFromNode(node).percent(); +namespace { + int32_t + getWeight(const Node &node) { + return getWeightFromNode(node).percent(); + } } -int -Test::Main() +TEST("test variations of getWeight") { - TEST_INIT("getweight_test"); EXPECT_EQUAL(0, getWeight(SimpleAnd())); EXPECT_EQUAL(0, getWeight(SimpleAndNot())); EXPECT_EQUAL(42, getWeight(SimpleEquiv(0, Weight(42)))); @@ -42,7 +37,6 @@ Test::Main() EXPECT_EQUAL(42, getWeight(SimpleWeightedSetTerm("bar", 1, Weight(42)))); EXPECT_EQUAL(42, getWeight(SimpleDotProduct("bar", 1, Weight(42)))); EXPECT_EQUAL(42, getWeight(SimpleWandTerm("bar", 1, Weight(42), 57, 67, 77.7))); - TEST_DONE(); } -TEST_APPHOOK(Test); +TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchlib/src/tests/queryeval/queryeval.cpp b/searchlib/src/tests/queryeval/queryeval.cpp index 26e7095dd60..32dc9b1fa7e 100644 --- a/searchlib/src/tests/queryeval/queryeval.cpp +++ b/searchlib/src/tests/queryeval/queryeval.cpp @@ -2,7 +2,6 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/searchlib/test/initrange.h> -#include <vespa/searchlib/common/bitvectoriterator.h> #include <vespa/searchlib/queryeval/andnotsearch.h> #include <vespa/searchlib/queryeval/andsearch.h> #include <vespa/searchlib/queryeval/booleanmatchiteratorwrapper.h> @@ -27,7 +26,6 @@ LOG_SETUP("query_eval_test"); using namespace search::queryeval; using search::BitVector; -using search::BitVectorIterator; using search::attribute::SearchContextParams; using search::fef::MatchData; using search::fef::TermFieldMatchData; @@ -342,18 +340,35 @@ public: _sc = _a.getSearch(std::make_unique<search::QueryTermSimple>("1", search::QueryTermSimple::WORD), SearchContextParams().useBitVector(true)); } - virtual SearchIterator::UP + SearchIterator::UP createLeafSearch(const TermFieldMatchDataArray &tfmda, bool strict) const override { (void) tfmda; return _sc->createIterator(&_tfmd, strict); } + const search::AttributeVector::SearchContext & getSearchContext() const { return *_sc; } private: search::SingleBoolAttribute _a; search::AttributeVector::SearchContext::UP _sc; mutable TermFieldMatchData _tfmd; }; +TEST("test bool attribute searchcontext") { + SimpleResult a; + a.addHit(5).addHit(17).addHit(30); + auto bp = std::make_unique<DummySingleValueBitNumericAttributeBlueprint>(a); + const search::AttributeVector::SearchContext & sc = bp->getSearchContext(); + EXPECT_FALSE(sc.matches(7)); + EXPECT_TRUE(sc.matches(17)); + int32_t weight(0); + EXPECT_FALSE(sc.matches(7, weight)); + EXPECT_EQUAL(0, weight); + EXPECT_TRUE(sc.matches(17, weight)); + EXPECT_EQUAL(1, weight); + EXPECT_FALSE(sc.matches(27, weight)); + EXPECT_EQUAL(0, weight); +} + TEST("testAndNot") { { diff --git a/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp b/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp index e1277653b83..250182f924b 100644 --- a/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp +++ b/searchlib/src/vespa/searchlib/attribute/singleboolattribute.cpp @@ -112,14 +112,17 @@ private: bool _invert; bool _valid; bool valid() const override { return _valid; } - int32_t onFind(DocId , int32_t , int32_t & ) const override { - assert(false); - return -1; + int32_t onFind(DocId docId, int32_t elemId, int32_t & weight) const override final { + if ((elemId == 0) && _bv.testBit(docId)) { + weight = 1; + return 0; + } + weight = 0; + return -1; } - int32_t onFind(DocId , int32_t ) const override { - assert(false); - return -1; + int32_t onFind(DocId docId, int32_t elemId) const override final { + return ((elemId == 0) && _bv.testBit(docId)) ? 0 : -1; } public: |