aboutsummaryrefslogtreecommitdiffstats
path: root/searchcommon
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-05-03 07:55:42 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-05-03 07:55:42 +0000
commita91e44a0ab32d4b14d42bbca95331f339f109267 (patch)
tree81086e49174fd1117c6eec3948db61af116080c3 /searchcommon
parentc1bfad36330765d713188280c402de0c284ded9b (diff)
Specify default values when loading an IndexField from config lines.
Diffstat (limited to 'searchcommon')
-rw-r--r--searchcommon/src/tests/schema/schema-without-index-field-properties.txt7
-rw-r--r--searchcommon/src/tests/schema/schema_test.cpp16
-rw-r--r--searchcommon/src/vespa/searchcommon/common/schema.cpp4
3 files changed, 24 insertions, 3 deletions
diff --git a/searchcommon/src/tests/schema/schema-without-index-field-properties.txt b/searchcommon/src/tests/schema/schema-without-index-field-properties.txt
new file mode 100644
index 00000000000..4491b1242e0
--- /dev/null
+++ b/searchcommon/src/tests/schema/schema-without-index-field-properties.txt
@@ -0,0 +1,7 @@
+attributefield[0]
+summaryfield[0]
+fieldset[0]
+indexfield[1]
+indexfield[0].name foo
+indexfield[0].datatype STRING
+indexfield[0].collectiontype SINGLE
diff --git a/searchcommon/src/tests/schema/schema_test.cpp b/searchcommon/src/tests/schema/schema_test.cpp
index 780ea7a6640..e360ee1ba7a 100644
--- a/searchcommon/src/tests/schema/schema_test.cpp
+++ b/searchcommon/src/tests/schema/schema_test.cpp
@@ -16,6 +16,7 @@ namespace search::index {
using schema::DataType;
using schema::CollectionType;
using SIAF = Schema::ImportedAttributeField;
+using SIF = Schema::IndexField;
void
assertField(const Schema::Field& exp, const Schema::Field& act)
@@ -170,7 +171,6 @@ TEST(SchemaTest, test_basic)
TEST(SchemaTest, test_load_and_save)
{
- using SIF = Schema::IndexField;
using SAF = Schema::AttributeField;
using SSF = Schema::SummaryField;
using SDT = schema::DataType;
@@ -439,6 +439,20 @@ TEST(SchemaTest, require_that_schema_can_be_built_with_imported_attribute_fields
assertField(SIAF("regular", DataType::INT32, CollectionType::SINGLE), regular[0]);
}
+TEST(SchemaTest, require_that_index_field_is_loaded_with_default_values_when_properties_are_not_set)
+{
+ Schema s;
+ s.loadFromFile("schema-without-index-field-properties.txt");
+
+ const auto& index_fields = s.getIndexFields();
+ ASSERT_EQ(1, index_fields.size());
+ assertIndexField(SIF("foo", DataType::STRING, CollectionType::SINGLE).
+ setAvgElemLen(512).
+ set_experimental_posting_list_format(false),
+ index_fields[0]);
+ assertIndexField(SIF("foo", DataType::STRING, CollectionType::SINGLE), index_fields[0]);
+}
+
}
GTEST_MAIN_RUN_ALL_TESTS()
diff --git a/searchcommon/src/vespa/searchcommon/common/schema.cpp b/searchcommon/src/vespa/searchcommon/common/schema.cpp
index 5e89555acb6..b56bec85f7f 100644
--- a/searchcommon/src/vespa/searchcommon/common/schema.cpp
+++ b/searchcommon/src/vespa/searchcommon/common/schema.cpp
@@ -146,8 +146,8 @@ Schema::IndexField::IndexField(vespalib::stringref name, DataType dt,
Schema::IndexField::IndexField(const std::vector<vespalib::string> &lines)
: Field(lines),
- _avgElemLen(ConfigParser::parse<int32_t>("averageelementlen", lines)),
- _experimental_posting_list_format(ConfigParser::parse<bool>("experimentalpostinglistformat", lines))
+ _avgElemLen(ConfigParser::parse<int32_t>("averageelementlen", lines, 512)),
+ _experimental_posting_list_format(ConfigParser::parse<bool>("experimentalpostinglistformat", lines, false))
{
}