From ab393107b2ec5ddbbbba1a92616bfb375dd9d2c4 Mon Sep 17 00:00:00 2001 From: Geir Storli Date: Wed, 18 Oct 2017 14:15:43 +0000 Subject: Do not require that fields in a field set must be part of the document type. Imported fields (from parent/referenced document types) are not part of the document type, but can be part of field sets for search purposes. --- document/src/tests/documenttypetestcase.cpp | 30 ++++++++++++++-------- .../src/vespa/document/datatype/documenttype.cpp | 11 -------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/document/src/tests/documenttypetestcase.cpp b/document/src/tests/documenttypetestcase.cpp index dfca4a67e31..311a841e75e 100644 --- a/document/src/tests/documenttypetestcase.cpp +++ b/document/src/tests/documenttypetestcase.cpp @@ -21,7 +21,7 @@ struct DocumentTypeTest : public CppUnit::TestFixture { void testSetGet(); void testHeaderContent(); - void testFieldSet(); + void testFieldSetCanContainFieldsNotInDocType(); void testInheritance(); void testInheritanceConfig(); void testMultipleInheritance(); @@ -29,7 +29,7 @@ struct DocumentTypeTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( DocumentTypeTest); CPPUNIT_TEST(testSetGet); - CPPUNIT_TEST(testFieldSet); + CPPUNIT_TEST(testFieldSetCanContainFieldsNotInDocType); CPPUNIT_TEST(testInheritance); CPPUNIT_TEST(testInheritanceConfig); CPPUNIT_TEST(testMultipleInheritance); @@ -162,20 +162,28 @@ void DocumentTypeTest::testMultipleInheritance() doc.getValue(doc.getField("tmp"))->getAsString()); } -void DocumentTypeTest::testFieldSet() -{ +namespace { + +bool containsField(const DocumentType::FieldSet &fieldSet, const vespalib::string &field) { + return fieldSet.getFields().find(field) != fieldSet.getFields().end(); +} + +} + +void DocumentTypeTest::testFieldSetCanContainFieldsNotInDocType() { DocumentType docType("test1"); docType.addField(Field("stringattr", 3, *DataType::STRING, false)); docType.addField(Field("nalle", 0, *DataType::INT, false)); - DocumentType::FieldSet::Fields tmp; - tmp.insert("nalle"); - tmp.insert("nulle"); - try { + { + DocumentType::FieldSet::Fields tmp; + tmp.insert("nalle"); + tmp.insert("nulle"); docType.addFieldSet("a", tmp); - CPPUNIT_ASSERT(false); - } catch (const vespalib::IllegalArgumentException & e) { - CPPUNIT_ASSERT_EQUAL(vespalib::string("Fieldset 'a': No field with name 'nulle' in document type 'test1'."), e.getMessage()); } + auto fieldSet = docType.getFieldSet("a"); + CPPUNIT_ASSERT_EQUAL((size_t)2, fieldSet->getFields().size()); + CPPUNIT_ASSERT(containsField(*fieldSet, "nalle")); + CPPUNIT_ASSERT(containsField(*fieldSet, "nulle")); } void DocumentTypeTest::testInheritance() diff --git a/document/src/vespa/document/datatype/documenttype.cpp b/document/src/vespa/document/datatype/documenttype.cpp index 61bfba3b028..c7eaf42b50b 100644 --- a/document/src/vespa/document/datatype/documenttype.cpp +++ b/document/src/vespa/document/datatype/documenttype.cpp @@ -75,17 +75,6 @@ DocumentType::~DocumentType() DocumentType & DocumentType::addFieldSet(const vespalib::string & name, const FieldSet::Fields & fields) { - for (FieldSet::Fields::const_iterator it(fields.begin()), mt(fields.end()); it != mt; it++) { - if ( ! _fields->hasField(*it) ) { - FieldPath fieldPath; - try { - _fields->buildFieldPath(fieldPath, *it); - } catch (FieldNotFoundException & e) { - throw IllegalArgumentException("Fieldset '" + name + "': No field with name '" + *it + - "' in document type '" + getName() + "'.", VESPA_STRLOC); - } - } - } _fieldSets[name] = FieldSet(name, fields); return *this; } -- cgit v1.2.3