aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-10-04 14:37:19 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-10-08 07:02:03 +0000
commit0b3af78f01fca7fc0c1b1ccf10fec2f26cf4448b (patch)
tree3fbfe7eb3cba07ed264aa6504559c18b5d31547c /searchsummary
parent09a59e25ad2bc2b1e378c8e059e2a8be80f0aac5 (diff)
Move StructFields class to separate files and rename to StructFieldsResolver.
Diffstat (limited to 'searchsummary')
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt1
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp84
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/struct_fields_resolver.cpp64
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/struct_fields_resolver.h32
4 files changed, 101 insertions, 80 deletions
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt b/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt
index fb6a399e71c..6d846a47d93 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt
+++ b/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt
@@ -22,6 +22,7 @@ vespa_add_library(searchsummary_docsummary OBJECT
resultconfig.cpp
resultpacker.cpp
searchdatatype.cpp
+ struct_fields_resolver.cpp
struct_map_attribute_combiner_dfw.cpp
summaryfeaturesdfw.cpp
summaryfieldconverter.cpp
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp
index 69296509a85..db6ffc0f80d 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp
@@ -1,95 +1,19 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include "attribute_combiner_dfw.h"
#include "array_attribute_combiner_dfw.h"
-#include "struct_map_attribute_combiner_dfw.h"
+#include "attribute_combiner_dfw.h"
#include "docsum_field_writer_state.h"
#include "docsumstate.h"
-#include <vespa/searchlib/attribute/attributeguard.h>
-#include <vespa/searchlib/attribute/attributevector.h>
-#include <vespa/searchlib/attribute/iattributemanager.h>
+#include "struct_fields_resolver.h"
+#include "struct_map_attribute_combiner_dfw.h"
#include <vespa/searchlib/common/struct_field_mapper.h>
#include <algorithm>
#include <vespa/log/log.h>
LOG_SETUP(".searchsummary.docsummary.attribute_combiner_dfw");
-using search::AttributeGuard;
-using search::AttributeVector;
-using search::attribute::CollectionType;
-
namespace search::docsummary {
-namespace {
-
-class StructFields
-{
- std::vector<vespalib::string> _mapFields;
- std::vector<vespalib::string> _arrayFields;
- bool _hasMapKey;
- bool _error;
-
-public:
- StructFields(const vespalib::string &fieldName, const IAttributeManager &attrMgr);
- ~StructFields();
- const std::vector<vespalib::string> &getMapFields() const { return _mapFields; }
- const std::vector<vespalib::string> &getArrayFields() const { return _arrayFields; }
- bool hasMapKey() const { return _hasMapKey; }
- bool getError() const { return _error; }
-};
-
-
-StructFields::StructFields(const vespalib::string &fieldName, const IAttributeManager &attrMgr)
- : _mapFields(),
- _arrayFields(),
- _hasMapKey(false),
- _error(false)
-{
- std::vector<const search::attribute::IAttributeVector *> attrs;
- auto attrCtx = attrMgr.createContext();
- attrCtx->getAttributeList(attrs);
- vespalib::string prefix = fieldName + ".";
- vespalib::string keyName = prefix + "key";
- vespalib::string valuePrefix = prefix + "value.";
- for (const auto attr : attrs) {
- vespalib::string name = attr->getName();
- if (name.substr(0, prefix.size()) != prefix) {
- continue;
- }
- auto collType = attr->getCollectionType();
- if (collType != CollectionType::Type::ARRAY) {
- LOG(warning, "Attribute %s is not an array attribute", name.c_str());
- _error = true;
- break;
- }
- if (name.substr(0, valuePrefix.size()) == valuePrefix) {
- _mapFields.emplace_back(name.substr(valuePrefix.size()));
- } else {
- _arrayFields.emplace_back(name.substr(prefix.size()));
- if (name == keyName) {
- _hasMapKey = true;
- }
- }
- }
- if (!_error) {
- std::sort(_arrayFields.begin(), _arrayFields.end());
- std::sort(_mapFields.begin(), _mapFields.end());
- if (!_mapFields.empty()) {
- if (!_hasMapKey) {
- LOG(warning, "Missing key attribute '%s', have value attributes for map", keyName.c_str());
- _error = true;
- } else if (_arrayFields.size() != 1u) {
- LOG(warning, "Could not determine if field '%s' is array or map of struct", fieldName.c_str());
- _error = true;
- }
- }
- }
-}
-
-StructFields::~StructFields() = default;
-
-}
-
AttributeCombinerDFW::AttributeCombinerDFW(const vespalib::string &fieldName, bool filter_elements, std::shared_ptr<StructFieldMapper> struct_field_mapper)
: ISimpleDFW(),
_stateIndex(0),
@@ -117,7 +41,7 @@ AttributeCombinerDFW::setFieldWriterStateIndex(uint32_t fieldWriterStateIndex)
std::unique_ptr<IDocsumFieldWriter>
AttributeCombinerDFW::create(const vespalib::string &fieldName, IAttributeManager &attrMgr, bool filter_elements, std::shared_ptr<StructFieldMapper> struct_field_mapper)
{
- StructFields structFields(fieldName, attrMgr);
+ StructFieldsResolver structFields(fieldName, attrMgr);
if (structFields.getError()) {
return std::unique_ptr<IDocsumFieldWriter>();
} else if (!structFields.getMapFields().empty()) {
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/struct_fields_resolver.cpp b/searchsummary/src/vespa/searchsummary/docsummary/struct_fields_resolver.cpp
new file mode 100644
index 00000000000..4333861f0b2
--- /dev/null
+++ b/searchsummary/src/vespa/searchsummary/docsummary/struct_fields_resolver.cpp
@@ -0,0 +1,64 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "struct_fields_resolver.h"
+#include <vespa/searchlib/attribute/iattributemanager.h>
+#include <algorithm>
+
+#include <vespa/log/log.h>
+LOG_SETUP(".searchsummary.docsummary.struct_fields_resolver");
+
+using search::attribute::CollectionType;
+
+namespace search::docsummary {
+
+StructFieldsResolver::StructFieldsResolver(const vespalib::string& fieldName, const IAttributeManager& attrMgr)
+ : _mapFields(),
+ _arrayFields(),
+ _hasMapKey(false),
+ _error(false)
+{
+ std::vector<const search::attribute::IAttributeVector *> attrs;
+ auto attrCtx = attrMgr.createContext();
+ attrCtx->getAttributeList(attrs);
+ vespalib::string prefix = fieldName + ".";
+ vespalib::string keyName = prefix + "key";
+ vespalib::string valuePrefix = prefix + "value.";
+ for (const auto attr : attrs) {
+ vespalib::string name = attr->getName();
+ if (name.substr(0, prefix.size()) != prefix) {
+ continue;
+ }
+ auto collType = attr->getCollectionType();
+ if (collType != CollectionType::Type::ARRAY) {
+ LOG(warning, "Attribute %s is not an array attribute", name.c_str());
+ _error = true;
+ break;
+ }
+ if (name.substr(0, valuePrefix.size()) == valuePrefix) {
+ _mapFields.emplace_back(name.substr(valuePrefix.size()));
+ } else {
+ _arrayFields.emplace_back(name.substr(prefix.size()));
+ if (name == keyName) {
+ _hasMapKey = true;
+ }
+ }
+ }
+ if (!_error) {
+ std::sort(_arrayFields.begin(), _arrayFields.end());
+ std::sort(_mapFields.begin(), _mapFields.end());
+ if (!_mapFields.empty()) {
+ if (!_hasMapKey) {
+ LOG(warning, "Missing key attribute '%s', have value attributes for map", keyName.c_str());
+ _error = true;
+ } else if (_arrayFields.size() != 1u) {
+ LOG(warning, "Could not determine if field '%s' is array or map of struct", fieldName.c_str());
+ _error = true;
+ }
+ }
+ }
+}
+
+StructFieldsResolver::~StructFieldsResolver() = default;
+
+}
+
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/struct_fields_resolver.h b/searchsummary/src/vespa/searchsummary/docsummary/struct_fields_resolver.h
new file mode 100644
index 00000000000..5708f4f940c
--- /dev/null
+++ b/searchsummary/src/vespa/searchsummary/docsummary/struct_fields_resolver.h
@@ -0,0 +1,32 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/vespalib/stllike/string.h>
+#include <vector>
+
+namespace search { class IAttributeManager; }
+
+namespace search::docsummary {
+
+/**
+ * Class used to resolve which struct sub fields a complex field consists of,
+ * based on which attribute vectors are present.
+ */
+class StructFieldsResolver {
+private:
+ std::vector<vespalib::string> _mapFields;
+ std::vector<vespalib::string> _arrayFields;
+ bool _hasMapKey;
+ bool _error;
+
+public:
+ StructFieldsResolver(const vespalib::string& fieldName, const IAttributeManager& attrMgr);
+ ~StructFieldsResolver();
+ const std::vector<vespalib::string>& getMapFields() const { return _mapFields; }
+ const std::vector<vespalib::string>& getArrayFields() const { return _arrayFields; }
+ bool getError() const { return _error; }
+};
+
+}
+