diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-02-03 00:05:55 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-02-03 14:51:09 +0100 |
commit | b5bd5ab87541f18cd7e377e841557c84aaa15a5f (patch) | |
tree | b9bae9ac59d4fce13c15bc427f676e38f6ae1ca4 /searchlib | |
parent | 981a211fc074198c4e13b5af41aa3e076d7df43f (diff) |
Use the iterator verifier for weak and too.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/attribute/searchcontext/searchcontext.cpp | 78 |
1 files changed, 41 insertions, 37 deletions
diff --git a/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp b/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp index 6c69e79a93b..da53d48c2b1 100644 --- a/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp +++ b/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp @@ -1,37 +1,27 @@ // 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/log/log.h> #include <vespa/searchlib/attribute/attribute.h> #include <vespa/searchlib/attribute/attributefactory.h> #include <vespa/searchlib/attribute/attributeiterators.h> #include <vespa/searchlib/attribute/flagattribute.h> #include <vespa/searchlib/attribute/singlenumericattribute.h> -#include <vespa/searchlib/attribute/multinumericattribute.h> #include <vespa/searchlib/attribute/singlestringattribute.h> #include <vespa/searchlib/attribute/multistringattribute.h> #include <vespa/searchlib/common/bitvectoriterator.h> #include <vespa/searchlib/fef/matchdata.h> -#include <vespa/searchlib/fef/termfieldmatchdata.h> #include <vespa/searchlib/fef/termfieldmatchdataarray.h> -#include <vespa/searchlib/fef/termfieldmatchdataposition.h> -#include <vespa/searchlib/queryeval/searchiterator.h> -#include <vespa/searchlib/queryeval/emptysearch.h> #include <vespa/searchlib/queryeval/hitcollector.h> #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/compress.h> -#include <vespa/vespalib/stllike/asciistream.h> -#include <vespa/searchlib/test/initrange.h> -#include <iterator> -#include <set> +#include <vespa/searchlib/test/searchiteratorverifier.h> #include <vespa/searchlib/attribute/attributevector.hpp> +#include <vespa/log/log.h> LOG_SETUP("searchcontext_test"); namespace search { -namespace -{ +namespace { bool isUnsignedSmallIntAttribute(const AttributeVector &a) @@ -105,6 +95,12 @@ public: class SearchContextTest : public vespalib::TestApp { +public: + // helper functions + static void addReservedDoc(AttributeVector &ptr); + static void addDocs(AttributeVector & ptr, uint32_t numDocs); + template <typename V, typename T> + static SearchContextPtr getSearch(const V & vec, const T & term, QueryTermSimple::SearchTerm termType=QueryTermSimple::WORD); private: typedef std::map<vespalib::string, Config> ConfigMap; // Map of all config objects @@ -113,11 +109,6 @@ private: ConfigMap _stringCfg; - // helper functions - void - addReservedDoc(AttributeVector &ptr); - - void addDocs(AttributeVector & ptr, uint32_t numDocs); template <typename T> void fillVector(std::vector<T> & values, size_t numValues); template <typename V, typename T> @@ -128,10 +119,9 @@ private: void fillPostingList(PostingList<V, T> & pl, const DocRange & range); template <typename V, typename T> void fillPostingList(PostingList<V, T> & pl); - void buildTermQuery(std::vector<char> & buffer, const vespalib::string & index, const vespalib::string & term, - QueryTermSimple::SearchTerm termType=QueryTermSimple::WORD); - template <typename V, typename T> - SearchContextPtr getSearch(const V & vec, const T & term, QueryTermSimple::SearchTerm termType=QueryTermSimple::WORD); + static void buildTermQuery(std::vector<char> & buffer, const vespalib::string & index, const vespalib::string & term, + QueryTermSimple::SearchTerm termType=QueryTermSimple::WORD); + ResultSetPtr performSearch(SearchIterator & sb, uint32_t numDocs); template <typename V, typename T> ResultSetPtr performSearch(const V & vec, const T & term, QueryTermSimple::SearchTerm termType=QueryTermSimple::WORD); @@ -612,25 +602,39 @@ void SearchContextTest::testSearch(const ConfigMap & cfgs) { } } -using search::test::InitRangeVerifier; + +template<typename T, typename A> +class Verifier : public search::test::SearchIteratorVerifier { +public: + Verifier(T key, const vespalib::string & keyAsString, const vespalib::string & name, const Config & cfg) : + _attribute(AttributeFactory::createAttribute(name + "-initrange", cfg)), + _sc() + { + SearchContextTest::addDocs(*_attribute, getDocIdLimit()); + for (uint32_t doc : getExpectedDocIds()) { + EXPECT_TRUE(nullptr != dynamic_cast<A *>(_attribute.get())); + EXPECT_TRUE(dynamic_cast<A *>(_attribute.get())->update(doc, key)); + } + _attribute->commit(true); + _sc = SearchContextTest::getSearch(*_attribute, keyAsString); + ASSERT_TRUE(_sc->valid()); + _sc->fetchPostings(true); + } + SearchIterator::UP create(bool strict) const override { + return _sc->createIterator(&_dummy, strict); + } +private: + mutable TermFieldMatchData _dummy; + AttributePtr _attribute; + SearchContextPtr _sc; +}; template<typename T, typename A> void SearchContextTest::testInitRange(T key, const vespalib::string & keyAsString, const ConfigMap & cfgs) { - InitRangeVerifier ir; + for (const auto & cfg : cfgs) { - AttributePtr attribute = AttributeFactory::createAttribute(cfg.first + "-initrange", cfg.second); - addDocs(*attribute, ir.getDocIdLimit()); - for (uint32_t doc : ir.getExpectedDocIds()) { - EXPECT_TRUE(nullptr != dynamic_cast<A *>(attribute.get())); - EXPECT_TRUE(dynamic_cast<A *>(attribute.get())->update(doc, key)); - } - attribute->commit(true); - SearchContextPtr sc = getSearch(*attribute, keyAsString); - ASSERT_TRUE(sc->valid()); - sc->fetchPostings(true); - TermFieldMatchData dummy; - SearchBasePtr sb = sc->createIterator(&dummy, true); - ir.verify(*sb); + Verifier<T, A> verifier(key, keyAsString, cfg.first, cfg.second); + verifier.verify(); } } |