summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahoo-inc.com>2017-04-22 11:46:07 +0000
committerTor Egge <Tor.Egge@yahoo-inc.com>2017-04-22 11:46:07 +0000
commit6100db1650d36954134a56ed96521d6f230ccb83 (patch)
tree7f82bcecc3b14aad85653b07d2dea1bfc40d9949 /searchlib
parentc01dab23f28165116dab3da5e4da47f77fab7e0f (diff)
Handle missing attribute in attribute blueprint factory.
This can be caused by delaying addition of attribute aspect.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp21
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp3
2 files changed, 19 insertions, 5 deletions
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 a780cbbd229..8e624c2556a 100644
--- a/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp
+++ b/searchlib/src/tests/attribute/searchable/attribute_searchable_adapter_test.cpp
@@ -219,24 +219,29 @@ Result do_search(IAttributeManager &attribute_manager, const Node &node, bool st
}
bool search(const Node &node, IAttributeManager &attribute_manager,
- bool fast_search = false, bool strict = true)
+ bool fast_search = false, bool strict = true, bool empty = false)
{
Result result = do_search(attribute_manager, node, strict);
if (fast_search) {
EXPECT_LESS(result.est_hits, num_docs / 10);
} else {
- EXPECT_TRUE(!result.est_empty);
- EXPECT_EQUAL(num_docs, result.est_hits);
+ if (empty) {
+ EXPECT_TRUE(result.est_empty);
+ EXPECT_EQUAL(0, result.est_hits);
+ } else {
+ EXPECT_TRUE(!result.est_empty);
+ EXPECT_EQUAL(num_docs, result.est_hits);
+ }
}
return (result.hits.size() == 1) && (result.hits[0].docid == (num_docs - 1));
}
bool search(const string &term, IAttributeManager &attribute_manager,
- bool fast_search = false, bool strict = true)
+ bool fast_search = false, bool strict = true, bool empty = false)
{
TEST_STATE(term.c_str());
SimpleStringTerm node(term, "field", 0, Weight(0));
- return search(node, attribute_manager, fast_search, strict);
+ return search(node, attribute_manager, fast_search, strict, empty);
}
template <typename T> struct AttributeVectorTypeFinder {
@@ -287,6 +292,12 @@ TEST("requireThatIteratorsCanBeCreated") {
EXPECT_TRUE(search("foo", attribute_manager));
}
+TEST("require that missing attribute produces empty search")
+{
+ MyAttributeManager attribute_manager(nullptr);
+ EXPECT_FALSE(search("foo", attribute_manager, false, false, true));
+}
+
TEST("requireThatRangeTermsWorkToo") {
MyAttributeManager attribute_manager = makeAttributeManager(int64_t(42));
diff --git a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp
index b143c33eed1..8779b850886 100644
--- a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp
@@ -613,6 +613,9 @@ AttributeBlueprintFactory::createBlueprint(const IRequestContext & requestContex
const search::query::Node &term)
{
const IAttributeVector *attr(requestContext.getAttribute(field.getName()));
+ if (attr == nullptr) {
+ return std::make_unique<queryeval::EmptyBlueprint>(field);
+ }
CreateBlueprintVisitor visitor(*this, requestContext, field, *attr);
const_cast<Node &>(term).accept(visitor);
return visitor.getResult();