From 723f2ae4228a82692831af2682942e701be7aa16 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Mon, 18 May 2020 18:31:44 +0000 Subject: - Handle more than 64k hits in the element vector. - Avoid computing all vectors in full separately and instead do an incremental inline merge with. - Also avoid requiring the searchiterator aspect on the wrappers. --- .../attribute/searchcontext/searchcontext_test.cpp | 94 ++++++++++------------ 1 file changed, 42 insertions(+), 52 deletions(-) (limited to 'searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp') diff --git a/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp b/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp index 416ddb5fbc0..ffae7824668 100644 --- a/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp +++ b/searchlib/src/tests/attribute/searchcontext/searchcontext_test.cpp @@ -1,12 +1,9 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include #include #include -#include -#include +#include #include -#include #include #include #include @@ -22,6 +19,7 @@ #include #include #include +#include #include LOG_SETUP("searchcontext_test"); @@ -628,29 +626,24 @@ void SearchContextTest::testSearch(const ConfigMap & cfgs) { template class Verifier : public search::test::SearchIteratorVerifier { public: - Verifier(const std::vector & keys, const vespalib::string & keyAsString, const vespalib::string & name, - const Config & cfg, bool withElementId); + Verifier(const std::vector & keys, const vespalib::string & keyAsString, + const vespalib::string & name, const Config & cfg); ~Verifier() override; SearchIterator::UP create(bool strict) const override { _sc->fetchPostings(queryeval::ExecuteInfo::create(strict, 1.0)); - auto search = _sc->createIterator(&_dummy, strict); - if (_withElementId) { - search = std::make_unique(std::move(search), *_sc, _dummy); - } - return search; + return _sc->createIterator(&_dummy, strict); } private: mutable TermFieldMatchData _dummy; - const bool _withElementId; AttributePtr _attribute; SearchContextPtr _sc; }; template -Verifier::Verifier(const std::vector & keys, const vespalib::string & keyAsString, const vespalib::string & name, - const Config & cfg, bool withElementId) - : _withElementId(withElementId), +Verifier::Verifier(const std::vector & keys, const vespalib::string & keyAsString, + const vespalib::string & name, const Config & cfg) + : _dummy(), _attribute(AttributeFactory::createAttribute(name + "-initrange", cfg)), _sc() { @@ -670,22 +663,18 @@ Verifier::~Verifier() = default; template void SearchContextTest::testSearchIterator(const std::vector & keys, const vespalib::string &keyAsString, const ConfigMap &cfgs) { - - for (bool withElementId : {false, true} ) { - for (const auto & cfg : cfgs) { - { - Verifier verifier(keys, keyAsString, cfg.first, cfg.second, withElementId); - verifier.verify(); - } - { - Config withFilter(cfg.second); - withFilter.setIsFilter(true); - Verifier verifier(keys, keyAsString, cfg.first + "-filter", withFilter, withElementId); - verifier.verify(); - } + for (const auto & cfg : cfgs) { + { + Verifier verifier(keys, keyAsString, cfg.first, cfg.second); + verifier.verify(); + } + { + Config withFilter(cfg.second); + withFilter.setIsFilter(true); + Verifier verifier(keys, keyAsString, cfg.first + "-filter", withFilter); + verifier.verify(); } } - } void SearchContextTest::testSearchIteratorConformance() { @@ -976,11 +965,13 @@ SearchContextTest::testSearchIteratorUnpacking(const AttributePtr & attr, Search pos.setElementWeight(100); md.appendPosition(pos); - SearchBasePtr sb = sc.createIterator(&md, strict); + SearchBasePtr sbp = sc.createIterator(&md, strict); + SearchIterator & search = *sbp; + queryeval::ElementIterator::UP elemIt; if (withElementId) { - sb = std::make_unique(std::move(sb), sc, md); + elemIt = std::make_unique(std::move(sbp), sc); } - sb->initFullRange(); + search.initFullRange(); std::vector weights(3); if (attr->getCollectionType() == CollectionType::SINGLE || @@ -1000,41 +991,40 @@ SearchContextTest::testSearchIteratorUnpacking(const AttributePtr & attr, Search } // unpack and check weights - sb->unpack(1); - EXPECT_EQUAL(sb->getDocId(), 1u); + search.unpack(1); + EXPECT_EQUAL(search.getDocId(), 1u); EXPECT_EQUAL(md.getDocId(), 1u); EXPECT_EQUAL(md.getWeight(), weights[0]); - sb->unpack(2); - EXPECT_EQUAL(sb->getDocId(), 2u); + search.unpack(2); + EXPECT_EQUAL(search.getDocId(), 2u); EXPECT_EQUAL(md.getDocId(), 2u); if (withElementId && attr->hasMultiValue() && !attr->hasWeightedSetType()) { - EXPECT_EQUAL(2, md.end()- md.begin()); - EXPECT_EQUAL(md.begin()[0].getElementId(), 0u); - EXPECT_EQUAL(md.begin()[0].getElementWeight(), 1); - EXPECT_EQUAL(md.begin()[1].getElementId(), 1u); - EXPECT_EQUAL(md.begin()[1].getElementWeight(), 1); + std::vector elems; + elemIt->getElementIds(2, elems); + ASSERT_EQUAL(2u, elems.size()); + EXPECT_EQUAL(0u,elems[0]); + EXPECT_EQUAL(1u,elems[1]); } else { EXPECT_EQUAL(md.getWeight(), weights[1]); } - sb->unpack(3); - EXPECT_EQUAL(sb->getDocId(), 3u); + search.unpack(3); + EXPECT_EQUAL(search.getDocId(), 3u); EXPECT_EQUAL(md.getDocId(), 3u); if (withElementId && attr->hasMultiValue() && !attr->hasWeightedSetType()) { - EXPECT_EQUAL(3, md.end()- md.begin()); - EXPECT_EQUAL(md.begin()[0].getElementId(), 0u); - EXPECT_EQUAL(md.begin()[0].getElementWeight(), 1); - EXPECT_EQUAL(md.begin()[1].getElementId(), 1u); - EXPECT_EQUAL(md.begin()[1].getElementWeight(), 1); - EXPECT_EQUAL(md.begin()[2].getElementId(), 2u); - EXPECT_EQUAL(md.begin()[2].getElementWeight(), 1); + std::vector elems; + elemIt->getElementIds(3, elems); + ASSERT_EQUAL(3u, elems.size()); + EXPECT_EQUAL(0u,elems[0]); + EXPECT_EQUAL(1u,elems[1]); + EXPECT_EQUAL(2u,elems[2]); } else { EXPECT_EQUAL(md.getWeight(), weights[2]); } if (extra) { - sb->unpack(4); - EXPECT_EQUAL(sb->getDocId(), 4u); + search.unpack(4); + EXPECT_EQUAL(search.getDocId(), 4u); EXPECT_EQUAL(md.getDocId(), 4u); EXPECT_EQUAL(md.getWeight(), 1); } -- cgit v1.2.3