1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "testdocrepo.h"
#include <vespa/document/datatype/documenttype.h>
#include <vespa/document/repo/documenttyperepo.h>
#include <vespa/document/repo/configbuilder.h>
#include <vespa/config/print/fileconfigreader.hpp>
using document::config_builder::Struct;
using document::config_builder::Wset;
using document::config_builder::Array;
using document::config_builder::Map;
namespace document {
TestDocRepo::TestDocRepo()
: _cfg(getDefaultConfig()),
_repo(new DocumentTypeRepo(_cfg)) {
}
TestDocRepo::~TestDocRepo() = default;
DocumenttypesConfig TestDocRepo::getDefaultConfig() {
const int type1_id = 238423572;
const int type2_id = 238424533;
const int type3_id = 1088783091;
const int mystruct_id = -2092985851;
const int structarray_id = 759956026;
config_builder::DocumenttypesConfigBuilderHelper builder;
::config::StringVector documentfields = { "headerval", "hstringval", "title" };
builder.document(type1_id, "testdoctype1",
Struct("testdoctype1.header")
.addField("headerval", DataType::T_INT)
.addField("headerlongval", DataType::T_LONG)
.addField("hfloatval", DataType::T_FLOAT)
.addField("hstringval", DataType::T_STRING)
.addField("mystruct", Struct("mystruct")
.setId(mystruct_id)
.addField("key", DataType::T_INT)
.addField("value", DataType::T_STRING))
.addField("tags", Array(DataType::T_STRING))
.addField("boolfield", DataType::T_BOOL)
.addField("stringweightedset", Wset(DataType::T_STRING))
.addField("stringweightedset2", DataType::T_TAG)
.addField("byteweightedset", Wset(DataType::T_BYTE))
.addField("mymap",
Map(DataType::T_INT, DataType::T_STRING))
.addField("structarrmap", Map(
DataType::T_STRING,
Array(mystruct_id).setId(structarray_id)))
.addField("title", DataType::T_STRING)
.addField("byteval", DataType::T_BYTE),
Struct("testdoctype1.body")
.addField("content", DataType::T_STRING)
.addField("rawarray", Array(DataType::T_RAW))
.addField("structarray", structarray_id)
.addTensorField("sparse_tensor", "tensor(x{})")
.addTensorField("sparse_xy_tensor", "tensor(x{},y{})")
.addTensorField("sparse_float_tensor", "tensor<float>(x{})")
.addTensorField("dense_tensor", "tensor(x[2])"))
.imported_field("my_imported_field")
.doc_type.fieldsets["[document]"].fields.swap(documentfields);
builder.document(type2_id, "testdoctype2",
Struct("testdoctype2.header")
.addField("onlyinchild", DataType::T_INT),
Struct("testdoctype2.body"))
.inherit(type1_id);
builder.document(type3_id, "_test_doctype3_",
Struct("_test_doctype3_.header")
.addField("_only_in_child_", DataType::T_INT),
Struct("_test_doctype3_.body"))
.inherit(type1_id);
return builder.config();
}
const DataType*
TestDocRepo::getDocumentType(const vespalib::string &t) const {
return _repo->getDocumentType(t);
}
DocumenttypesConfig readDocumenttypesConfig(const char *file_name) {
::config::FileConfigReader<DocumenttypesConfig> reader(file_name);
return DocumenttypesConfig(*reader.read());
}
DocumenttypesConfig readDocumenttypesConfig(const std::string &file_name ) {
return readDocumenttypesConfig(file_name.c_str());
}
} // namespace document
|