aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-07-05 12:06:16 +0200
committerTor Egge <Tor.Egge@online.no>2022-07-05 12:06:16 +0200
commitd836aecf76195fa79c3fe2b5fbec73d84fc7ed41 (patch)
tree6f0eed5746294f675db272b16a2907a1d0e63348 /searchsummary
parentf2802027f402d5b16f5fffb9cfc5a3d7f7401ab4 (diff)
Add IDocsumStoreDocument, an interface for accessing the original document
when generating a document summary.
Diffstat (limited to 'searchsummary')
-rw-r--r--searchsummary/src/tests/docsummary/matched_elements_filter/matched_elements_filter_test.cpp3
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt1
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp31
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h23
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsumstorevalue.cpp20
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsumstorevalue.h25
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp11
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/general_result.h5
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h24
9 files changed, 100 insertions, 43 deletions
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 de6b704189d..675af283ee8 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
@@ -15,6 +15,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/docsum_store_document.h>
#include <vespa/searchsummary/docsummary/docsumstate.h>
#include <vespa/searchsummary/docsummary/idocsumenvironment.h>
#include <vespa/searchsummary/docsummary/matched_elements_filter_dfw.h>
@@ -132,7 +133,7 @@ public:
const char* buf;
uint32_t buf_len;
assert(_packer.GetDocsumBlob(&buf, &buf_len));
- return DocsumStoreValue(buf, buf_len, std::move(doc));
+ return DocsumStoreValue(buf, buf_len, std::make_unique<DocsumStoreDocument>(std::move(doc)));
}
};
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt b/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt
index 4a5648d0842..947fe9deeab 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt
+++ b/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt
@@ -9,6 +9,7 @@ vespa_add_library(searchsummary_docsummary OBJECT
docsumconfig.cpp
docsumfieldwriter.cpp
docsumstate.cpp
+ docsum_store_document.cpp
docsumstorevalue.cpp
docsumwriter.cpp
dynamicteaserdfw.cpp
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp
new file mode 100644
index 00000000000..c0b894ddc0a
--- /dev/null
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp
@@ -0,0 +1,31 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "docsum_store_document.h"
+#include <vespa/document/datatype/datatype.h>
+#include <vespa/document/fieldvalue/document.h>
+
+namespace search::docsummary {
+
+DocsumStoreDocument::DocsumStoreDocument(std::unique_ptr<document::Document> document)
+ : _document(std::move(document))
+{
+}
+
+DocsumStoreDocument::~DocsumStoreDocument() = default;
+
+std::unique_ptr<document::FieldValue>
+DocsumStoreDocument::get_field_value(const vespalib::string& field_name) const
+{
+ if (_document) {
+ const document::Field& field = _document->getField(field_name);
+ auto value(field.getDataType().createFieldValue());
+ if (value) {
+ if (_document->getValue(field, *value)) {
+ return value;
+ }
+ }
+ }
+ return {};
+}
+
+}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h
new file mode 100644
index 00000000000..4508132e7e0
--- /dev/null
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h
@@ -0,0 +1,23 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "i_docsum_store_document.h"
+
+namespace document { class Document; }
+
+namespace search::docsummary {
+
+/**
+ * Class providing access to a document retrieved from an IDocsumStore.
+ **/
+class DocsumStoreDocument : public IDocsumStoreDocument
+{
+ std::unique_ptr<document::Document> _document;
+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;
+};
+
+}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumstorevalue.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumstorevalue.cpp
index 8fbbeb6db28..a60ae93b58f 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/docsumstorevalue.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumstorevalue.cpp
@@ -1,35 +1,25 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "docsumstorevalue.h"
-#include <vespa/document/fieldvalue/document.h>
+#include "i_docsum_store_document.h"
namespace search::docsummary {
DocsumStoreValue::DocsumStoreValue()
: _value(static_cast<const char*>(0), 0),
- _document(),
- _document_ptr(nullptr)
+ _document()
{
}
DocsumStoreValue::DocsumStoreValue(const char *pt_, uint32_t len_)
: _value(pt_, len_),
- _document(),
- _document_ptr(nullptr)
+ _document()
{
}
-DocsumStoreValue::DocsumStoreValue(const char *pt_, uint32_t len_, std::unique_ptr<document::Document> document_)
+DocsumStoreValue::DocsumStoreValue(const char *pt_, uint32_t len_, std::unique_ptr<IDocsumStoreDocument> document)
: _value(pt_, len_),
- _document(std::move(document_)),
- _document_ptr(_document.get())
-{
-}
-
-DocsumStoreValue::DocsumStoreValue(const char *pt_, uint32_t len_, const document::Document* document_ptr)
- : _value(pt_, len_),
- _document(),
- _document_ptr(document_ptr)
+ _document(std::move(document))
{
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumstorevalue.h b/searchsummary/src/vespa/searchsummary/docsummary/docsumstorevalue.h
index bd6454d9c87..bdc4e7b9e19 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/docsumstorevalue.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumstorevalue.h
@@ -5,10 +5,10 @@
#include <memory>
#include <utility>
-namespace document { class Document; }
-
namespace search::docsummary {
+class IDocsumStoreDocument;
+
/**
* Simple wrapper class containing the location and size of a docsum
* blob located in memory. The memory containing the docsum blob is
@@ -19,11 +19,11 @@ class DocsumStoreValue
{
private:
std::pair<const char *, uint32_t> _value;
- // The document instance that was used to generate the docsum blob.
+ // An interface for accessing the document instance that was used
+ // to generate the docsum blob.
// Note: This is temporary until the docsummary framework is simplified,
// and the docsum blob concept is removed.
- std::unique_ptr<document::Document> _document;
- const document::Document* _document_ptr;
+ std::unique_ptr<IDocsumStoreDocument> _document;
public:
DocsumStoreValue(const DocsumStoreValue&) = delete;
@@ -47,18 +47,9 @@ public:
*
* @param pt_ docsum location
* @param len_ docsum size
- * @param document_ document instance used to generate the docsum blob
- **/
- DocsumStoreValue(const char *pt_, uint32_t len_, std::unique_ptr<document::Document> document_);
-
- /**
- * Construct object encapsulating the given location and size.
- *
- * @param pt_ docsum location
- * @param len_ docsum size
- * @param document_ptr document instance used to generate the docsum blob. Note: external ownership.
+ * @param document docsum store document instance
**/
- DocsumStoreValue(const char *pt_, uint32_t len_, const document::Document* document_ptr);
+ DocsumStoreValue(const char *pt_, uint32_t len_, std::unique_ptr<IDocsumStoreDocument> document);
~DocsumStoreValue();
@@ -87,7 +78,7 @@ public:
**/
bool valid() const { return (_value.first != 0) && (_value.second >= sizeof(uint32_t)); }
- const document::Document* get_document() const { return _document_ptr; }
+ const IDocsumStoreDocument* get_document() const { return _document.get(); }
};
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp b/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp
index 781cce8f972..12391d26ce1 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/general_result.cpp
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "general_result.h"
+#include "i_docsum_store_document.h"
#include "resultconfig.h"
#include <vespa/document/fieldvalue/document.h>
#include <vespa/document/datatype/datatype.h>
@@ -73,15 +74,9 @@ std::unique_ptr<document::FieldValue>
GeneralResult::get_field_value(const vespalib::string& field_name) const
{
if (_document != nullptr) {
- const document::Field & field = _document->getField(field_name);
- auto value(field.getDataType().createFieldValue());
- if (value) {
- if (_document->getValue(field, *value)) {
- return value;
- }
- }
+ return _document->get_field_value(field_name);
}
- return std::unique_ptr<document::FieldValue>();
+ return {};
}
bool
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/general_result.h b/searchsummary/src/vespa/searchsummary/docsummary/general_result.h
index a5664a8a606..93114dbb44d 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/general_result.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/general_result.h
@@ -6,12 +6,13 @@
#include "docsumstorevalue.h"
namespace document {
-class Document;
class FieldValue;
}
namespace search::docsummary {
+class DocsumStoreDocument;
+
class GeneralResult
{
private:
@@ -21,7 +22,7 @@ private:
const ResultClass *_resClass;
uint32_t _entrycnt;
ResEntry *_entries;
- const document::Document* _document;
+ const IDocsumStoreDocument* _document;
void AllocEntries();
void FreeEntries();
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h b/searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h
new file mode 100644
index 00000000000..3fbf54b18a9
--- /dev/null
+++ b/searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h
@@ -0,0 +1,24 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/vespalib/stllike/string.h>
+#include <memory>
+
+namespace document { class FieldValue; }
+
+namespace search::docsummary {
+
+/**
+ * Interface class providing access to a document retrieved from an
+ * IDocsumStore. Some implementations (e.g. DocsumStoreVsmDocument) might
+ * apply transforms when accessing some fields.
+ **/
+class IDocsumStoreDocument
+{
+public:
+ virtual ~IDocsumStoreDocument() = default;
+ virtual std::unique_ptr<document::FieldValue> get_field_value(const vespalib::string& field_name) const = 0;
+};
+
+}