summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/attribute/searchcontext
diff options
context:
space:
mode:
authorGeir Storli <geirst@oath.com>2018-06-25 11:29:26 +0000
committerGeir Storli <geirst@oath.com>2018-06-25 14:59:15 +0000
commitb39627aadd24b5274c8e793d921354b837fea628 (patch)
treeb2ca2b9aab5ffecbddab06bc93d8af8b5a68e7f9 /searchlib/src/tests/attribute/searchcontext
parentab61e5ea77c483c0fe4fb6a3f266bd47f590988a (diff)
Ensure that all attribute iterators expose the search context creating the iterator.
This ensures that also fast-search struct field attributes work together with the sameElement operator.
Diffstat (limited to 'searchlib/src/tests/attribute/searchcontext')
-rw-r--r--searchlib/src/tests/attribute/searchcontext/searchcontext.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp b/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp
index 77504c4ab3c..85492df7016 100644
--- a/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp
+++ b/searchlib/src/tests/attribute/searchcontext/searchcontext.cpp
@@ -266,6 +266,11 @@ private:
void requireThatOutOfBoundsSearchTermGivesZeroHits(const vespalib::string &name, const Config &cfg, int64_t maxValue);
void requireThatOutOfBoundsSearchTermGivesZeroHits();
+
+ template <typename AttributeType, typename ValueType>
+ void requireThatSearchIteratorExposesSearchContext(const ConfigMap &cfg, ValueType value, const vespalib::string &searchTerm);
+ void requireThatSearchIteratorExposesSearchContext();
+
// init maps with config objects
void initIntegerConfig();
void initFloatConfig();
@@ -1809,6 +1814,46 @@ SearchContextTest::requireThatOutOfBoundsSearchTermGivesZeroHits()
}
}
+void
+assertSearchIteratorExposesSearchContext(search::attribute::ISearchContext &ctx)
+{
+ ASSERT_TRUE(ctx.valid());
+ ctx.fetchPostings(true);
+ TermFieldMatchData dummy;
+ SearchBasePtr itr = ctx.createIterator(&dummy, true);
+ EXPECT_TRUE(itr->getAttributeSearchContext() != nullptr);
+ EXPECT_EQUAL(&ctx, itr->getAttributeSearchContext());
+}
+
+template <typename AttributeType, typename ValueType>
+void
+SearchContextTest::requireThatSearchIteratorExposesSearchContext(const ConfigMap &cfgMap,
+ ValueType value,
+ const vespalib::string &searchTerm)
+{
+ vespalib::string attrSuffix = "-itr-exposes-ctx";
+ std::vector<ValueType> values = {value};
+ for (const auto &cfg : cfgMap) {
+ vespalib::string attrName = cfg.first + attrSuffix;
+ AttributePtr attr = AttributeFactory::createAttribute(attrName, cfg.second);
+ addDocs(*attr, 2);
+ AttributeType &concreteAttr = dynamic_cast<AttributeType &>(*attr);
+ if (attr->hasMultiValue()) {
+ fillAttribute(concreteAttr, values);
+ } else {
+ resetAttribute(concreteAttr, value);
+ }
+ assertSearchIteratorExposesSearchContext(*getSearch(*attr, searchTerm));
+ }
+}
+
+void
+SearchContextTest::requireThatSearchIteratorExposesSearchContext()
+{
+ requireThatSearchIteratorExposesSearchContext<IntegerAttribute, largeint_t>(_integerCfg, 3, "3");
+ requireThatSearchIteratorExposesSearchContext<FloatingPointAttribute, double>(_floatCfg, 5.7, "5.7");
+ requireThatSearchIteratorExposesSearchContext<StringAttribute, vespalib::string>(_stringCfg, "foo", "foo");
+}
void
SearchContextTest::initIntegerConfig()
@@ -1940,6 +1985,7 @@ SearchContextTest::Main()
TEST_DO(requireThatInvalidSearchTermGivesZeroHits());
TEST_DO(requireThatFlagAttributeHandlesTheByteRange());
TEST_DO(requireThatOutOfBoundsSearchTermGivesZeroHits());
+ TEST_DO(requireThatSearchIteratorExposesSearchContext());
TEST_DONE();
}