aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-07-12 16:20:12 +0200
committerTor Egge <Tor.Egge@online.no>2022-07-12 16:20:12 +0200
commit54700f81a5e835bd995c66f82ffac262f32a2718 (patch)
treefaf1a78d36a75b4a52b0f361777e26d3562db56f
parentdaa55302054e5ec62aaa3b0ce2d5221b91af2405 (diff)
Add DocumentIdDFW, used to print document id without using docsum blob.
-rw-r--r--searchsummary/CMakeLists.txt1
-rw-r--r--searchsummary/src/tests/docsummary/document_id_dfw/CMakeLists.txt10
-rw-r--r--searchsummary/src/tests/docsummary/document_id_dfw/document_id_dfw_test.cpp153
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt1
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp11
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h1
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp4
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/document_id_dfw.cpp31
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/document_id_dfw.h22
-rw-r--r--searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h1
-rw-r--r--streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp11
11 files changed, 246 insertions, 0 deletions
diff --git a/searchsummary/CMakeLists.txt b/searchsummary/CMakeLists.txt
index 17b46499317..8c34f1b2016 100644
--- a/searchsummary/CMakeLists.txt
+++ b/searchsummary/CMakeLists.txt
@@ -19,6 +19,7 @@ vespa_define_module(
src/tests/docsummary
src/tests/docsummary/attribute_combiner
src/tests/docsummary/attributedfw
+ src/tests/docsummary/document_id_dfw
src/tests/docsummary/matched_elements_filter
src/tests/docsummary/slime_summary
src/tests/docsummary/summary_field_converter
diff --git a/searchsummary/src/tests/docsummary/document_id_dfw/CMakeLists.txt b/searchsummary/src/tests/docsummary/document_id_dfw/CMakeLists.txt
new file mode 100644
index 00000000000..3591a36c8de
--- /dev/null
+++ b/searchsummary/src/tests/docsummary/document_id_dfw/CMakeLists.txt
@@ -0,0 +1,10 @@
+# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(searchsummary_document_id_dfw_test_app TEST
+ SOURCES
+ document_id_dfw_test.cpp
+ DEPENDS
+ searchsummary
+ searchsummary_test
+ GTest::GTest
+)
+vespa_add_test(NAME searchsummary_document_id_dfw_test_app COMMAND searchsummary_document_id_dfw_test_app)
diff --git a/searchsummary/src/tests/docsummary/document_id_dfw/document_id_dfw_test.cpp b/searchsummary/src/tests/docsummary/document_id_dfw/document_id_dfw_test.cpp
new file mode 100644
index 00000000000..0ea78b722c0
--- /dev/null
+++ b/searchsummary/src/tests/docsummary/document_id_dfw/document_id_dfw_test.cpp
@@ -0,0 +1,153 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/document/base/documentid.h>
+#include <vespa/document/datatype/documenttype.h>
+#include <vespa/document/fieldvalue/document.h>
+#include <vespa/document/repo/configbuilder.h>
+#include <vespa/document/repo/documenttyperepo.h>
+#include <vespa/searchsummary/docsummary/docsum_blob_entry_filter.h>
+#include <vespa/searchsummary/docsummary/docsum_store_document.h>
+#include <vespa/searchsummary/docsummary/document_id_dfw.h>
+#include <vespa/searchsummary/docsummary/general_result.h>
+#include <vespa/searchsummary/docsummary/resultconfig.h>
+#include <vespa/searchsummary/docsummary/resultpacker.h>
+#include <vespa/vespalib/data/slime/slime.h>
+#include <vespa/vespalib/gtest/gtest.h>
+#include <iostream>
+#include <memory>
+
+using document::Document;
+using document::DocumentId;
+using document::DocumentType;
+using document::DocumentTypeRepo;
+using document::config_builder::DocumenttypesConfigBuilderHelper;
+using document::config_builder::Struct;
+using search::docsummary::DocsumBlobEntryFilter;
+using search::docsummary::DocsumStoreDocument;
+using search::docsummary::DocsumStoreValue;
+using search::docsummary::DocumentIdDFW;
+using search::docsummary::IDocsumStoreDocument;
+using search::docsummary::ResultClass;
+using search::docsummary::ResultConfig;
+using search::docsummary::ResultPacker;
+using search::docsummary::GeneralResult;
+using vespalib::Slime;
+using vespalib::slime::Cursor;
+using vespalib::slime::ObjectInserter;
+using vespalib::slime::SlimeInserter;
+
+namespace {
+
+const int32_t doc_type_id = 787121340;
+const vespalib::string doc_type_name = "test";
+const vespalib::string header_name = doc_type_name + ".header";
+const vespalib::string body_name = doc_type_name + ".body";
+
+
+std::unique_ptr<const DocumentTypeRepo>
+make_doc_type_repo()
+{
+ DocumenttypesConfigBuilderHelper builder;
+ builder.document(doc_type_id, doc_type_name,
+ Struct(header_name), Struct(body_name));
+ return std::unique_ptr<const DocumentTypeRepo>(new DocumentTypeRepo(builder.config()));
+}
+
+class DocumentIdDFWTest : public ::testing::Test
+{
+ vespalib::string _field_name;
+ vespalib::Memory _field_name_view;
+ DocsumBlobEntryFilter _docsum_blob_entry_filter;
+ std::unique_ptr<ResultConfig> _result_config;
+ std::unique_ptr<ResultPacker> _packer; // owns docsum blob
+ std::unique_ptr<const DocumentTypeRepo> _repo;
+ const DocumentType* _document_type;
+
+protected:
+ DocumentIdDFWTest();
+ ~DocumentIdDFWTest() override;
+
+ std::unique_ptr<DocsumStoreDocument> make_docsum_store_document(const vespalib::string &id);
+ std::unique_ptr<DocsumStoreValue> make_docsum_store_value(std::unique_ptr<DocsumStoreDocument> doc);
+ vespalib::Slime write(const DocsumStoreValue& value);
+ vespalib::Memory get_field_name_view() const noexcept { return _field_name_view; }
+};
+
+DocumentIdDFWTest::DocumentIdDFWTest()
+ : testing::Test(),
+ _field_name("documentid"),
+ _field_name_view(_field_name.data(), _field_name.size()),
+ _docsum_blob_entry_filter(DocsumBlobEntryFilter().add_skip(search::docsummary::RES_LONG_STRING)),
+ _result_config(std::make_unique<ResultConfig>(_docsum_blob_entry_filter)),
+ _packer(std::make_unique<ResultPacker>(_result_config.get())),
+ _repo(make_doc_type_repo()),
+ _document_type(_repo->getDocumentType(doc_type_name))
+{
+ auto* cfg = _result_config->AddResultClass("default", 0);
+ cfg->AddConfigEntry(_field_name.c_str(), search::docsummary::RES_LONG_STRING);
+ _result_config->CreateEnumMaps();
+}
+
+
+DocumentIdDFWTest::~DocumentIdDFWTest() = default;
+
+
+std::unique_ptr<DocsumStoreDocument>
+DocumentIdDFWTest::make_docsum_store_document(const vespalib::string& id)
+{
+ auto doc = std::make_unique<Document>(*_document_type, DocumentId(id));
+ doc->setRepo(*_repo);
+ return std::make_unique<DocsumStoreDocument>(std::move(doc));
+}
+
+std::unique_ptr<DocsumStoreValue>
+DocumentIdDFWTest::make_docsum_store_value(std::unique_ptr<DocsumStoreDocument> doc)
+{
+ EXPECT_TRUE(_packer->Init(0));
+ const char *ptr = nullptr;
+ uint32_t len = 0;
+ EXPECT_TRUE(_packer->GetDocsumBlob(&ptr, &len));
+ return std::make_unique<DocsumStoreValue>(ptr, len, std::move(doc));
+}
+
+vespalib::Slime
+DocumentIdDFWTest::write(const DocsumStoreValue& value)
+{
+ auto result = std::make_unique<GeneralResult>(_result_config->LookupResultClass(0));
+ EXPECT_TRUE(result->inplaceUnpack(value));
+ Slime slime;
+ SlimeInserter top_inserter(slime);
+ Cursor & docsum = top_inserter.insertObject();
+ ObjectInserter field_inserter(docsum, _field_name_view);
+ DocumentIdDFW writer;
+ writer.insertField(0, result.get(), nullptr, search::docsummary::RES_LONG_STRING, field_inserter);
+ return slime;
+}
+
+TEST_F(DocumentIdDFWTest, insert_document_id)
+{
+ vespalib::string id("id::test::0");
+ auto doc = make_docsum_store_document(id);
+ auto dsvalue = make_docsum_store_value(std::move(doc));
+ auto slime = write(*dsvalue);
+ EXPECT_TRUE(slime.get()[get_field_name_view()].valid());
+ EXPECT_EQ(id, slime.get()[get_field_name_view()].asString().make_string());
+}
+
+TEST_F(DocumentIdDFWTest, insert_document_id_no_document_doc)
+{
+ auto dsvalue = make_docsum_store_value(std::make_unique<DocsumStoreDocument>(std::unique_ptr<Document>()));
+ auto slime = write(*dsvalue);
+ EXPECT_FALSE(slime.get()[get_field_name_view()].valid());
+}
+
+TEST_F(DocumentIdDFWTest, insert_document_id_no_docsum_store_doc)
+{
+ auto dsvalue = make_docsum_store_value({});
+ auto slime = write(*dsvalue);
+ EXPECT_FALSE(slime.get()[get_field_name_view()].valid());
+}
+
+}
+
+GTEST_MAIN_RUN_ALL_TESTS()
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt b/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt
index e3272fb36de..e262482cddb 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt
+++ b/searchsummary/src/vespa/searchsummary/docsummary/CMakeLists.txt
@@ -13,6 +13,7 @@ vespa_add_library(searchsummary_docsummary OBJECT
docsumstate.cpp
docsumstorevalue.cpp
docsumwriter.cpp
+ document_id_dfw.cpp
dynamicteaserdfw.cpp
empty_dfw.cpp
general_result.cpp
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp
index e525989e972..e6c8d0b6ab8 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.cpp
@@ -5,6 +5,7 @@
#include "summaryfieldconverter.h"
#include <vespa/document/datatype/datatype.h>
#include <vespa/document/fieldvalue/document.h>
+#include <vespa/vespalib/data/slime/inserter.h>
namespace search::docsummary {
@@ -39,4 +40,14 @@ DocsumStoreDocument::insert_summary_field(const vespalib::string& field_name, ve
}
}
+void
+DocsumStoreDocument::insert_document_id(vespalib::slime::Inserter& inserter) const
+{
+ if (_document) {
+ auto id = _document->getId().toString();
+ vespalib::Memory id_view(id.data(), id.size());
+ inserter.insertString(id_view);
+ }
+}
+
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h
index 66a5a74fa8d..3b0bea6e721 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsum_store_document.h
@@ -19,6 +19,7 @@ public:
~DocsumStoreDocument() override;
std::unique_ptr<document::FieldValue> 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/docsumconfig.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp
index 376d4f90204..fea11923858 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp
+++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp
@@ -4,6 +4,7 @@
#include "attribute_combiner_dfw.h"
#include "copy_dfw.h"
#include "docsumwriter.h"
+#include "document_id_dfw.h"
#include "empty_dfw.h"
#include "geoposdfw.h"
#include "idocsumenvironment.h"
@@ -113,6 +114,9 @@ DynamicDocsumConfig::createFieldWriter(const string & fieldName, const string &
*attr_ctx, matching_elems_fields);
rc = static_cast<bool>(fieldWriter);
}
+ } else if (overrideName == "documentid") {
+ fieldWriter = std::make_unique<DocumentIdDFW>();
+ rc = true;
} else {
throw IllegalArgumentException("unknown override operation '" + overrideName + "' for field '" + fieldName + "'.");
}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/document_id_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/document_id_dfw.cpp
new file mode 100644
index 00000000000..8fcf7c95cdc
--- /dev/null
+++ b/searchsummary/src/vespa/searchsummary/docsummary/document_id_dfw.cpp
@@ -0,0 +1,31 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "document_id_dfw.h"
+#include "general_result.h"
+#include "i_docsum_store_document.h"
+
+namespace search::docsummary {
+
+DocumentIdDFW::DocumentIdDFW()
+{
+}
+
+DocumentIdDFW::~DocumentIdDFW() = default;
+
+bool
+DocumentIdDFW::IsGenerated() const
+{
+ return false;
+}
+
+void
+DocumentIdDFW::insertField(uint32_t, GeneralResult *gres, GetDocsumsState *, ResType,
+ vespalib::slime::Inserter &target)
+{
+ const auto* document = gres->get_document();
+ if (document != nullptr) {
+ document->insert_document_id(target);
+ }
+}
+
+}
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/document_id_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/document_id_dfw.h
new file mode 100644
index 00000000000..f6353912384
--- /dev/null
+++ b/searchsummary/src/vespa/searchsummary/docsummary/document_id_dfw.h
@@ -0,0 +1,22 @@
+// 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 for writing document id field.
+ */
+class DocumentIdDFW : public DocsumFieldWriter
+{
+private:
+public:
+ DocumentIdDFW();
+ ~DocumentIdDFW() override;
+ bool IsGenerated() const override;
+ void insertField(uint32_t docid, GeneralResult *gres, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) override;
+};
+
+}
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 f81412eb34c..c177568c467 100644
--- a/searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h
+++ b/searchsummary/src/vespa/searchsummary/docsummary/i_docsum_store_document.h
@@ -22,6 +22,7 @@ public:
virtual ~IDocsumStoreDocument() = default;
virtual std::unique_ptr<document::FieldValue> 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 20083b9160e..5bcead79f97 100644
--- a/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp
+++ b/streamingvisitors/src/vespa/vsm/vsm/docsumfilter.cpp
@@ -135,6 +135,7 @@ public:
~DocsumStoreVsmDocument() override;
std::unique_ptr<document::FieldValue> 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;
};
DocsumStoreVsmDocument::DocsumStoreVsmDocument(const document::Document* document)
@@ -168,6 +169,16 @@ DocsumStoreVsmDocument::insert_summary_field(const vespalib::string& field_name,
}
}
+void
+DocsumStoreVsmDocument::insert_document_id(vespalib::slime::Inserter& inserter) const
+{
+ if (_document) {
+ auto id = _document->getId().toString();
+ vespalib::Memory id_view(id.data(), id.size());
+ inserter.insertString(id_view);
+ }
+}
+
}
FieldPath