diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-08-19 12:44:46 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-08-19 12:47:03 +0200 |
commit | 9937b33bb8700922adb654b5bb1b4b8b50d1fd0a (patch) | |
tree | e282eb29fa3243525d8c69e8887186ac5902c619 | |
parent | a572e24ced3c57d7f4686fc7b5d4af2c37462268 (diff) |
Adjust signature for IDocsumStoreDocument::get_field_value() to return DocsumStoreFieldValue.
7 files changed, 52 insertions, 19 deletions
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp index e6c8d0b6ab8..71800eb2128 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp @@ -16,7 +16,7 @@ DocsumStoreDocument::DocsumStoreDocument(std::unique_ptr<document::Document> doc DocsumStoreDocument::~DocsumStoreDocument() = default; -std::unique_ptr<document::FieldValue> +DocsumStoreFieldValue DocsumStoreDocument::get_field_value(const vespalib::string& field_name) const { if (_document) { @@ -24,11 +24,11 @@ DocsumStoreDocument::get_field_value(const vespalib::string& field_name) const auto value(field.getDataType().createFieldValue()); if (value) { if (_document->getValue(field, *value)) { - return value; + return DocsumStoreFieldValue(std::move(value)); } } } - return {}; + return DocsumStoreFieldValue(); } void diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h index 3b0bea6e721..26cccc9970f 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h @@ -17,7 +17,7 @@ class DocsumStoreDocument : public IDocsumStoreDocument public: DocsumStoreDocument(std::unique_ptr<document::Document> document); ~DocsumStoreDocument() override; - std::unique_ptr<document::FieldValue> get_field_value(const vespalib::string& field_name) const override; + DocsumStoreFieldValue 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; void insert_document_id(vespalib::slime::Inserter& inserter) const override; }; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_field_value.h b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_field_value.h new file mode 100644 index 00000000000..d06a2ab8287 --- /dev/null +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_field_value.h @@ -0,0 +1,38 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <vespa/document/fieldvalue/fieldvalue.h> +#include <memory> + +namespace search::docsummary { + +/* + * Class containing a field value returned from an IDocsumStoreDocument. + */ +class DocsumStoreFieldValue { + const document::FieldValue* _value; + std::unique_ptr<document::FieldValue> _value_store; +public: + explicit DocsumStoreFieldValue(std::unique_ptr<document::FieldValue> value) noexcept + : _value(value.get()), + _value_store(std::move(value)) + { + } + explicit DocsumStoreFieldValue(const document::FieldValue* value) noexcept + : _value(value), + _value_store() + { + } + DocsumStoreFieldValue() + : DocsumStoreFieldValue(nullptr) + { + } + ~DocsumStoreFieldValue() = default; + const document::FieldValue& operator*() const noexcept { return *_value; } + const document::FieldValue* operator->() const noexcept { return _value; } + const document::FieldValue* get() const noexcept { return _value; } + operator bool () const noexcept { return _value != nullptr; } +}; + +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp b/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp index 825c3b39c1b..359959391fd 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp @@ -62,13 +62,13 @@ GeneralResult::GetPresentEntryFromEnumValue(uint32_t value) return GetPresentEntry(idx); } -std::unique_ptr<document::FieldValue> +DocsumStoreFieldValue GeneralResult::get_field_value(const vespalib::string& field_name) const { if (_document != nullptr) { return _document->get_field_value(field_name); } - return {}; + return DocsumStoreFieldValue(); } bool diff --git a/searchsummary/src/vespa/searchsummary/docsummary/general_result.h b/searchsummary/src/vespa/searchsummary/docsummary/general_result.h index cff27a496e3..8f7a1377502 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/general_result.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/general_result.h @@ -4,10 +4,7 @@ #include "resultclass.h" #include "docsumstorevalue.h" - -namespace document { -class FieldValue; -} +#include "docsum_store_field_value.h" namespace search::docsummary { @@ -42,7 +39,7 @@ public: } ResEntry *GetPresentEntry(const char *name); ResEntry *GetPresentEntryFromEnumValue(uint32_t val); - std::unique_ptr<document::FieldValue> get_field_value(const vespalib::string& field_name) const; + DocsumStoreFieldValue get_field_value(const vespalib::string& field_name) const; bool unpack(const char *buf, const size_t buflen); bool inplaceUnpack(const DocsumStoreValue &value) { 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 c177568c467..b9c2ae76e7a 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h @@ -2,10 +2,8 @@ #pragma once +#include "docsum_store_field_value.h" #include <vespa/vespalib/stllike/string.h> -#include <memory> - -namespace document { class FieldValue; } namespace vespalib::slime { struct Inserter; } @@ -20,7 +18,7 @@ class IDocsumStoreDocument { public: virtual ~IDocsumStoreDocument() = default; - virtual std::unique_ptr<document::FieldValue> get_field_value(const vespalib::string& field_name) const = 0; + virtual DocsumStoreFieldValue 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; virtual void insert_document_id(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 5bcead79f97..3d0f8ed6e37 100644 --- a/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp +++ b/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp @@ -133,7 +133,7 @@ class DocsumStoreVsmDocument : public IDocsumStoreDocument public: DocsumStoreVsmDocument(const document::Document* document); ~DocsumStoreVsmDocument() override; - std::unique_ptr<document::FieldValue> get_field_value(const vespalib::string& field_name) const override; + DocsumStoreFieldValue 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; void insert_document_id(vespalib::slime::Inserter& inserter) const override; }; @@ -145,7 +145,7 @@ DocsumStoreVsmDocument::DocsumStoreVsmDocument(const document::Document* documen DocsumStoreVsmDocument::~DocsumStoreVsmDocument() = default; -std::unique_ptr<document::FieldValue> +DocsumStoreFieldValue DocsumStoreVsmDocument::get_field_value(const vespalib::string& field_name) const { if (_document != nullptr) { @@ -153,11 +153,11 @@ DocsumStoreVsmDocument::get_field_value(const vespalib::string& field_name) cons auto value(field.getDataType().createFieldValue()); if (value) { if (_document->getValue(field, *value)) { - return value; + return DocsumStoreFieldValue(std::move(value)); } } } - return {}; + return DocsumStoreFieldValue(); } void |