From d2b1b8857eb0f36a111af394509eca1a66d121b8 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Tue, 5 Jul 2022 20:38:22 +0200 Subject: Add insert_summary_field member function to IDoscumStoreDocument. --- .../docsummary/docsum_store_document.cpp | 15 ++++++++++++ .../docsummary/docsum_store_document.h | 1 + .../searchsummary/docsummary/docsumfieldwriter.cpp | 15 ++++-------- .../searchsummary/docsummary/docsumwriter.cpp | 28 +++++++--------------- .../searchsummary/docsummary/general_result.h | 2 ++ .../docsummary/i_docsum_store_document.h | 3 +++ .../src/vespa/vsm/vsm/docsumfilter.cpp | 14 +++++++++++ 7 files changed, 49 insertions(+), 29 deletions(-) diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp index c0b894ddc0a..f97956be6da 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp @@ -1,6 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "docsum_store_document.h" +#include "check_undefined_value_visitor.h" +#include "summaryfieldconverter.h" #include #include @@ -28,4 +30,17 @@ DocsumStoreDocument::get_field_value(const vespalib::string& field_name) const return {}; } +void +DocsumStoreDocument::insert_summary_field(const vespalib::string& field_name, vespalib::slime::Inserter& inserter) const +{ + auto field_value = get_field_value(field_name); + if (field_value) { + CheckUndefinedValueVisitor check_undefined; + field_value->accept(check_undefined); + if (!check_undefined.is_undefined()) { + SummaryFieldConverter::insert_summary_field(false, *field_value, inserter); + } + } +} + } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h index 4508132e7e0..66a5a74fa8d 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h @@ -18,6 +18,7 @@ public: DocsumStoreDocument(std::unique_ptr document); ~DocsumStoreDocument() override; std::unique_ptr get_field_value(const vespalib::string& field_name) const override; + void insert_summary_field(const vespalib::string& field_name, vespalib::slime::Inserter& inserter) const override; }; } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp index e70b094aa64..416526bead3 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumfieldwriter.cpp @@ -1,7 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "docsumfieldwriter.h" -#include "check_undefined_value_visitor.h" +#include "i_docsum_store_document.h" #include "idocsumenvironment.h" #include "docsumstate.h" #include "summaryfieldconverter.h" @@ -90,16 +90,11 @@ CopyDFW::insertField(uint32_t /*docid*/, GeneralResult *gres, GetDocsumsState *, ResEntry *entry = gres->GetEntry(idx); if (entry == nullptr) { - auto input_field_value = gres->get_field_value(_input_field_name); - if (input_field_value) { - CheckUndefinedValueVisitor check_undefined; - input_field_value->accept(check_undefined); - if (!check_undefined.is_undefined()) { - SummaryFieldConverter::insert_summary_field(false, *input_field_value, target); - } + const auto* document = gres->get_document(); + if (document != nullptr) { + document->insert_summary_field(_input_field_name, target); } - } else if (IsRuntimeCompatible(entry->_type, type)) - { + } else if (IsRuntimeCompatible(entry->_type, type)) { switch (type) { case RES_INT: { uint32_t val32 = entry->_intval; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp index de8bb36e98b..a5ad577e240 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp @@ -1,9 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "docsumwriter.h" -#include "check_undefined_value_visitor.h" #include "docsumstate.h" #include "docsum_field_writer_state.h" +#include "i_docsum_store_document.h" #include "summaryfieldconverter.h" #include #include @@ -20,22 +20,6 @@ using vespalib::Issue; namespace search::docsummary { -namespace { - -void insert_document_field(const vespalib::string& field_name, const GeneralResult& gres, Inserter &inserter) -{ - auto input_field_value = gres.get_field_value(field_name); - if (input_field_value) { - CheckUndefinedValueVisitor check_undefined; - input_field_value->accept(check_undefined); - if (!check_undefined.is_undefined()) { - SummaryFieldConverter::insert_summary_field(false, *input_field_value, inserter); - } - } -} - -} - uint32_t IDocsumWriter::slime2RawBuf(const Slime & slime, RawBuf & buf) { @@ -116,7 +100,10 @@ static void convertEntry(const ResConfigEntry *resCfg, LOG_ASSERT(resCfg != nullptr); if (entry == nullptr || entry->_not_present) { // Entry is not present in docsum blob - insert_document_field(resCfg->_bindname, gres, inserter); + const auto* document = gres.get_document(); + if (document != nullptr) { + document->insert_summary_field(resCfg->_bindname, inserter); + } return; } @@ -220,7 +207,10 @@ DynamicDocsumWriter::insertDocsum(const ResolveClassInfo & rci, uint32_t docid, LOG_ASSERT(entry != nullptr); convertEntry(outCfg, entry, gres, inserter, slime); } else { - insert_document_field(outCfg->_bindname, gres, inserter); + const auto* document = gres.get_document(); + if (document != nullptr) { + document->insert_summary_field(outCfg->_bindname, inserter); + } } } } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/general_result.h b/searchsummary/src/vespa/searchsummary/docsummary/general_result.h index 93114dbb44d..f23d5ff5ea7 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/general_result.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/general_result.h @@ -46,6 +46,8 @@ public: return false; } } + + const IDocsumStoreDocument *get_document() const noexcept { return _document; } }; } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h b/searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h index 3fbf54b18a9..f81412eb34c 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h @@ -7,6 +7,8 @@ namespace document { class FieldValue; } +namespace vespalib::slime { struct Inserter; } + namespace search::docsummary { /** @@ -19,6 +21,7 @@ class IDocsumStoreDocument public: virtual ~IDocsumStoreDocument() = default; virtual std::unique_ptr get_field_value(const vespalib::string& field_name) const = 0; + virtual void insert_summary_field(const vespalib::string& field_name, vespalib::slime::Inserter& inserter) const = 0; }; } diff --git a/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp b/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp index a5fe08da605..5341379fe96 100644 --- a/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp +++ b/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp @@ -134,6 +134,7 @@ public: DocsumStoreVsmDocument(const document::Document* document); ~DocsumStoreVsmDocument() override; std::unique_ptr get_field_value(const vespalib::string& field_name) const override; + void insert_summary_field(const vespalib::string& field_name, vespalib::slime::Inserter& inserter) const override; }; DocsumStoreVsmDocument::DocsumStoreVsmDocument(const document::Document* document) @@ -158,6 +159,19 @@ DocsumStoreVsmDocument::get_field_value(const vespalib::string& field_name) cons return {}; } +void +DocsumStoreVsmDocument::insert_summary_field(const vespalib::string& field_name, vespalib::slime::Inserter& inserter) const +{ + auto field_value = get_field_value(field_name); + if (field_value) { + CheckUndefinedValueVisitor check_undefined; + field_value->accept(check_undefined); + if (!check_undefined.is_undefined()) { + SummaryFieldConverter::insert_summary_field(false, *field_value, inserter); + } + } +} + } FieldPath -- cgit v1.2.3