diff options
author | Geir Storli <geirst@yahoo-inc.com> | 2017-08-14 15:47:05 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahoo-inc.com> | 2017-08-16 10:55:11 +0200 |
commit | 5d7ff977824a80cd1cecff859e429e922e597c79 (patch) | |
tree | c5031d14701f995d6b148af33c9a2b152ff3dcf4 /searchcommon/src | |
parent | 64383fa4fdff3d52cb9c7a1838f7b9cdb14be960 (diff) |
Change SchemaBuilder to use attributes config to setup imported attribute fields in schema.
Diffstat (limited to 'searchcommon/src')
-rw-r--r-- | searchcommon/src/tests/schema/imported-fields-cfg/attributes.cfg (renamed from searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg) | 11 | ||||
-rw-r--r-- | searchcommon/src/tests/schema/schema_test.cpp | 7 | ||||
-rw-r--r-- | searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp | 34 | ||||
-rw-r--r-- | searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h | 2 |
4 files changed, 22 insertions, 32 deletions
diff --git a/searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg b/searchcommon/src/tests/schema/imported-fields-cfg/attributes.cfg index d41ccc4bd61..9a08f7e2324 100644 --- a/searchcommon/src/tests/schema/imported-fields-cfg/imported-fields.cfg +++ b/searchcommon/src/tests/schema/imported-fields-cfg/attributes.cfg @@ -1,11 +1,12 @@ -attribute[2] +attribute[3] attribute[0].name imported_a -attribute[0].referencefield ref_a -attribute[0].targetfield target_a +attribute[0].imported true attribute[0].datatype INT32 attribute[0].collectiontype SINGLE attribute[1].name imported_b -attribute[1].referencefield ref_b -attribute[1].targetfield target_b +attribute[1].imported true attribute[1].datatype STRING attribute[1].collectiontype ARRAY +attribute[2].name regular +attribute[2].datatype INT32 +attribute[2].collectiontype SINGLE diff --git a/searchcommon/src/tests/schema/schema_test.cpp b/searchcommon/src/tests/schema/schema_test.cpp index cb35fbf4cb2..8a70e4f12df 100644 --- a/searchcommon/src/tests/schema/schema_test.cpp +++ b/searchcommon/src/tests/schema/schema_test.cpp @@ -411,14 +411,19 @@ TEST("require that imported attribute fields are not saved to disk") } } -TEST("require that schema can be built from imported-fields config") +TEST("require that schema can be built with imported attribute fields") { Schema s; SchemaConfigurer configurer(s, "dir:" + TEST_PATH("imported-fields-cfg")); + const auto &imported = s.getImportedAttributeFields(); EXPECT_EQUAL(2u, imported.size()); TEST_DO(assertField(SIAF("imported_a", DataType::INT32, CollectionType::SINGLE), imported[0])); TEST_DO(assertField(SIAF("imported_b", DataType::STRING, CollectionType::ARRAY), imported[1])); + + const auto ®ular = s.getAttributeFields(); + EXPECT_EQUAL(1u, regular.size()); + TEST_DO(assertField(SIAF("regular", DataType::INT32, CollectionType::SINGLE), regular[0])); } } // namespace index diff --git a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp index d58c6ba3bc4..cae2299132f 100644 --- a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp +++ b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.cpp @@ -166,11 +166,16 @@ SchemaBuilder::build(const IndexschemaConfig &cfg, Schema &schema) void SchemaBuilder::build(const AttributesConfig &cfg, Schema &schema) { - for (size_t i = 0; i < cfg.attribute.size(); ++i) { - const AttributesConfig::Attribute & a = cfg.attribute[i]; - schema.addAttributeField(Schema::Field(a.name, - convertDataType(a.datatype), - convertCollectionType(a.collectiontype))); + for (const auto &attr : cfg.attribute) { + if (attr.imported) { + schema.addImportedAttributeField(Schema::ImportedAttributeField(attr.name, + convertDataType(attr.datatype), + convertCollectionType(attr.collectiontype))); + } else { + schema.addAttributeField(Schema::Field(attr.name, + convertDataType(attr.datatype), + convertCollectionType(attr.collectiontype))); + } } } @@ -206,16 +211,6 @@ SchemaBuilder::build(const SummaryConfig &cfg, Schema &schema) } void -SchemaBuilder::build(const ImportedFieldsConfig &cfg, Schema &schema) -{ - for (const auto &attr : cfg.attribute) { - schema.addImportedAttributeField(Schema::ImportedAttributeField(attr.name, - convertDataType(attr.datatype), - convertCollectionType(attr.collectiontype))); - } -} - -void SchemaConfigurer::configure(const IndexschemaConfig &cfg) { SchemaBuilder::build(cfg, _schema); @@ -233,12 +228,6 @@ SchemaConfigurer::configure(const SummaryConfig & cfg) SchemaBuilder::build(cfg, _schema); } -void -SchemaConfigurer::configure(const vespa::config::search::ImportedFieldsConfig &cfg) -{ - SchemaBuilder::build(cfg, _schema); -} - SchemaConfigurer::SchemaConfigurer(Schema &schema, const vespalib::string &configId) : _schema(schema) @@ -249,12 +238,9 @@ SchemaConfigurer::SchemaConfigurer(Schema &schema, attributesSubscriber(*this, &SchemaConfigurer::configure); search::SubscriptionProxyNg<SchemaConfigurer, SummaryConfig> summarySubscriber(*this, &SchemaConfigurer::configure); - search::SubscriptionProxyNg<SchemaConfigurer, ImportedFieldsConfig> - importedFieldsSubscriber(*this, &SchemaConfigurer::configure); indexSchemaSubscriber.subscribe(configId.c_str()); attributesSubscriber.subscribe(configId.c_str()); summarySubscriber.subscribe(configId.c_str()); - importedFieldsSubscriber.subscribe(configId.c_str()); } diff --git a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h index 634082077fe..e1999e45296 100644 --- a/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h +++ b/searchcommon/src/vespa/searchcommon/common/schemaconfigurer.h @@ -39,7 +39,6 @@ public: **/ static void build(const vespa::config::search::SummaryConfig &cfg, Schema &schema); - static void build(const vespa::config::search::ImportedFieldsConfig &cfg, Schema &schema); }; class SchemaConfigurer @@ -49,7 +48,6 @@ private: void configure(const vespa::config::search::IndexschemaConfig & cfg); void configure(const vespa::config::search::AttributesConfig & cfg); void configure(const vespa::config::search::SummaryConfig & cfg); - void configure(const vespa::config::search::ImportedFieldsConfig &cfg); public: /** |