diff options
Diffstat (limited to 'searchsummary/src')
13 files changed, 63 insertions, 29 deletions
diff --git a/searchsummary/src/tests/docsummary/attribute_combiner/attribute_combiner_test.cpp b/searchsummary/src/tests/docsummary/attribute_combiner/attribute_combiner_test.cpp index 961acadeddf..a8c752582d5 100644 --- a/searchsummary/src/tests/docsummary/attribute_combiner/attribute_combiner_test.cpp +++ b/searchsummary/src/tests/docsummary/attribute_combiner/attribute_combiner_test.cpp @@ -9,6 +9,7 @@ #include <vespa/searchlib/attribute/integerbase.h> #include <vespa/searchlib/attribute/stringbase.h> #include <vespa/searchlib/common/matching_elements.h> +#include <vespa/searchlib/common/struct_field_mapper.h> #include <vespa/searchlib/util/slime_output_raw_buf_adapter.h> #include <vespa/searchsummary/docsummary/docsumstate.h> #include <vespa/searchsummary/docsummary/docsum_field_writer_state.h> @@ -165,7 +166,7 @@ public: void FillSummaryFeatures(GetDocsumsState *, IDocsumEnvironment *) override { } void FillRankFeatures(GetDocsumsState *, IDocsumEnvironment *) override { } void ParseLocation(GetDocsumsState *) override { } - std::unique_ptr<MatchingElements> fill_matching_elements() override { return std::make_unique<MatchingElements>(_matching_elements); } + std::unique_ptr<MatchingElements> fill_matching_elements(const search::StructFieldMapper &) override { return std::make_unique<MatchingElements>(_matching_elements); } ~DummyStateCallback() override { } }; @@ -211,7 +212,11 @@ AttributeCombinerTest::~AttributeCombinerTest() = default; void AttributeCombinerTest::set_field(const vespalib::string &field_name, bool filter_elements) { - writer = AttributeCombinerDFW::create(field_name, attrs.mgr, filter_elements); + std::shared_ptr<search::StructFieldMapper> struct_field_mapper; + if (filter_elements) { + struct_field_mapper = std::make_shared<search::StructFieldMapper>(); + } + writer = AttributeCombinerDFW::create(field_name, attrs.mgr, filter_elements, struct_field_mapper); EXPECT_TRUE(writer->setFieldWriterStateIndex(0)); state._fieldWriterStates.resize(1); } diff --git a/searchsummary/src/tests/docsummary/positionsdfw_test.cpp b/searchsummary/src/tests/docsummary/positionsdfw_test.cpp index 476891ca40f..b161958fc43 100644 --- a/searchsummary/src/tests/docsummary/positionsdfw_test.cpp +++ b/searchsummary/src/tests/docsummary/positionsdfw_test.cpp @@ -106,7 +106,7 @@ struct MyGetDocsumsStateCallback : GetDocsumsStateCallback { virtual void FillSummaryFeatures(GetDocsumsState *, IDocsumEnvironment *) override {} virtual void FillRankFeatures(GetDocsumsState *, IDocsumEnvironment *) override {} virtual void ParseLocation(GetDocsumsState *) override {} - std::unique_ptr<MatchingElements> fill_matching_elements() override { abort(); } + std::unique_ptr<MatchingElements> fill_matching_elements(const StructFieldMapper &) override { abort(); } }; template <typename AttrType> diff --git a/searchsummary/src/tests/docsummary/slime_summary/slime_summary_test.cpp b/searchsummary/src/tests/docsummary/slime_summary/slime_summary_test.cpp index c0d9ec2de3a..5b74666cbec 100644 --- a/searchsummary/src/tests/docsummary/slime_summary/slime_summary_test.cpp +++ b/searchsummary/src/tests/docsummary/slime_summary/slime_summary_test.cpp @@ -78,7 +78,7 @@ struct DocsumFixture : IDocsumStore, GetDocsumsStateCallback { void FillSummaryFeatures(GetDocsumsState *, IDocsumEnvironment *) override { } void FillRankFeatures(GetDocsumsState *, IDocsumEnvironment *) override { } void ParseLocation(GetDocsumsState *) override { } - std::unique_ptr<MatchingElements> fill_matching_elements() override { abort(); } + std::unique_ptr<MatchingElements> fill_matching_elements(const search::StructFieldMapper &) override { abort(); } }; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.cpp index 9d4d3829047..88be8aac8c5 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.cpp @@ -6,6 +6,7 @@ #include <vespa/searchcommon/attribute/iattributecontext.h> #include <vespa/searchcommon/attribute/iattributevector.h> #include <vespa/searchlib/common/matching_elements.h> +#include <vespa/searchlib/common/struct_field_mapper.h> #include <vespa/vespalib/data/slime/cursor.h> #include <cassert> @@ -100,8 +101,9 @@ ArrayAttributeFieldWriterState::insertField(uint32_t docId, vespalib::slime::Ins ArrayAttributeCombinerDFW::ArrayAttributeCombinerDFW(const vespalib::string &fieldName, const std::vector<vespalib::string> &fields, - bool filter_elements) - : AttributeCombinerDFW(fieldName, filter_elements), + bool filter_elements, + std::shared_ptr<StructFieldMapper> struct_field_mapper) + : AttributeCombinerDFW(fieldName, filter_elements, std::move(struct_field_mapper)), _fields(fields), _attributeNames() { @@ -110,6 +112,11 @@ ArrayAttributeCombinerDFW::ArrayAttributeCombinerDFW(const vespalib::string &fie for (const auto &field : _fields) { _attributeNames.emplace_back(prefix + field); } + if (filter_elements && _struct_field_mapper && !_struct_field_mapper->is_struct_field(fieldName)) { + for (const auto &sub_field : _attributeNames) { + _struct_field_mapper->add_mapping(fieldName, sub_field); + } + } } ArrayAttributeCombinerDFW::~ArrayAttributeCombinerDFW() = default; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.h index 15c3030c782..473bdbbc4e7 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.h @@ -23,7 +23,8 @@ class ArrayAttributeCombinerDFW : public AttributeCombinerDFW public: ArrayAttributeCombinerDFW(const vespalib::string &fieldName, const std::vector<vespalib::string> &fields, - bool filter_elements); + bool filter_elements, + std::shared_ptr<StructFieldMapper> struct_field_mapper); ~ArrayAttributeCombinerDFW() override; }; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp index ed053ce0115..69296509a85 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp @@ -8,6 +8,7 @@ #include <vespa/searchlib/attribute/attributeguard.h> #include <vespa/searchlib/attribute/attributevector.h> #include <vespa/searchlib/attribute/iattributemanager.h> +#include <vespa/searchlib/common/struct_field_mapper.h> #include <algorithm> #include <vespa/log/log.h> @@ -89,11 +90,12 @@ StructFields::~StructFields() = default; } -AttributeCombinerDFW::AttributeCombinerDFW(const vespalib::string &fieldName, bool filter_elements) +AttributeCombinerDFW::AttributeCombinerDFW(const vespalib::string &fieldName, bool filter_elements, std::shared_ptr<StructFieldMapper> struct_field_mapper) : ISimpleDFW(), _stateIndex(0), _filter_elements(filter_elements), - _fieldName(fieldName) + _fieldName(fieldName), + _struct_field_mapper(std::move(struct_field_mapper)) { } @@ -113,15 +115,15 @@ AttributeCombinerDFW::setFieldWriterStateIndex(uint32_t fieldWriterStateIndex) } std::unique_ptr<IDocsumFieldWriter> -AttributeCombinerDFW::create(const vespalib::string &fieldName, IAttributeManager &attrMgr, bool filter_elements) +AttributeCombinerDFW::create(const vespalib::string &fieldName, IAttributeManager &attrMgr, bool filter_elements, std::shared_ptr<StructFieldMapper> struct_field_mapper) { StructFields structFields(fieldName, attrMgr); if (structFields.getError()) { return std::unique_ptr<IDocsumFieldWriter>(); } else if (!structFields.getMapFields().empty()) { - return std::make_unique<StructMapAttributeCombinerDFW>(fieldName, structFields.getMapFields(), filter_elements); + return std::make_unique<StructMapAttributeCombinerDFW>(fieldName, structFields.getMapFields(), filter_elements, std::move(struct_field_mapper)); } - return std::make_unique<ArrayAttributeCombinerDFW>(fieldName, structFields.getArrayFields(), filter_elements); + return std::make_unique<ArrayAttributeCombinerDFW>(fieldName, structFields.getArrayFields(), filter_elements, std::move(struct_field_mapper)); } void @@ -131,7 +133,7 @@ AttributeCombinerDFW::insertField(uint32_t docid, GetDocsumsState *state, ResTyp if (!fieldWriterState) { const MatchingElements *matching_elements = nullptr; if (_filter_elements) { - matching_elements = &state->get_matching_elements(); + matching_elements = &state->get_matching_elements(*_struct_field_mapper); } fieldWriterState = allocFieldWriterState(*state->_attrCtx, matching_elements); } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h index ec806ba0ac6..3b7ab911956 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h @@ -4,7 +4,10 @@ #include "docsumfieldwriter.h" -namespace search { class MatchingElements; } +namespace search { +class MatchingElements; +class StructFieldMapper; +} namespace search::attribute { class IAttributeContext; } namespace search::docsummary { @@ -22,14 +25,15 @@ protected: uint32_t _stateIndex; const bool _filter_elements; vespalib::string _fieldName; - AttributeCombinerDFW(const vespalib::string &fieldName, bool filter_elements); + std::shared_ptr<StructFieldMapper> _struct_field_mapper; + AttributeCombinerDFW(const vespalib::string &fieldName, bool filter_elements, std::shared_ptr<StructFieldMapper> struct_field_mapper); protected: virtual std::unique_ptr<DocsumFieldWriterState> allocFieldWriterState(search::attribute::IAttributeContext &context, const MatchingElements* matching_elements) = 0; public: ~AttributeCombinerDFW() override; bool IsGenerated() const override; bool setFieldWriterStateIndex(uint32_t fieldWriterStateIndex) override; - static std::unique_ptr<IDocsumFieldWriter> create(const vespalib::string &fieldName, IAttributeManager &attrMgr, bool filter_elements); + static std::unique_ptr<IDocsumFieldWriter> create(const vespalib::string &fieldName, IAttributeManager &attrMgr, bool filter_elements, std::shared_ptr<StructFieldMapper> struct_field_mapper); void insertField(uint32_t docid, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) override; }; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp index 3a06346c7b4..59a1a67a890 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp @@ -9,6 +9,7 @@ #include "positionsdfw.h" #include "juniperdfw.h" #include "attribute_combiner_dfw.h" +#include <vespa/searchlib/common/struct_field_mapper.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/exceptions.h> @@ -23,7 +24,7 @@ DynamicDocsumConfig::getResultConfig() const { } IDocsumFieldWriter::UP -DynamicDocsumConfig::createFieldWriter(const string & fieldName, const string & overrideName, const string & argument, bool & rc) +DynamicDocsumConfig::createFieldWriter(const string & fieldName, const string & overrideName, const string & argument, bool & rc, std::shared_ptr<StructFieldMapper> struct_field_mapper) { const ResultConfig & resultConfig = getResultConfig(); rc = false; @@ -94,13 +95,13 @@ DynamicDocsumConfig::createFieldWriter(const string & fieldName, const string & } } else if (overrideName == "attributecombiner") { if (getEnvironment() && getEnvironment()->getAttributeManager()) { - fieldWriter = AttributeCombinerDFW::create(fieldName, *getEnvironment()->getAttributeManager(), false); + fieldWriter = AttributeCombinerDFW::create(fieldName, *getEnvironment()->getAttributeManager(), false, std::shared_ptr<StructFieldMapper>()); rc = static_cast<bool>(fieldWriter); } } else if (overrideName == "matchedattributeelementsfilter") { string source_field = argument.empty() ? fieldName : argument; if (getEnvironment() && getEnvironment()->getAttributeManager()) { - fieldWriter = AttributeCombinerDFW::create(source_field, *getEnvironment()->getAttributeManager(), true); + fieldWriter = AttributeCombinerDFW::create(source_field, *getEnvironment()->getAttributeManager(), true, struct_field_mapper); rc = static_cast<bool>(fieldWriter); } } else { @@ -113,13 +114,14 @@ void DynamicDocsumConfig::configure(const vespa::config::search::SummarymapConfig &cfg) { std::vector<string> strCfg; + auto struct_field_mapper = std::make_shared<StructFieldMapper>(); if ((cfg.defaultoutputclass != -1) && !_writer->SetDefaultOutputClass(cfg.defaultoutputclass)) { throw IllegalArgumentException(make_string("could not set default output class to %d", cfg.defaultoutputclass)); } for (size_t i = 0; i < cfg.override.size(); ++i) { const vespa::config::search::SummarymapConfig::Override & o = cfg.override[i]; bool rc(false); - IDocsumFieldWriter::UP fieldWriter = createFieldWriter(o.field, o.command, o.arguments, rc); + IDocsumFieldWriter::UP fieldWriter = createFieldWriter(o.field, o.command, o.arguments, rc, struct_field_mapper); if (rc && fieldWriter.get() != NULL) { rc = _writer->Override(o.field.c_str(), fieldWriter.release()); // OBJECT HAND-OVER } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.h b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.h index 21015e21459..34ca49824c5 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.h @@ -4,6 +4,7 @@ #include <vespa/config-summarymap.h> +namespace search { class StructFieldMapper; } namespace search::docsummary { class IDocsumEnvironment; @@ -28,7 +29,7 @@ protected: virtual std::unique_ptr<IDocsumFieldWriter> createFieldWriter(const string & fieldName, const string & overrideName, - const string & argument, bool & rc); + const string & argument, bool & rc, std::shared_ptr<StructFieldMapper> struct_field_mapper); private: IDocsumEnvironment * _env; DynamicDocsumWriter * _writer; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp index 7a609f2c971..3270e4b4c98 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.cpp @@ -50,10 +50,10 @@ GetDocsumsState::~GetDocsumsState() } const MatchingElements & -GetDocsumsState::get_matching_elements() +GetDocsumsState::get_matching_elements(const StructFieldMapper &struct_field_mapper) { if (!_matching_elements) { - _matching_elements = _callback.fill_matching_elements(); + _matching_elements = _callback.fill_matching_elements(struct_field_mapper); } return *_matching_elements; } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h index 9eec51e3459..350e2410c9d 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h @@ -13,7 +13,10 @@ namespace juniper { class Result; } -namespace search { class MatchingElements; } +namespace search { +class MatchingElements; +class StructFieldMapper; +} namespace search::common { class Location; } namespace search::attribute { class IAttributeContext; @@ -32,7 +35,7 @@ public: virtual void FillSummaryFeatures(GetDocsumsState * state, IDocsumEnvironment * env) = 0; virtual void FillRankFeatures(GetDocsumsState * state, IDocsumEnvironment * env) = 0; virtual void ParseLocation(GetDocsumsState * state) = 0; - virtual std::unique_ptr<MatchingElements> fill_matching_elements() = 0; + virtual std::unique_ptr<MatchingElements> fill_matching_elements(const StructFieldMapper &struct_field_mapper) = 0; virtual ~GetDocsumsStateCallback(void) { } GetDocsumsStateCallback(const GetDocsumsStateCallback &) = delete; GetDocsumsStateCallback & operator = (const GetDocsumsStateCallback &) = delete; @@ -93,7 +96,7 @@ public: GetDocsumsState& operator=(const GetDocsumsState &) = delete; GetDocsumsState(GetDocsumsStateCallback &callback); ~GetDocsumsState(); - const MatchingElements &get_matching_elements(); + const MatchingElements &get_matching_elements(const StructFieldMapper &struct_field_mapper); }; } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/struct_map_attribute_combiner_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/struct_map_attribute_combiner_dfw.cpp index e34012de7de..1b43acc7231 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/struct_map_attribute_combiner_dfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/struct_map_attribute_combiner_dfw.cpp @@ -6,6 +6,7 @@ #include <vespa/searchcommon/attribute/iattributecontext.h> #include <vespa/searchcommon/attribute/iattributevector.h> #include <vespa/searchlib/common/matching_elements.h> +#include <vespa/searchlib/common/struct_field_mapper.h> #include <vespa/vespalib/data/slime/cursor.h> #include <cassert> @@ -121,8 +122,9 @@ StructMapAttributeFieldWriterState::insertField(uint32_t docId, vespalib::slime: StructMapAttributeCombinerDFW::StructMapAttributeCombinerDFW(const vespalib::string &fieldName, const std::vector<vespalib::string> &valueFields, - bool filter_elements) - : AttributeCombinerDFW(fieldName, filter_elements), + bool filter_elements, + std::shared_ptr<StructFieldMapper> struct_field_mapper) + : AttributeCombinerDFW(fieldName, filter_elements, std::move(struct_field_mapper)), _keyAttributeName(), _valueFields(valueFields), _valueAttributeNames() @@ -133,6 +135,12 @@ StructMapAttributeCombinerDFW::StructMapAttributeCombinerDFW(const vespalib::str for (const auto &field : _valueFields) { _valueAttributeNames.emplace_back(prefix + field); } + if (filter_elements && _struct_field_mapper && !_struct_field_mapper->is_struct_field(fieldName)) { + _struct_field_mapper->add_mapping(fieldName, _keyAttributeName); + for (const auto &sub_field : _valueAttributeNames) { + _struct_field_mapper->add_mapping(fieldName, sub_field); + } + } } StructMapAttributeCombinerDFW::~StructMapAttributeCombinerDFW() = default; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/struct_map_attribute_combiner_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/struct_map_attribute_combiner_dfw.h index 375d55df678..1f92172d68b 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/struct_map_attribute_combiner_dfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/struct_map_attribute_combiner_dfw.h @@ -24,7 +24,8 @@ class StructMapAttributeCombinerDFW : public AttributeCombinerDFW public: StructMapAttributeCombinerDFW(const vespalib::string &fieldName, const std::vector<vespalib::string> &valueFields, - bool filter_elements); + bool filter_elements, + std::shared_ptr<StructFieldMapper> struct_field_mapper); ~StructMapAttributeCombinerDFW() override; }; |