diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-07-07 23:47:46 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-07-07 23:47:46 +0200 |
commit | dbd132133357a0354933df5800bdb5ec7b26088d (patch) | |
tree | e5c95008e90870c92bc704cde2c0632e1cbb381a /searchsummary | |
parent | ebf6eda095d61b1a1c5b755b98062d39a5c58f0b (diff) |
Remove unneeded includes in header files.
Diffstat (limited to 'searchsummary')
46 files changed, 503 insertions, 356 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 d5a908fc8bd..7265dd89be4 100644 --- a/searchsummary/src/tests/docsummary/attribute_combiner/attribute_combiner_test.cpp +++ b/searchsummary/src/tests/docsummary/attribute_combiner/attribute_combiner_test.cpp @@ -5,7 +5,7 @@ #include <vespa/searchlib/common/matching_elements.h> #include <vespa/searchlib/common/matching_elements_fields.h> #include <vespa/searchlib/util/slime_output_raw_buf_adapter.h> -#include <vespa/searchsummary/docsummary/docsumfieldwriter.h> +#include <vespa/searchsummary/docsummary/docsum_field_writer.h> #include <vespa/searchsummary/docsummary/docsumstate.h> #include <vespa/searchsummary/docsummary/docsum_field_writer_state.h> #include <vespa/searchsummary/docsummary/attribute_combiner_dfw.h> @@ -24,7 +24,7 @@ using search::docsummary::AttributeCombinerDFW; using search::docsummary::GetDocsumsState; using search::docsummary::GetDocsumsStateCallback; using search::docsummary::IDocsumEnvironment; -using search::docsummary::IDocsumFieldWriter; +using search::docsummary::DocsumFieldWriter; using search::docsummary::test::MockAttributeManager; using search::docsummary::test::MockStateCallback; using search::docsummary::test::SlimeValue; @@ -34,7 +34,7 @@ namespace { struct AttributeCombinerTest : public ::testing::Test { MockAttributeManager attrs; - std::unique_ptr<IDocsumFieldWriter> writer; + std::unique_ptr<DocsumFieldWriter> writer; MockStateCallback callback; GetDocsumsState state; std::shared_ptr<search::MatchingElementsFields> _matching_elems_fields; diff --git a/searchsummary/src/tests/docsummary/attributedfw/attributedfw_test.cpp b/searchsummary/src/tests/docsummary/attributedfw/attributedfw_test.cpp index 67d505582d8..42443cf1058 100644 --- a/searchsummary/src/tests/docsummary/attributedfw/attributedfw_test.cpp +++ b/searchsummary/src/tests/docsummary/attributedfw/attributedfw_test.cpp @@ -16,7 +16,7 @@ using search::attribute::BasicType; using search::attribute::CollectionType; using search::docsummary::AttributeDFWFactory; using search::docsummary::GetDocsumsState; -using search::docsummary::IDocsumFieldWriter; +using search::docsummary::DocsumFieldWriter; using search::docsummary::test::MockAttributeManager; using search::docsummary::test::MockStateCallback; using search::docsummary::test::SlimeValue; @@ -26,7 +26,7 @@ using ElementVector = std::vector<uint32_t>; class AttributeDFWTest : public ::testing::Test { protected: MockAttributeManager _attrs; - std::unique_ptr<IDocsumFieldWriter> _writer; + std::unique_ptr<DocsumFieldWriter> _writer; MockStateCallback _callback; GetDocsumsState _state; std::shared_ptr<search::MatchingElementsFields> _matching_elems_fields; diff --git a/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp b/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp index 675af283ee8..82aa9ceba92 100644 --- a/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp +++ b/searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp @@ -16,8 +16,10 @@ #include <vespa/searchlib/common/matching_elements_fields.h> #include <vespa/searchlib/util/slime_output_raw_buf_adapter.h> #include <vespa/searchsummary/docsummary/docsum_store_document.h> +#include <vespa/searchsummary/docsummary/docsumstorevalue.h> #include <vespa/searchsummary/docsummary/docsumstate.h> #include <vespa/searchsummary/docsummary/idocsumenvironment.h> +#include <vespa/searchsummary/docsummary/general_result.h> #include <vespa/searchsummary/docsummary/matched_elements_filter_dfw.h> #include <vespa/searchsummary/docsummary/resultconfig.h> #include <vespa/searchsummary/docsummary/resultpacker.h> @@ -215,7 +217,7 @@ public: { } ~MatchedElementsFilterTest(); - std::unique_ptr<IDocsumFieldWriter> make_field_writer(const std::string& input_field_name) { + std::unique_ptr<DocsumFieldWriter> make_field_writer(const std::string& input_field_name) { int input_field_enum = _doc_store.get_config().GetFieldNameEnum().Lookup(input_field_name.c_str()); return MatchedElementsFilterDFW::create(input_field_name, input_field_enum, _attr_ctx, _fields); diff --git a/searchsummary/src/tests/docsummary/positionsdfw_test.cpp b/searchsummary/src/tests/docsummary/positionsdfw_test.cpp index 11f0d0eb6d6..60584b26e31 100644 --- a/searchsummary/src/tests/docsummary/positionsdfw_test.cpp +++ b/searchsummary/src/tests/docsummary/positionsdfw_test.cpp @@ -4,7 +4,7 @@ #include <vespa/searchlib/attribute/extendableattributes.h> #include <vespa/searchlib/attribute/iattributemanager.h> #include <vespa/searchlib/common/matching_elements.h> -#include <vespa/searchsummary/docsummary/docsumfieldwriter.h> +#include <vespa/searchsummary/docsummary/docsum_field_writer.h> #include <vespa/searchsummary/docsummary/positionsdfw.h> #include <vespa/searchsummary/docsummary/idocsumenvironment.h> #include <vespa/searchsummary/docsummary/docsumstate.h> diff --git a/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt b/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt index 947fe9deeab..e3272fb36de 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt +++ b/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt @@ -6,13 +6,15 @@ vespa_add_library(searchsummary_docsummary OBJECT attribute_field_writer.cpp attributedfw.cpp check_undefined_value_visitor.cpp + copy_dfw.cpp docsumconfig.cpp - docsumfieldwriter.cpp - docsumstate.cpp + docsum_field_writer.cpp docsum_store_document.cpp + docsumstate.cpp docsumstorevalue.cpp docsumwriter.cpp dynamicteaserdfw.cpp + empty_dfw.cpp general_result.cpp geoposdfw.cpp getdocsumargs.cpp @@ -22,10 +24,12 @@ vespa_add_library(searchsummary_docsummary OBJECT matched_elements_filter_dfw.cpp positionsdfw.cpp rankfeaturesdfw.cpp + res_type_utils.cpp resultclass.cpp resultconfig.cpp resultpacker.cpp searchdatatype.cpp + simple_dfw.cpp struct_fields_resolver.cpp struct_map_attribute_combiner_dfw.cpp summaryfeaturesdfw.cpp 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 ff5c2c5e05b..f308795a1bc 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.cpp @@ -9,6 +9,7 @@ #include <vespa/searchlib/common/matching_elements.h> #include <vespa/searchlib/common/matching_elements_fields.h> #include <vespa/vespalib/data/slime/cursor.h> +#include <vespa/vespalib/data/slime/inserter.h> #include <vespa/vespalib/util/stash.h> #include <algorithm> #include <cassert> 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 18b4fd34e66..e5bed876b63 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/array_attribute_combiner_dfw.h @@ -3,6 +3,7 @@ #pragma once #include "attribute_combiner_dfw.h" +#include <vector> namespace search::attribute { class IAttributeContext; } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp index 79c11b20479..bf5578f38d6 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.cpp @@ -18,7 +18,7 @@ namespace search::docsummary { AttributeCombinerDFW::AttributeCombinerDFW(const vespalib::string &fieldName, bool filter_elements, std::shared_ptr<MatchingElementsFields> matching_elems_fields) - : ISimpleDFW(), + : SimpleDFW(), _stateIndex(0), _filter_elements(filter_elements), _fieldName(fieldName), @@ -41,13 +41,13 @@ AttributeCombinerDFW::setFieldWriterStateIndex(uint32_t fieldWriterStateIndex) return true; } -std::unique_ptr<IDocsumFieldWriter> +std::unique_ptr<DocsumFieldWriter> AttributeCombinerDFW::create(const vespalib::string &fieldName, IAttributeContext &attrCtx, bool filter_elements, std::shared_ptr<MatchingElementsFields> matching_elems_fields) { StructFieldsResolver structFields(fieldName, attrCtx, true); if (structFields.has_error()) { - return std::unique_ptr<IDocsumFieldWriter>(); + return std::unique_ptr<DocsumFieldWriter>(); } else if (structFields.is_map_of_struct()) { return std::make_unique<StructMapAttributeCombinerDFW>(fieldName, structFields, filter_elements, std::move(matching_elems_fields)); } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h index c1742595745..39f2d498c5b 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/attribute_combiner_dfw.h @@ -2,7 +2,8 @@ #pragma once -#include "docsumfieldwriter.h" +#include "simple_dfw.h" +#include <memory> namespace search { class MatchingElements; @@ -21,7 +22,7 @@ class DynamicDocsumWriter; * This class reads values from multiple struct field attributes and * inserts them as an array of struct or a map of struct. */ -class AttributeCombinerDFW : public ISimpleDFW +class AttributeCombinerDFW : public SimpleDFW { protected: uint32_t _stateIndex; @@ -36,8 +37,8 @@ public: ~AttributeCombinerDFW() override; bool IsGenerated() const override; bool setFieldWriterStateIndex(uint32_t fieldWriterStateIndex) override; - static std::unique_ptr<IDocsumFieldWriter> create(const vespalib::string &fieldName, search::attribute::IAttributeContext &attrCtx, - bool filter_elements, std::shared_ptr<MatchingElementsFields> matching_elems_fields); + static std::unique_ptr<DocsumFieldWriter> create(const vespalib::string &fieldName, search::attribute::IAttributeContext &attrCtx, + bool filter_elements, std::shared_ptr<MatchingElementsFields> matching_elems_fields); void insertField(uint32_t docid, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) override; }; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp index d5fdee096b1..e7b6acec646 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp @@ -2,6 +2,7 @@ #include "attributedfw.h" #include "docsumwriter.h" +#include "docsumstate.h" #include "docsum_field_writer_state.h" #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/value_codec.h> @@ -38,6 +39,24 @@ AttrDFW::AttrDFW(const vespalib::string & attrName) : { } +const attribute::IAttributeVector& +AttrDFW::get_attribute(const GetDocsumsState& s) const +{ + return *s.getAttribute(getIndex()); +} + +const vespalib::string & +AttrDFW::getAttributeName() const +{ + return _attrName; +} + +bool +AttrDFW::IsGenerated() const +{ + return true; +} + namespace { class SingleAttrDFW : public AttrDFW @@ -333,7 +352,7 @@ MultiAttrDFW::insertField(uint32_t docid, GetDocsumsState *state, ResType, vespa field_writer_state->insertField(docid, target); } -std::unique_ptr<IDocsumFieldWriter> +std::unique_ptr<DocsumFieldWriter> create_multi_writer(const IAttributeVector& attr, bool filter_elements, std::shared_ptr<MatchingElementsFields> matching_elems_fields) { auto type = attr.getBasicType(); @@ -355,7 +374,7 @@ create_multi_writer(const IAttributeVector& attr, bool filter_elements, std::sha } -std::unique_ptr<IDocsumFieldWriter> +std::unique_ptr<DocsumFieldWriter> AttributeDFWFactory::create(IAttributeManager& attr_mgr, const vespalib::string& attr_name, bool filter_elements, @@ -365,7 +384,7 @@ AttributeDFWFactory::create(IAttributeManager& attr_mgr, const auto* attr = ctx->getAttribute(attr_name); if (attr == nullptr) { Issue::report("No valid attribute vector found: '%s'", attr_name.c_str()); - return std::unique_ptr<IDocsumFieldWriter>(); + return std::unique_ptr<DocsumFieldWriter>(); } if (attr->hasMultiValue()) { return create_multi_writer(*attr, filter_elements, std::move(matching_elems_fields)); diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h index 35f67fd5446..26351bdf501 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h @@ -2,38 +2,38 @@ #pragma once -#include "docsumfieldwriter.h" -#include "docsumstate.h" +#include "simple_dfw.h" +#include <memory> -namespace search { class MatchingElementsFields; } +namespace search { +class IAttributeManager; +class MatchingElementsFields; +} namespace search::attribute { class IAttributeVector; } namespace search::docsummary { /** - * Factory to create an IDocsumFieldWriter to write an attribute vector to slime. + * Factory to create an DocsumFieldWriter to write an attribute vector to slime. */ class AttributeDFWFactory { public: - static std::unique_ptr<IDocsumFieldWriter> create(IAttributeManager& attr_mgr, - const vespalib::string& attr_name, - bool filter_elements = false, - std::shared_ptr<MatchingElementsFields> matching_elems_fields - = std::shared_ptr<MatchingElementsFields>()); + static std::unique_ptr<DocsumFieldWriter> create(IAttributeManager& attr_mgr, + const vespalib::string& attr_name, + bool filter_elements = false, + std::shared_ptr<MatchingElementsFields> matching_elems_fields = std::shared_ptr<MatchingElementsFields>()); }; -class AttrDFW : public ISimpleDFW +class AttrDFW : public SimpleDFW { private: vespalib::string _attrName; protected: - const attribute::IAttributeVector& get_attribute(const GetDocsumsState& s) const { - return *s.getAttribute(getIndex()); - } - const vespalib::string & getAttributeName() const override { return _attrName; } + const attribute::IAttributeVector& get_attribute(const GetDocsumsState& s) const; + const vespalib::string & getAttributeName() const override; public: AttrDFW(const vespalib::string & attrName); - bool IsGenerated() const override { return true; } + bool IsGenerated() const override; }; } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.cpp index 0f0ac9ddf72..836273ce3d8 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.cpp @@ -1,51 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "docsumfieldwriter.h" +#include "copy_dfw.h" +#include "general_result.h" #include "i_docsum_store_document.h" -#include "idocsumenvironment.h" -#include "docsumstate.h" -#include "summaryfieldconverter.h" -#include <vespa/searchlib/common/documentlocations.h> -#include <vespa/searchlib/common/location.h> -#include <vespa/searchlib/parsequery/stackdumpiterator.h> +#include "resultconfig.h" #include <vespa/vespalib/data/slime/slime.h> #include <vespa/log/log.h> -LOG_SETUP(".searchlib.docsummary.docsumfieldwriter"); +LOG_SETUP(".searchlib.docsummary.copy_dfw"); namespace search::docsummary { -using search::attribute::IAttributeContext; -using search::attribute::IAttributeVector; -using search::attribute::BasicType; -using search::common::Location; - -//-------------------------------------------------------------------------- - -const vespalib::string IDocsumFieldWriter::_empty(""); - -bool -IDocsumFieldWriter::setFieldWriterStateIndex(uint32_t) -{ - return false; // Don't need any field writer state by default -} - -//-------------------------------------------------------------------------- - -EmptyDFW::EmptyDFW() = default; - -EmptyDFW::~EmptyDFW() = default; - -void -EmptyDFW::insertField(uint32_t, GetDocsumsState *, ResType, vespalib::slime::Inserter &target) -{ - // insert explicitly-empty field? - // target.insertNix(); - (void)target; -} - -//-------------------------------------------------------------------------- - CopyDFW::CopyDFW() : _inputFieldEnumValue(static_cast<uint32_t>(-1)), _input_field_name() diff --git a/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.h new file mode 100644 index 00000000000..40427e0e458 --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.h @@ -0,0 +1,28 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "docsum_field_writer.h" + +namespace search::docsummary { + +class ResultConfig; + +class CopyDFW : public DocsumFieldWriter +{ +private: + uint32_t _inputFieldEnumValue; + vespalib::string _input_field_name; + +public: + CopyDFW(); + ~CopyDFW() override; + + bool Init(const ResultConfig & config, const char *inputField); + + bool IsGenerated() const override { return false; } + void insertField(uint32_t docid, GeneralResult *gres, GetDocsumsState *state, ResType type, + vespalib::slime::Inserter &target) override; +}; + +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_blob_entry_filter.h b/searchsummary/src/vespa/searchsummary/docsummary/docsum_blob_entry_filter.h new file mode 100644 index 00000000000..1d006386d35 --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_blob_entry_filter.h @@ -0,0 +1,29 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "res_type.h" +#include <bitset> + +namespace search::docsummary { + +/* + * Class containing the set of result types not stored in docsum blobs. + * This is used for gradual migration towards elimination of docsum blobs. + */ +class DocsumBlobEntryFilter { + std::bitset<14> _skip_types; + +public: + DocsumBlobEntryFilter() + : _skip_types() + { + } + bool skip(ResType type) const noexcept { return _skip_types.test(type); } + DocsumBlobEntryFilter &add_skip(ResType type) { + _skip_types.set(type); + return *this; + } +}; + +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_field_writer.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsum_field_writer.cpp new file mode 100644 index 00000000000..c698f0603c6 --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_field_writer.cpp @@ -0,0 +1,27 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "docsum_field_writer.h" + +namespace search::docsummary { + +const vespalib::string DocsumFieldWriter::_empty(""); + +const vespalib::string& +DocsumFieldWriter::getAttributeName() const +{ + return _empty; +} + +bool +DocsumFieldWriter::isDefaultValue(uint32_t, const GetDocsumsState*) const +{ + return false; +} + +bool +DocsumFieldWriter::setFieldWriterStateIndex(uint32_t) +{ + return false; // Don't need any field writer state by default +} + +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_field_writer.h b/searchsummary/src/vespa/searchsummary/docsummary/docsum_field_writer.h new file mode 100644 index 00000000000..764f3507380 --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_field_writer.h @@ -0,0 +1,41 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "res_type_utils.h" +#include <vespa/vespalib/stllike/string.h> + +namespace vespalib::slime { struct Inserter; } + +namespace search::docsummary { + +class GeneralResult; +class GetDocsumsState; + +/* + * Abstract class for writing document summaries. + */ +class DocsumFieldWriter +{ +public: + DocsumFieldWriter() + : _index(0) + { + } + virtual ~DocsumFieldWriter() = default; + static bool IsRuntimeCompatible(ResType a, ResType b) { + return ResTypeUtils::IsRuntimeCompatible(a, b); + } + virtual bool IsGenerated() const = 0; + virtual void insertField(uint32_t docid, GeneralResult *gres, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) = 0; + virtual const vespalib::string & getAttributeName() const; + virtual bool isDefaultValue(uint32_t docid, const GetDocsumsState * state) const; + void setIndex(size_t v) { _index = v; } + size_t getIndex() const { return _index; } + virtual bool setFieldWriterStateIndex(uint32_t fieldWriterStateIndex); +private: + size_t _index; + static const vespalib::string _empty; +}; + +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp index 24642c418fd..376d4f90204 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp @@ -1,8 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "attribute_combiner_dfw.h" #include "docsumconfig.h" +#include "attribute_combiner_dfw.h" +#include "copy_dfw.h" #include "docsumwriter.h" +#include "empty_dfw.h" #include "geoposdfw.h" #include "idocsumenvironment.h" #include "juniperdfw.h" @@ -10,6 +12,7 @@ #include "positionsdfw.h" #include "rankfeaturesdfw.h" #include "textextractordfw.h" +#include "summaryfeaturesdfw.h" #include <vespa/searchlib/common/matching_elements_fields.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/exceptions.h> @@ -24,12 +27,12 @@ DynamicDocsumConfig::getResultConfig() const { return *_writer->GetResultConfig(); } -IDocsumFieldWriter::UP +std::unique_ptr<DocsumFieldWriter> DynamicDocsumConfig::createFieldWriter(const string & fieldName, const string & overrideName, const string & argument, bool & rc, std::shared_ptr<MatchingElementsFields> matching_elems_fields) { const ResultConfig & resultConfig = getResultConfig(); rc = false; - IDocsumFieldWriter::UP fieldWriter; + std::unique_ptr<DocsumFieldWriter> fieldWriter; if (overrideName == "dynamicteaser") { if ( ! argument.empty() ) { const char *langFieldName = "something unused"; @@ -127,7 +130,7 @@ DynamicDocsumConfig::configure(const vespa::config::search::SummarymapConfig &cf 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, matching_elems_fields); + std::unique_ptr<DocsumFieldWriter> fieldWriter = createFieldWriter(o.field, o.command, o.arguments, rc, matching_elems_fields); if (rc && fieldWriter) { 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 70c8d524527..b86313dfbd4 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.h @@ -8,9 +8,9 @@ namespace search { class MatchingElementsFields; } namespace search::docsummary { class IDocsumEnvironment; +class DocsumFieldWriter; class DynamicDocsumWriter; class ResultConfig; -class IDocsumFieldWriter; class DynamicDocsumConfig { @@ -27,7 +27,7 @@ protected: const IDocsumEnvironment * getEnvironment() const { return _env; } const ResultConfig & getResultConfig() const; - virtual std::unique_ptr<IDocsumFieldWriter> + virtual std::unique_ptr<DocsumFieldWriter> createFieldWriter(const string & fieldName, const string & overrideName, const string & argument, bool & rc, std::shared_ptr<MatchingElementsFields> matching_elems_fields); private: diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.h b/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.h deleted file mode 100644 index bc135404de1..00000000000 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include "general_result.h" -#include "resultconfig.h" -#include <vespa/searchlib/util/rawbuf.h> -#include <vespa/vespalib/data/slime/inserter.h> - -namespace search { class IAttributeManager; } - -namespace search::docsummary { - -class GetDocsumsState; - -class IDocsumFieldWriter -{ -public: - using UP = std::unique_ptr<IDocsumFieldWriter>; - IDocsumFieldWriter() : _index(0) { } - virtual ~IDocsumFieldWriter() = default; - - static bool IsRuntimeCompatible(ResType a, ResType b) { - return ResultConfig::IsRuntimeCompatible(a, b); - } - - virtual bool IsGenerated() const = 0; - virtual void insertField(uint32_t docid, GeneralResult *gres, GetDocsumsState *state, ResType type, - vespalib::slime::Inserter &target) = 0; - virtual const vespalib::string & getAttributeName() const { return _empty; } - virtual bool isDefaultValue(uint32_t docid, const GetDocsumsState * state) const { - (void) docid; - (void) state; - return false; - } - void setIndex(size_t v) { _index = v; } - size_t getIndex() const { return _index; } - virtual bool setFieldWriterStateIndex(uint32_t fieldWriterStateIndex); -private: - size_t _index; - static const vespalib::string _empty; -}; - -class ISimpleDFW : public IDocsumFieldWriter -{ -public: - virtual void insertField(uint32_t docid, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) = 0; - void insertField(uint32_t docid, GeneralResult *, GetDocsumsState *state, ResType type, - vespalib::slime::Inserter &target) override - { - insertField(docid, state, type, target); - } -}; - -//-------------------------------------------------------------------------- - -class EmptyDFW : public ISimpleDFW -{ -public: - EmptyDFW(); - ~EmptyDFW() override; - - bool IsGenerated() const override { return true; } - void insertField(uint32_t docid, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) override; -}; - -//-------------------------------------------------------------------------- - -class CopyDFW : public IDocsumFieldWriter -{ -private: - uint32_t _inputFieldEnumValue; - vespalib::string _input_field_name; - -public: - CopyDFW(); - ~CopyDFW() override; - - bool Init(const ResultConfig & config, const char *inputField); - - bool IsGenerated() const override { return false; } - void insertField(uint32_t docid, GeneralResult *gres, GetDocsumsState *state, ResType type, - vespalib::slime::Inserter &target) override; -}; - -} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp index c6e5a224e21..1492ce2b435 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp @@ -168,7 +168,7 @@ DynamicDocsumWriter::insertDocsum(const ResolveClassInfo & rci, uint32_t docid, vespalib::slime::Cursor & docsum = topInserter.insertObject(); for (uint32_t i = 0; i < rci.outputClass->GetNumEntries(); ++i) { const ResConfigEntry *resCfg = rci.outputClass->GetEntry(i); - IDocsumFieldWriter *writer = _overrideTable[resCfg->_enumValue]; + DocsumFieldWriter *writer = _overrideTable[resCfg->_enumValue]; if (! writer->isDefaultValue(docid, state)) { const Memory field_name(resCfg->_bindname.data(), resCfg->_bindname.size()); ObjectInserter inserter(docsum, field_name); @@ -188,7 +188,7 @@ DynamicDocsumWriter::insertDocsum(const ResolveClassInfo & rci, uint32_t docid, vespalib::slime::Cursor & docsum = topInserter.insertObject(); for (uint32_t i = 0; i < rci.outputClass->GetNumEntries(); ++i) { const ResConfigEntry *outCfg = rci.outputClass->GetEntry(i); - IDocsumFieldWriter *writer = _overrideTable[outCfg->_enumValue]; + DocsumFieldWriter *writer = _overrideTable[outCfg->_enumValue]; const Memory field_name(outCfg->_bindname.data(), outCfg->_bindname.size()); ObjectInserter inserter(docsum, field_name); if (writer != nullptr) { @@ -230,7 +230,7 @@ DynamicDocsumWriter::DynamicDocsumWriter( ResultConfig *config, KeywordExtractor { LOG_ASSERT(config != nullptr); _classInfoTable = new ResultClass::DynamicInfo[_numClasses]; - _overrideTable = new IDocsumFieldWriter*[_numEnumValues]; + _overrideTable = new DocsumFieldWriter*[_numEnumValues]; uint32_t i = 0; for (ResultConfig::iterator it(config->begin()), mt(config->end()); it != mt; it++, i++) { @@ -279,7 +279,7 @@ DynamicDocsumWriter::SetDefaultOutputClass(uint32_t classID) bool -DynamicDocsumWriter::Override(const char *fieldName, IDocsumFieldWriter *writer) +DynamicDocsumWriter::Override(const char *fieldName, DocsumFieldWriter *writer) { uint32_t fieldEnumValue = _resultConfig->GetFieldNameEnum().Lookup(fieldName); @@ -324,7 +324,7 @@ DynamicDocsumWriter::InitState(IAttributeManager & attrMan, GetDocsumsState *sta state->_attributes.resize(_numEnumValues); state->_fieldWriterStates.resize(_numFieldWriterStates); for (size_t i(0); i < state->_attributes.size(); i++) { - const IDocsumFieldWriter *fw = _overrideTable[i]; + const DocsumFieldWriter *fw = _overrideTable[i]; if (fw) { const vespalib::string & attributeName = fw->getAttributeName(); if (!attributeName.empty()) { diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.h b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.h index e70e3db8655..b3182221b68 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.h @@ -7,12 +7,14 @@ #include "resultconfig.h" #include "docsumstore.h" #include "keywordextractor.h" -#include "docsumfieldwriter.h" +#include "docsum_field_writer.h" #include <vespa/searchlib/util/rawbuf.h> #include <vespa/fastlib/text/unicodeutil.h> #include <vespa/fastlib/text/wordfolder.h> -using search::IAttributeManager; +namespace search { class IAttributeManager; } + +namespace vespalib { class Slime; } namespace search::docsummary { @@ -36,7 +38,7 @@ public: }; virtual ~IDocsumWriter() {} - virtual void InitState(IAttributeManager & attrMan, GetDocsumsState *state) = 0; + virtual void InitState(search::IAttributeManager & attrMan, GetDocsumsState *state) = 0; virtual uint32_t WriteDocsum(uint32_t docid, GetDocsumsState *state, IDocsumStore *docinfos, search::RawBuf *target) = 0; virtual void insertDocsum(const ResolveClassInfo & rci, uint32_t docid, GetDocsumsState *state, @@ -58,7 +60,7 @@ private: uint32_t _numEnumValues; uint32_t _numFieldWriterStates; ResultClass::DynamicInfo *_classInfoTable; - IDocsumFieldWriter **_overrideTable; + DocsumFieldWriter** _overrideTable; void resolveInputClass(ResolveClassInfo &rci, uint32_t id) const; @@ -73,8 +75,8 @@ public: ResultConfig *GetResultConfig() { return _resultConfig; } bool SetDefaultOutputClass(uint32_t classID); - bool Override(const char *fieldName, IDocsumFieldWriter *writer); - void InitState(IAttributeManager & attrMan, GetDocsumsState *state) override; + bool Override(const char *fieldName, DocsumFieldWriter *writer); + void InitState(search::IAttributeManager & attrMan, GetDocsumsState *state) override; uint32_t WriteDocsum(uint32_t docid, GetDocsumsState *state, IDocsumStore *docinfos, search::RawBuf *target) override; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/empty_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/empty_dfw.cpp new file mode 100644 index 00000000000..3d3b1e11626 --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/empty_dfw.cpp @@ -0,0 +1,19 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "empty_dfw.h" + +namespace search::docsummary { + +EmptyDFW::EmptyDFW() = default; + +EmptyDFW::~EmptyDFW() = default; + +void +EmptyDFW::insertField(uint32_t, GetDocsumsState *, ResType, vespalib::slime::Inserter &target) +{ + // insert explicitly-empty field? + // target.insertNix(); + (void)target; +} + +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/empty_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/empty_dfw.h new file mode 100644 index 00000000000..c842e1416db --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/empty_dfw.h @@ -0,0 +1,19 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "simple_dfw.h" + +namespace search::docsummary { + +class EmptyDFW : public SimpleDFW +{ +public: + EmptyDFW(); + ~EmptyDFW() override; + + bool IsGenerated() const override { return true; } + void insertField(uint32_t docid, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) override; +}; + +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.cpp index 8f627ac1b9a..c3806d6e7ea 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.cpp @@ -6,6 +6,7 @@ #include <vespa/searchlib/common/location.h> #include <vespa/vespalib/util/jsonwriter.h> #include <vespa/vespalib/data/slime/cursor.h> +#include <vespa/vespalib/data/slime/inserter.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/util/issue.h> #include <climits> diff --git a/searchsummary/src/vespa/searchsummary/docsummary/juniperdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/juniperdfw.h index d9a657038c4..5e2ec517a47 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/juniperdfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/juniperdfw.h @@ -4,14 +4,14 @@ #include "general_result.h" #include "resultconfig.h" -#include "docsumfieldwriter.h" +#include "docsum_field_writer.h" #include <vespa/searchlib/util/rawbuf.h> #include <vespa/vespalib/data/slime/inserter.h> #include <vespa/juniper/rpinterface.h> namespace search::docsummary { -class JuniperDFW : public IDocsumFieldWriter +class JuniperDFW : public DocsumFieldWriter { public: virtual bool Init( @@ -21,7 +21,7 @@ public: const char *inputField); protected: JuniperDFW(juniper::Juniper * juniper); - virtual ~JuniperDFW(); + ~JuniperDFW() override; uint32_t _inputFieldEnumValue; std::unique_ptr<juniper::Config> _juniperConfig; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp index c2115201d9b..c05fec7a0ce 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.cpp @@ -1,7 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "docsumstate.h" #include "matched_elements_filter_dfw.h" +#include "docsumstate.h" +#include "general_result.h" #include "struct_fields_resolver.h" #include "summaryfieldconverter.h" #include <vespa/document/fieldvalue/document.h> @@ -40,21 +41,21 @@ MatchedElementsFilterDFW::MatchedElementsFilterDFW(const std::string& input_fiel { } -std::unique_ptr<IDocsumFieldWriter> +std::unique_ptr<DocsumFieldWriter> MatchedElementsFilterDFW::create(const std::string& input_field_name, uint32_t input_field_enum, std::shared_ptr<MatchingElementsFields> matching_elems_fields) { return std::make_unique<MatchedElementsFilterDFW>(input_field_name, input_field_enum, std::move(matching_elems_fields)); } -std::unique_ptr<IDocsumFieldWriter> +std::unique_ptr<DocsumFieldWriter> MatchedElementsFilterDFW::create(const std::string& input_field_name, uint32_t input_field_enum, search::attribute::IAttributeContext& attr_ctx, std::shared_ptr<MatchingElementsFields> matching_elems_fields) { StructFieldsResolver resolver(input_field_name, attr_ctx, false); if (resolver.has_error()) { - return std::unique_ptr<IDocsumFieldWriter>(); + return std::unique_ptr<DocsumFieldWriter>(); } resolver.apply_to(*matching_elems_fields); return std::make_unique<MatchedElementsFilterDFW>(input_field_name, input_field_enum, std::move(matching_elems_fields)); diff --git a/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.h index 505a2557408..b117da541d6 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.h @@ -2,7 +2,11 @@ #pragma once -#include "docsumfieldwriter.h" +#include "docsum_field_writer.h" +#include <memory> +#include <vector> + +namespace search { class MatchingElementsFields; } namespace search::attribute { class IAttributeContext; } @@ -13,7 +17,7 @@ namespace search::docsummary { * (array of primitive, weighted set of primitive, map of primitives, map of struct, array of struct) * that is retrieved from the document store. */ -class MatchedElementsFilterDFW : public IDocsumFieldWriter { +class MatchedElementsFilterDFW : public DocsumFieldWriter { private: std::string _input_field_name; uint32_t _input_field_enum; @@ -24,11 +28,11 @@ private: public: MatchedElementsFilterDFW(const std::string& input_field_name, uint32_t input_field_enum, std::shared_ptr<MatchingElementsFields> matching_elems_fields); - static std::unique_ptr<IDocsumFieldWriter> create(const std::string& input_field_name, uint32_t input_field_enum, - std::shared_ptr<MatchingElementsFields> matching_elems_fields); - static std::unique_ptr<IDocsumFieldWriter> create(const std::string& input_field_name, uint32_t input_field_enum, - search::attribute::IAttributeContext& attr_ctx, - std::shared_ptr<MatchingElementsFields> matching_elems_fields); + static std::unique_ptr<DocsumFieldWriter> create(const std::string& input_field_name, uint32_t input_field_enum, + std::shared_ptr<MatchingElementsFields> matching_elems_fields); + static std::unique_ptr<DocsumFieldWriter> create(const std::string& input_field_name, uint32_t input_field_enum, + search::attribute::IAttributeContext& attr_ctx, + std::shared_ptr<MatchingElementsFields> matching_elems_fields); ~MatchedElementsFilterDFW(); bool IsGenerated() const override { return false; } void insertField(uint32_t docid, GeneralResult* result, GetDocsumsState *state, diff --git a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp index 1fcb0a49be1..7f3a929a62f 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp @@ -270,8 +270,9 @@ PositionsDFW::UP PositionsDFW::create(const char *attribute_name, IAttributeMana return std::make_unique<PositionsDFW>(attribute_name, useV8geoPositions); } -AbsDistanceDFW::UP AbsDistanceDFW::create(const char *attribute_name, IAttributeManager *attribute_manager) { - AbsDistanceDFW::UP ret; +std::unique_ptr<DocsumFieldWriter> +AbsDistanceDFW::create(const char *attribute_name, IAttributeManager *attribute_manager) { + std::unique_ptr<DocsumFieldWriter> ret; if (attribute_manager != nullptr) { if (!attribute_name) { LOG(debug, "createAbsDistanceDFW: missing attribute name '%p'", attribute_name); diff --git a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h index b3e041c1379..d9445abd2ff 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h @@ -45,7 +45,7 @@ public: void insertField(uint32_t docid, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) override; - static UP create(const char *attribute_name, IAttributeManager *index_man); + static std::unique_ptr<DocsumFieldWriter> create(const char *attribute_name, IAttributeManager *index_man); }; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.cpp index 38b58ef94fc..5d3b104189b 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.cpp @@ -3,6 +3,7 @@ #include "rankfeaturesdfw.h" #include "docsumstate.h" #include <vespa/vespalib/data/slime/cursor.h> +#include <vespa/vespalib/data/slime/inserter.h> namespace search::docsummary { diff --git a/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.h index eab9fab60b2..91f9e80d303 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/rankfeaturesdfw.h @@ -2,11 +2,13 @@ #pragma once -#include "summaryfeaturesdfw.h" +#include "simple_dfw.h" namespace search::docsummary { -class RankFeaturesDFW : public ISimpleDFW +class IDocsumEnvironment; + +class RankFeaturesDFW : public SimpleDFW { private: IDocsumEnvironment * _env; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/res_type.h b/searchsummary/src/vespa/searchsummary/docsummary/res_type.h new file mode 100644 index 00000000000..02c9f1522a4 --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/res_type.h @@ -0,0 +1,30 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +namespace search::docsummary { + +/** + * This enumeration contains values denoting the different types of + * docsum fields. NOTE: The internal implementation depends on RES_INT + * having the value 0. All types < RES_STRING must be fixed size and + * all types > RES_STRING must be variable size. + **/ +enum ResType { + RES_INT = 0, + RES_SHORT, + RES_BOOL, + RES_BYTE, + RES_FLOAT, + RES_DOUBLE, + RES_INT64, + RES_STRING, + RES_DATA, + RES_LONG_STRING, + RES_LONG_DATA, + RES_JSONSTRING, + RES_TENSOR, + RES_FEATUREDATA +}; + +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/res_type_utils.cpp b/searchsummary/src/vespa/searchsummary/docsummary/res_type_utils.cpp new file mode 100644 index 00000000000..98cc8372ac1 --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/res_type_utils.cpp @@ -0,0 +1,29 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "res_type_utils.h" + +namespace search::docsummary { + +const char * +ResTypeUtils::GetResTypeName(ResType type) +{ + switch (type) { + case RES_INT: return "integer"; + case RES_SHORT: return "short"; + case RES_BYTE: return "byte"; + case RES_BOOL: return "bool"; + case RES_FLOAT: return "float"; + case RES_DOUBLE: return "double"; + case RES_INT64: return "int64"; + case RES_STRING: return "string"; + case RES_DATA: return "data"; + case RES_LONG_STRING: return "longstring"; + case RES_LONG_DATA: return "longdata"; + case RES_JSONSTRING: return "jsonstring"; + case RES_TENSOR: return "tensor"; + case RES_FEATUREDATA: return "featuredata"; + } + return "unknown-type"; +} + +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/res_type_utils.h b/searchsummary/src/vespa/searchsummary/docsummary/res_type_utils.h new file mode 100644 index 00000000000..194a008c179 --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/res_type_utils.h @@ -0,0 +1,102 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "res_type.h" + +namespace search::docsummary { + + +/* + * Utilitiy functions for checking if result type is ok. + */ +struct ResTypeUtils +{ + /** + * Determine if a result field type is of variable size. + * + * @return true for variable size field types, false for fixed + * size field types + **/ + static bool IsVariableSize(ResType t) { return (t >= RES_STRING); } + + + /** + * Determine if a pair of result field types are binary + * compatible. A pair of types are binary compatible if the packed + * representation is identical. + * + * @return true if the given types are binary compatible. + * @param a enum value of a result field type. + * @param b enum value of a result field type. + **/ + static bool IsBinaryCompatible(ResType a, ResType b) + { + if (a == b) { + return true; + } + switch (a) { + case RES_BYTE: + case RES_BOOL: + return (b == RES_BYTE || b == RES_BOOL); + case RES_STRING: + case RES_DATA: + return (b == RES_STRING || b == RES_DATA); + case RES_LONG_STRING: + case RES_LONG_DATA: + case RES_FEATUREDATA: + case RES_JSONSTRING: + return (b == RES_LONG_STRING || b == RES_LONG_DATA || + b == RES_FEATUREDATA || b == RES_JSONSTRING); + default: + return false; + } + return false; + } + + + /** + * Determine if a pair of result field types are runtime + * compatible. A pair of types are runtime compatible if the + * unpacked (@ref ResEntry) representation is identical. + * + * @return true if the given types are runtime compatible. + * @param a enum value of a result field type. + * @param b enum value of a result field type. + **/ + static bool IsRuntimeCompatible(ResType a, ResType b) + { + switch (a) { + case RES_INT: + case RES_SHORT: + case RES_BYTE: + case RES_BOOL: + return (b == RES_INT || b == RES_SHORT || b == RES_BYTE || b == RES_BOOL); + case RES_FLOAT: + case RES_DOUBLE: + return (b == RES_FLOAT || b == RES_DOUBLE); + case RES_INT64: + return b == RES_INT64; + case RES_STRING: + case RES_LONG_STRING: + case RES_JSONSTRING: + return (b == RES_STRING || b == RES_LONG_STRING || b == RES_JSONSTRING); + case RES_DATA: + case RES_LONG_DATA: + return (b == RES_DATA || b == RES_LONG_DATA); + case RES_TENSOR: + return (b == RES_TENSOR); + case RES_FEATUREDATA: + return (b == RES_FEATUREDATA); + } + return false; + } + + /** + * @return the name of the given result field type. + * @param resType enum value of a result field type. + **/ + static const char *GetResTypeName(ResType type); +}; + +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h b/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h index d6d247238cd..47feed70e97 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/resultclass.h @@ -2,57 +2,15 @@ #pragma once +#include "docsum_blob_entry_filter.h" #include <vespa/searchlib/util/rawbuf.h> #include <vespa/vespalib/stllike/string.h> #include <vespa/vespalib/stllike/hash_map.h> #include <vespa/searchlib/util/stringenum.h> -#include <bitset> namespace search::docsummary { /** - * This enumeration contains values denoting the different types of - * docsum fields. NOTE: The internal implementation depends on RES_INT - * having the value 0. All types < RES_STRING must be fixed size and - * all types > RES_STRING must be variable size. - **/ -enum ResType { - RES_INT = 0, - RES_SHORT, - RES_BOOL, - RES_BYTE, - RES_FLOAT, - RES_DOUBLE, - RES_INT64, - RES_STRING, - RES_DATA, - RES_LONG_STRING, - RES_LONG_DATA, - RES_JSONSTRING, - RES_TENSOR, - RES_FEATUREDATA -}; - -/* - * Class containing the set of result types not stored in docsum blobs. - * This is used for gradual migration towards elimination of docsum blobs. - */ -class DocsumBlobEntryFilter { - std::bitset<14> _skip_types; - -public: - DocsumBlobEntryFilter() - : _skip_types() - { - } - bool skip(ResType type) const noexcept { return _skip_types.test(type); } - DocsumBlobEntryFilter &add_skip(ResType type) { - _skip_types.set(type); - return *this; - } -}; - -/** * This struct describes a single docsum field (name and type). A * docsum blob is unpacked into an array of ResEntry instances * by interpreting it as described by an array of ResConfigEntry diff --git a/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.cpp b/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.cpp index 4096e26a6e3..168b4c81374 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.cpp @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "resultconfig.h" +#include "resultclass.h" #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/stllike/hash_map.hpp> #include <atomic> @@ -45,28 +46,6 @@ ResultConfig::~ResultConfig() } -const char * -ResultConfig::GetResTypeName(ResType type) -{ - switch (type) { - case RES_INT: return "integer"; - case RES_SHORT: return "short"; - case RES_BYTE: return "byte"; - case RES_BOOL: return "bool"; - case RES_FLOAT: return "float"; - case RES_DOUBLE: return "double"; - case RES_INT64: return "int64"; - case RES_STRING: return "string"; - case RES_DATA: return "data"; - case RES_LONG_STRING: return "longstring"; - case RES_LONG_DATA: return "longdata"; - case RES_JSONSTRING: return "jsonstring"; - case RES_TENSOR: return "tensor"; - case RES_FEATUREDATA: return "featuredata"; - } - return "unknown-type"; -} - void ResultConfig::Reset() { diff --git a/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.h b/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.h index 1438aee73ce..945eef8514f 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/resultconfig.h @@ -2,14 +2,15 @@ #pragma once -#include "resultclass.h" -#include "general_result.h" +#include "docsum_blob_entry_filter.h" +#include "res_type_utils.h" #include <vespa/config-summary.h> -#include <vespa/searchlib/util/rawbuf.h> #include <vespa/searchlib/util/stringenum.h> namespace search::docsummary { +class ResultClass; + /** * This class represents the overall result configuration. A result * configuration may contain multiple result classes, where each @@ -31,7 +32,7 @@ private: ResultConfig& operator=(const ResultConfig &); typedef vespalib::hash_map<vespalib::string, uint32_t> NameMap; - typedef vespalib::hash_map<uint32_t, ResultClass::UP> IdMap; + typedef vespalib::hash_map<uint32_t, std::unique_ptr<ResultClass>> IdMap; uint32_t _defaultSummaryId; bool _useV8geoPositions; search::util::StringEnum _fieldEnum; @@ -95,85 +96,9 @@ public: static uint32_t NoClassID() { return static_cast<uint32_t>(-1); } - /** - * Determine if a result field type is of variable size. - * - * @return true for variable size field types, false for fixed - * size field types - **/ - static bool IsVariableSize(ResType t) { return (t >= RES_STRING); } - - - /** - * Determine if a pair of result field types are binary - * compatible. A pair of types are binary compatible if the packed - * representation is identical. - * - * @return true if the given types are binary compatible. - * @param a enum value of a result field type. - * @param b enum value of a result field type. - **/ - static bool IsBinaryCompatible(ResType a, ResType b) - { - if (a == b) { - return true; - } - switch (a) { - case RES_BYTE: - case RES_BOOL: - return (b == RES_BYTE || b == RES_BOOL); - case RES_STRING: - case RES_DATA: - return (b == RES_STRING || b == RES_DATA); - case RES_LONG_STRING: - case RES_LONG_DATA: - case RES_FEATUREDATA: - case RES_JSONSTRING: - return (b == RES_LONG_STRING || b == RES_LONG_DATA || - b == RES_FEATUREDATA || b == RES_JSONSTRING); - default: - return false; - } - return false; - } - - - /** - * Determine if a pair of result field types are runtime - * compatible. A pair of types are runtime compatible if the - * unpacked (@ref ResEntry) representation is identical. - * - * @return true if the given types are runtime compatible. - * @param a enum value of a result field type. - * @param b enum value of a result field type. - **/ - static bool IsRuntimeCompatible(ResType a, ResType b) - { - switch (a) { - case RES_INT: - case RES_SHORT: - case RES_BYTE: - case RES_BOOL: - return (b == RES_INT || b == RES_SHORT || b == RES_BYTE || b == RES_BOOL); - case RES_FLOAT: - case RES_DOUBLE: - return (b == RES_FLOAT || b == RES_DOUBLE); - case RES_INT64: - return b == RES_INT64; - case RES_STRING: - case RES_LONG_STRING: - case RES_JSONSTRING: - return (b == RES_STRING || b == RES_LONG_STRING || b == RES_JSONSTRING); - case RES_DATA: - case RES_LONG_DATA: - return (b == RES_DATA || b == RES_LONG_DATA); - case RES_TENSOR: - return (b == RES_TENSOR); - case RES_FEATUREDATA: - return (b == RES_FEATUREDATA); - } - return false; - } + static bool IsVariableSize(ResType t) { return ResTypeUtils::IsVariableSize(t); } + static bool IsBinaryCompatible(ResType a, ResType b) { return ResTypeUtils::IsBinaryCompatible(a, b); } + static bool IsRuntimeCompatible(ResType a, ResType b) { return ResTypeUtils::IsRuntimeCompatible(a, b); } // whether last config seen wanted useV8geoPositions = true static bool wantedV8geoPositions(); @@ -182,7 +107,7 @@ public: * @return the name of the given result field type. * @param resType enum value of a result field type. **/ - static const char *GetResTypeName(ResType type); + static const char *GetResTypeName(ResType type) { return ResTypeUtils::GetResTypeName(type); } /** * Discard the current configuration and start over. After this diff --git a/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.cpp b/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.cpp index 4cf36785f69..66b15c1c8a9 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.cpp @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "resultpacker.h" +#include "resultconfig.h" #include <vespa/searchcommon/common/undefinedvalues.h> #include <vespa/vespalib/util/size_literals.h> diff --git a/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.h b/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.h index f2460f3d3c3..816433652b8 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/resultpacker.h @@ -2,9 +2,14 @@ #pragma once -#include "resultconfig.h" +#include "res_type_utils.h" +#include "resultclass.h" +#include <vespa/searchlib/util/rawbuf.h> namespace search::docsummary { + +class ResultConfig; + /** * An Object of this class may be used to create docsum blobs. A * single blob is created by first indicating what result class the @@ -27,11 +32,8 @@ private: const ResConfigEntry *_cfgEntry; // current field of current blob bool _error; // error flag for current blob - static const char *GetResTypeName(ResType type) - { return ResultConfig::GetResTypeName(type); } - - static bool IsBinaryCompatible(ResType a, ResType b) - { return ResultConfig::IsBinaryCompatible(a, b); } + static const char *GetResTypeName(ResType type) { return ResTypeUtils::GetResTypeName(type); } + static bool IsBinaryCompatible(ResType a, ResType b) { return ResTypeUtils::IsBinaryCompatible(a, b); } void WarnType(ResType type) const; void SetFormatError(ResType type); diff --git a/searchsummary/src/vespa/searchsummary/docsummary/simple_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/simple_dfw.cpp new file mode 100644 index 00000000000..8cc872378bd --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/simple_dfw.cpp @@ -0,0 +1,13 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "simple_dfw.h" + +namespace search::docsummary { + +void +SimpleDFW::insertField(uint32_t docid, GeneralResult *, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) +{ + insertField(docid, state, type, target); +} + +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/simple_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/simple_dfw.h new file mode 100644 index 00000000000..521bae6497b --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/simple_dfw.h @@ -0,0 +1,16 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "docsum_field_writer.h" + +namespace search::docsummary { + +class SimpleDFW : public DocsumFieldWriter +{ +public: + virtual void insertField(uint32_t docid, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) = 0; + void insertField(uint32_t docid, GeneralResult *, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) override; +}; + +} 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 aec55977546..38a9cc8c50b 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 @@ -9,6 +9,7 @@ #include <vespa/searchlib/common/matching_elements.h> #include <vespa/searchlib/common/matching_elements_fields.h> #include <vespa/vespalib/data/slime/cursor.h> +#include <vespa/vespalib/data/slime/inserter.h> #include <vespa/vespalib/util/stash.h> #include <algorithm> #include <cassert> diff --git a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.cpp index f920b7be0cd..c28e986612c 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.cpp @@ -3,6 +3,7 @@ #include "summaryfeaturesdfw.h" #include "docsumstate.h" #include <vespa/vespalib/data/slime/cursor.h> +#include <vespa/vespalib/data/slime/inserter.h> #include <vespa/log/log.h> LOG_SETUP(".searchlib.docsummary.summaryfeaturesdfw"); diff --git a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h index 6c4084b0221..d12feb69182 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h @@ -2,13 +2,13 @@ #pragma once -#include "docsumfieldwriter.h" +#include "simple_dfw.h" namespace search::docsummary { class IDocsumEnvironment; -class SummaryFeaturesDFW : public ISimpleDFW +class SummaryFeaturesDFW : public SimpleDFW { private: IDocsumEnvironment * _env; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.cpp index d12418dc254..dc6d9524ee4 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.cpp @@ -1,8 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "textextractordfw.h" -#include "tokenizer.h" #include "docsumstate.h" +#include "general_result.h" +#include "tokenizer.h" +#include "resultconfig.h" +#include <vespa/vespalib/data/slime/inserter.h> #include <vespa/log/log.h> LOG_SETUP(".searchlib.docsummary.textextractordfw"); diff --git a/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.h b/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.h index 10764e5c21d..3bce2ae5cd7 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/textextractordfw.h @@ -2,14 +2,16 @@ #pragma once -#include "docsumfieldwriter.h" +#include "docsum_field_writer.h" namespace search::docsummary { +class ResultConfig; + /** * This is the docsum field writer used to extract the original text from a disk summary on the juniper format. **/ -class TextExtractorDFW : public IDocsumFieldWriter +class TextExtractorDFW : public DocsumFieldWriter { private: TextExtractorDFW(const TextExtractorDFW &); @@ -19,7 +21,7 @@ private: public: TextExtractorDFW(); - ~TextExtractorDFW() {} + ~TextExtractorDFW() override = default; bool init(const vespalib::string & fieldName, const vespalib::string & inputField, const ResultConfig & config); bool IsGenerated() const override { return false; } void insertField(uint32_t docid, GeneralResult *gres, GetDocsumsState *state, |