diff options
3 files changed, 22 insertions, 54 deletions
diff --git a/searchlib/src/tests/attribute/document_weight_iterator/document_weight_iterator_test.cpp b/searchlib/src/tests/attribute/document_weight_iterator/document_weight_iterator_test.cpp index c864877aec2..98e70fd6c1f 100644 --- a/searchlib/src/tests/attribute/document_weight_iterator/document_weight_iterator_test.cpp +++ b/searchlib/src/tests/attribute/document_weight_iterator/document_weight_iterator_test.cpp @@ -38,13 +38,7 @@ void add_docs(AttributeVector::SP attr_ptr, size_t limit = 1000) { template <typename ATTR, typename KEY> void set_doc(ATTR *attr, uint32_t docid, KEY key, int32_t weight) { attr->clearDoc(docid); - if (attr->hasWeightedSetType()) { - attr->append(docid, key, weight); - } else { - for (int32_t i(0); i < weight; i++) { - attr->append(docid, key, 1); - } - } + attr->append(docid, key, weight); attr->commit(); } @@ -62,13 +56,11 @@ void populate_string(AttributeVector::SP attr_ptr) { set_doc(attr, 7, "foo", 10); } -template<CollectionType::Type CT> struct LongFixture { AttributeVector::SP attr; const IDocumentWeightAttribute *api; - LongFixture() - : attr(make_attribute(BasicType::INT64, CollectionType::WSET, true)), - api(attr->asDocumentWeightAttribute()) + LongFixture() : attr(make_attribute(BasicType::INT64, CollectionType::WSET, true)), + api(attr->asDocumentWeightAttribute()) { ASSERT_TRUE(api != nullptr); add_docs(attr); @@ -76,16 +68,11 @@ struct LongFixture { } }; -using LongWsetFixture = LongFixture<CollectionType::WSET>; -using LongArrayFixture = LongFixture<CollectionType::ARRAY>; - -template<CollectionType::Type CT> struct StringFixture { AttributeVector::SP attr; const IDocumentWeightAttribute *api; - StringFixture() - : attr(make_attribute(BasicType::STRING, CT, true)), - api(attr->asDocumentWeightAttribute()) + StringFixture() : attr(make_attribute(BasicType::STRING, CollectionType::WSET, true)), + api(attr->asDocumentWeightAttribute()) { ASSERT_TRUE(api != nullptr); add_docs(attr); @@ -93,15 +80,10 @@ struct StringFixture { } }; -using StringWsetFixture = StringFixture<CollectionType::WSET>; -using StringArrayFixture = StringFixture<CollectionType::ARRAY>; - TEST("require that appropriate attributes support the document weight attribute interface") { EXPECT_TRUE(make_attribute(BasicType::INT32, CollectionType::WSET, true)->asDocumentWeightAttribute() != nullptr); EXPECT_TRUE(make_attribute(BasicType::INT64, CollectionType::WSET, true)->asDocumentWeightAttribute() != nullptr); EXPECT_TRUE(make_attribute(BasicType::STRING, CollectionType::WSET, true)->asDocumentWeightAttribute() != nullptr); - EXPECT_TRUE(make_attribute(BasicType::INT64, CollectionType::ARRAY, true)->asDocumentWeightAttribute() != nullptr); - EXPECT_TRUE(make_attribute(BasicType::STRING, CollectionType::ARRAY, true)->asDocumentWeightAttribute() != nullptr); } TEST("require that inappropriate attributes do not support the document weight attribute interface") { @@ -109,10 +91,12 @@ TEST("require that inappropriate attributes do not support the document weight a EXPECT_TRUE(make_attribute(BasicType::INT64, CollectionType::ARRAY, false)->asDocumentWeightAttribute() == nullptr); EXPECT_TRUE(make_attribute(BasicType::INT64, CollectionType::WSET, false)->asDocumentWeightAttribute() == nullptr); EXPECT_TRUE(make_attribute(BasicType::INT64, CollectionType::SINGLE, true)->asDocumentWeightAttribute() == nullptr); + EXPECT_TRUE(make_attribute(BasicType::INT64, CollectionType::ARRAY, true)->asDocumentWeightAttribute() == nullptr); EXPECT_TRUE(make_attribute(BasicType::STRING, CollectionType::SINGLE, false)->asDocumentWeightAttribute() == nullptr); EXPECT_TRUE(make_attribute(BasicType::STRING, CollectionType::ARRAY, false)->asDocumentWeightAttribute() == nullptr); EXPECT_TRUE(make_attribute(BasicType::STRING, CollectionType::WSET, false)->asDocumentWeightAttribute() == nullptr); EXPECT_TRUE(make_attribute(BasicType::STRING, CollectionType::SINGLE, true)->asDocumentWeightAttribute() == nullptr); + EXPECT_TRUE(make_attribute(BasicType::STRING, CollectionType::ARRAY, true)->asDocumentWeightAttribute() == nullptr); EXPECT_TRUE(make_attribute(BasicType::FLOAT, CollectionType::WSET, true)->asDocumentWeightAttribute() == nullptr); EXPECT_TRUE(make_attribute(BasicType::DOUBLE, CollectionType::WSET, true)->asDocumentWeightAttribute() == nullptr); } @@ -131,22 +115,12 @@ void verify_invalid_lookup(IDocumentWeightAttribute::LookupResult result) { EXPECT_EQUAL(0, result.max_weight); } -TEST_F("require that integer wset lookup works correctly", LongWsetFixture) { +TEST_F("require that integer lookup works correctly", LongFixture) { verify_valid_lookup(f1.api->lookup("111", f1.api->get_dictionary_snapshot())); verify_invalid_lookup(f1.api->lookup("222", f1.api->get_dictionary_snapshot())); } -TEST_F("require that integer array lookup works correctly", LongArrayFixture) { - verify_valid_lookup(f1.api->lookup("111", f1.api->get_dictionary_snapshot())); - verify_invalid_lookup(f1.api->lookup("222", f1.api->get_dictionary_snapshot())); -} - -TEST_F("require string wset lookup works correctly", StringWsetFixture) { - verify_valid_lookup(f1.api->lookup("foo", f1.api->get_dictionary_snapshot())); - verify_invalid_lookup(f1.api->lookup("bar", f1.api->get_dictionary_snapshot())); -} - -TEST_F("require string array lookup works correctly", StringArrayFixture) { +TEST_F("require string lookup works correctly", StringFixture) { verify_valid_lookup(f1.api->lookup("foo", f1.api->get_dictionary_snapshot())); verify_invalid_lookup(f1.api->lookup("bar", f1.api->get_dictionary_snapshot())); } @@ -178,23 +152,15 @@ void verify_posting(const IDocumentWeightAttribute &api, const char *term) { } } -TEST_F("require that integer wset iterators are created correctly", LongWsetFixture) { +TEST_F("require that integer iterators are created correctly", LongFixture) { verify_posting(*f1.api, "111"); } -TEST_F("require that integer array iterators are created correctly", LongArrayFixture) { - verify_posting(*f1.api, "111"); -} - -TEST_F("require that string wset iterators are created correctly", StringWsetFixture) { - verify_posting(*f1.api, "foo"); -} - -TEST_F("require that string array iterators are created correctly", StringArrayFixture) { +TEST_F("require that string iterators are created correctly", StringFixture) { verify_posting(*f1.api, "foo"); } -TEST_F("require that collect_folded works for string", StringWsetFixture) +TEST_F("require that collect_folded works for string", StringFixture) { StringAttribute *attr = static_cast<StringAttribute *>(f1.attr.get()); set_doc(attr, 2, "bar", 30); @@ -210,7 +176,7 @@ TEST_F("require that collect_folded works for string", StringWsetFixture) EXPECT_EQUAL(expected_folded, folded); } -TEST_F("require that collect_folded works for integers", LongWsetFixture) +TEST_F("require that collect_folded works for integers", LongFixture) { IntegerAttributeTemplate<int64_t> *attr = dynamic_cast<IntegerAttributeTemplate<int64_t> *>(f1.attr.get()); set_doc(attr, 2, int64_t(112), 30); @@ -251,7 +217,7 @@ Verifier::Verifier() set_doc(int_attr, docid, int64_t(123), 1); } } -Verifier::~Verifier() = default; +Verifier::~Verifier() {} TEST("verify document weight search iterator") { Verifier verifier; diff --git a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp index 67dcc992c58..f652a3b95b9 100644 --- a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp @@ -154,9 +154,10 @@ template <typename B, typename M> const IDocumentWeightAttribute * MultiValueNumericPostingAttribute<B, M>::asDocumentWeightAttribute() const { - return this->isIntegerType() - ? &_document_weight_attribute_adapter - : nullptr; + if (this->hasWeightedSetType() && this->isIntegerType()) { + return &_document_weight_attribute_adapter; + } + return nullptr; } } // namespace search diff --git a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp index c10b370d629..b8844583911 100644 --- a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp @@ -174,9 +174,10 @@ template <typename B, typename T> const IDocumentWeightAttribute * MultiValueStringPostingAttributeT<B, T>::asDocumentWeightAttribute() const { - return this->isStringType() - ? &_document_weight_attribute_adapter - : nullptr; + if (this->hasWeightedSetType() && (this->isStringType())) { + return &_document_weight_attribute_adapter; + } + return nullptr; } } // namespace search |