aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-09-21 16:41:42 +0200
committerTor Egge <Tor.Egge@online.no>2022-09-21 16:41:42 +0200
commitc918094f4b3c7c02d6e8cea51b3c5d2650fecb2a (patch)
treeb7b866395b96dec68e6ed4950ddaa0cc7b86d76a /searchlib/src/vespa
parent5e08068fa0c7def183cf94b659e7d6fdb5ec1297 (diff)
Stop using search::index::DocBuilder in searchcore attribute unit test.
Diffstat (limited to 'searchlib/src/vespa')
-rw-r--r--searchlib/src/vespa/searchlib/index/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/index/empty_doc_builder.cpp59
-rw-r--r--searchlib/src/vespa/searchlib/index/empty_doc_builder.h36
3 files changed, 96 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/index/CMakeLists.txt b/searchlib/src/vespa/searchlib/index/CMakeLists.txt
index 00a06363596..958614844d1 100644
--- a/searchlib/src/vespa/searchlib/index/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/index/CMakeLists.txt
@@ -6,6 +6,7 @@ vespa_add_library(searchlib_searchlib_index OBJECT
docidandfeatures.cpp
doctypebuilder.cpp
dummyfileheadercontext.cpp
+ empty_doc_builder.cpp
indexbuilder.cpp
postinglisthandle.cpp
postinglistcounts.cpp
diff --git a/searchlib/src/vespa/searchlib/index/empty_doc_builder.cpp b/searchlib/src/vespa/searchlib/index/empty_doc_builder.cpp
new file mode 100644
index 00000000000..45588791926
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/index/empty_doc_builder.cpp
@@ -0,0 +1,59 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "empty_doc_builder.h"
+#include <vespa/document/datatype/documenttype.h>
+#include <vespa/document/fieldvalue/document.h>
+#include <vespa/document/repo/documenttyperepo.h>
+#include <vespa/document/repo/configbuilder.h>
+#include <cassert>
+
+using document::DataType;
+using document::Document;
+using document::DocumentId;
+using document::DocumentTypeRepo;
+
+namespace search::index {
+
+namespace {
+
+DocumenttypesConfig
+get_document_types_config(EmptyDocBuilder::AddFieldsType add_fields)
+{
+ using namespace document::config_builder;
+ DocumenttypesConfigBuilderHelper builder;
+ Struct header("searchdocument.header");
+ add_fields(header);
+ builder.document(42, "searchdocument",
+ header,
+ Struct("searchdocument.body"));
+ return builder.config();
+}
+
+}
+
+EmptyDocBuilder::EmptyDocBuilder(AddFieldsType add_fields)
+ : _repo(std::make_shared<const DocumentTypeRepo>(get_document_types_config(add_fields))),
+ _document_type(_repo->getDocumentType("searchdocument"))
+{
+}
+
+EmptyDocBuilder::~EmptyDocBuilder() = default;
+
+
+std::unique_ptr<Document>
+EmptyDocBuilder::make_document(vespalib::string document_id)
+{
+ auto doc = std::make_unique<Document>(get_document_type(), DocumentId(document_id));
+ doc->setRepo(get_repo());
+ return doc;
+}
+
+const DataType&
+EmptyDocBuilder::get_data_type(const vespalib::string &name) const
+{
+ const DataType *type = _repo->getDataType(*_document_type, name);
+ assert(type);
+ return *type;
+}
+
+}
diff --git a/searchlib/src/vespa/searchlib/index/empty_doc_builder.h b/searchlib/src/vespa/searchlib/index/empty_doc_builder.h
new file mode 100644
index 00000000000..d4b54359f87
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/index/empty_doc_builder.h
@@ -0,0 +1,36 @@
+// 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 <functional>
+#include <memory>
+
+namespace document {
+class DataType;
+class Document;
+class DocumentType;
+class DocumentTypeRepo;
+}
+namespace document::config_builder { struct Struct; }
+
+namespace search::index {
+
+/*
+ * Class used to make empty search documents.
+ */
+class EmptyDocBuilder {
+ std::shared_ptr<const document::DocumentTypeRepo> _repo;
+ const document::DocumentType* _document_type;
+public:
+ using AddFieldsType = std::function<void(document::config_builder::Struct&)>;
+ explicit EmptyDocBuilder(AddFieldsType add_fields);
+ ~EmptyDocBuilder();
+ const document::DocumentTypeRepo& get_repo() const noexcept { return *_repo; }
+ std::shared_ptr<const document::DocumentTypeRepo> get_repo_sp() const noexcept { return _repo; }
+ const document::DocumentType& get_document_type() const noexcept { return *_document_type; }
+ std::unique_ptr<document::Document> make_document(vespalib::string document_id);
+ const document::DataType &get_data_type(const vespalib::string &name) const;
+};
+
+}