diff options
Diffstat (limited to 'config-model')
4 files changed, 20 insertions, 22 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java index ff0a0d07102..e11f7d370c5 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaryFields.java @@ -23,7 +23,7 @@ public class ImplicitSummaryFields extends Processor { @Override public void process(boolean validate, boolean documentsOnly) { for (DocumentSummary docsum : schema.getSummariesInThis().values()) { - if (docsum.getInherited() != null) continue; // Implicit fields are added to inheriting summaries through their parent + if (docsum.inherited().isPresent()) continue; // Implicit fields are added to inheriting summaries through their parent addField(docsum, new SummaryField("rankfeatures", DataType.STRING, SummaryTransform.RANKFEATURES), validate); addField(docsum, new SummaryField("summaryfeatures", DataType.STRING, SummaryTransform.SUMMARYFEATURES), validate); } diff --git a/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java b/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java index 967e662dc6b..90ab6ad8fa1 100644 --- a/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java +++ b/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Optional; import java.util.logging.Level; /** @@ -19,7 +20,7 @@ public class DocumentSummary extends FieldView { private boolean fromDisk = false; private boolean omitSummaryFeatures = false; - private String inherited; + private Optional<String> inherited = Optional.empty(); private final Schema owner; @@ -57,20 +58,16 @@ public class DocumentSummary extends FieldView { public SummaryField getSummaryField(String name) { var field = (SummaryField)get(name); if (field != null) return field; - if (getInherited() == null) return null; - return getInherited().getSummaryField(name); + if (inherited().isEmpty()) return null; + return inherited().get().getSummaryField(name); } // TODO: This does not handle overriding in child summaries correctly public Collection<SummaryField> getSummaryFields() { var fields = new ArrayList<SummaryField>(getFields().size()); - var parent = getInherited(); - if (parent != null) { - fields.addAll(parent.getSummaryFields()); - } - for (var field : getFields()) { + inherited().ifPresent(inherited -> fields.addAll(inherited.getSummaryFields())); + for (var field : getFields()) fields.add((SummaryField) field); - } return fields; } @@ -101,12 +98,12 @@ public class DocumentSummary extends FieldView { /** Sets the parent of this. Both summaries must be present in the same search definition */ public void setInherited(String inherited) { - this.inherited = inherited; + this.inherited = Optional.of(inherited); } - /** Returns the parent of this, or null if none is inherited */ - public DocumentSummary getInherited() { - return owner.getSummary(inherited); + /** Returns the parent of this, if any */ + public Optional<DocumentSummary> inherited() { + return inherited.map(name -> owner.getSummary(name)); } @Override @@ -115,14 +112,14 @@ public class DocumentSummary extends FieldView { } public void validate(DeployLogger logger) { - if (inherited != null) { - if ( ! owner.getSummaries().containsKey(inherited)) { + if (inherited.isPresent()) { + if ( ! owner.getSummaries().containsKey(inherited.get())) { logger.log(Level.WARNING, - this + " inherits " + inherited + " but this" + " is not present in " + owner); + this + " inherits " + inherited.get() + " but this" + " is not present in " + owner); logger.logApplicationPackage(Level.WARNING, - this + " inherits " + inherited + " but this" + " is not present in " + owner); + this + " inherits " + inherited.get() + " but this" + " is not present in " + owner); // TODO: When safe, replace the above by - // throw new IllegalArgumentException(this + " inherits " + inherited + " but this" + + // throw new IllegalArgumentException(this + " inherits " + inherited.get() + " but this" + // " is not present in " + owner); // ... and update SummaryTestCase.testValidationOfInheritedSummary } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java index 329d27472c2..8b96779f695 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java @@ -166,7 +166,7 @@ public class SchemaTestCase { assertTrue(child.onnxModels().asMap().containsKey("child_model")); assertNotNull(child.getSummary("parent_summary")); assertNotNull(child.getSummary("child_summary")); - assertEquals("parent_summary", child.getSummary("child_summary").getInherited().getName()); + assertEquals("parent_summary", child.getSummary("child_summary").inherited().get().getName()); assertTrue(child.getSummaries().containsKey("parent_summary")); assertTrue(child.getSummaries().containsKey("child_summary")); assertNotNull(child.getSummaryField("pf1")); diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java index e57dcf38fed..cf17e9f2f2b 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java @@ -10,6 +10,7 @@ import static com.yahoo.config.model.test.TestUtil.joinLines; import java.util.Collection; import java.util.List; +import java.util.Optional; import java.util.logging.Level; import java.util.stream.Collectors; @@ -176,8 +177,8 @@ public class SummaryTestCase { .map(FieldBase::getName) .collect(Collectors.toList()); assertEquals(testValue.summary.getName() + (testValue.parent == null ? " does not inherit anything" : " inherits " + testValue.parent.getName()), - testValue.parent, - testValue.summary.getInherited()); + Optional.ofNullable(testValue.parent), + testValue.summary.inherited()); assertEquals("Summary " + testValue.summary.getName() + " has expected fields", testValue.fields, actualFields); }); } |