diff options
author | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2020-01-29 11:26:48 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2020-01-29 12:22:05 +0000 |
commit | bb74faa5f2e56c930db1ec06ebf912e5b316c087 (patch) | |
tree | 42860f1ae5821dea25b900270a5aa1721e4618e7 /searchlib/src/tests | |
parent | b525ae9930ce37017eec664fbc4a0e12258c3db0 (diff) |
Add ReadableAttributeVector accessor to IAttributeManager
Provides a unified interface for fetching both regular as well as
imported attributes. Exposing `ReadableAttributeVector` instead of
raw `AttributeVector` instances enforces that all access is done via
appropriate acquired read guards.
Refactor document selection processing code to use the new interface
in order to prepare for imported field support in selections.
Diffstat (limited to 'searchlib/src/tests')
3 files changed, 30 insertions, 0 deletions
diff --git a/searchlib/src/tests/attribute/attributemanager/attributemanager_test.cpp b/searchlib/src/tests/attribute/attributemanager/attributemanager_test.cpp index 62cde4d2c9c..7d09b2aa0b8 100644 --- a/searchlib/src/tests/attribute/attributemanager/attributemanager_test.cpp +++ b/searchlib/src/tests/attribute/attributemanager/attributemanager_test.cpp @@ -34,6 +34,7 @@ private: void testGuards(); void testConfigConvert(); void testContext(); + void can_get_readable_attribute_vector_by_name(); bool assertDataType(BT::Type exp, @@ -377,6 +378,21 @@ AttributeManagerTest::testContext() } } +void +AttributeManagerTest::can_get_readable_attribute_vector_by_name() +{ + auto attr = AttributeFactory::createAttribute("cool_attr", Config(BT::INT32, CT::SINGLE)); + // Ensure there's something to actually load, or fetching the attribute will throw. + attr->addDocs(64); + attr->commit(); + AttributeManager manager; + manager.add(attr); + auto av = manager.readable_attribute_vector("cool_attr"); + EXPECT_EQUAL(av.get(), static_cast<ReadableAttributeVector*>(attr.get())); + av = manager.readable_attribute_vector("uncool_attr"); + EXPECT_TRUE(av.get() == nullptr); +} + int AttributeManagerTest::Main() { TEST_INIT("attributemanager_test"); @@ -385,6 +401,7 @@ int AttributeManagerTest::Main() testGuards(); testConfigConvert(); testContext(); + can_get_readable_attribute_vector_by_name(); TEST_DONE(); } diff --git a/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp b/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp index 4818287b429..2eafeab20bd 100644 --- a/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp +++ b/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp @@ -123,6 +123,15 @@ public: return IAttributeContext::UP(); } + std::shared_ptr<attribute::ReadableAttributeVector> readable_attribute_vector(const string& name) const override { + if (name == field) { + return _attribute_vector; + } else if (name == other) { + return _other; + } + return {}; + } + void asyncForAttribute(const vespalib::string &name, std::unique_ptr<IAttributeFunctor> func) const override; }; diff --git a/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp b/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp index e9addae07b9..24be21f65ec 100644 --- a/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp +++ b/searchlib/src/tests/attribute/searchable/attributeblueprint_test.cpp @@ -100,6 +100,10 @@ public: void asyncForAttribute(const vespalib::string &, std::unique_ptr<IAttributeFunctor>) const override { assert(!"Not implemented"); } + + std::shared_ptr<attribute::ReadableAttributeVector> readable_attribute_vector(const string&) const override { + return _attribute_vector; + } }; constexpr uint32_t DOCID_LIMIT = 3; |