From 402027bcbddb7bbae84a643acdc7fcef9dfe6c11 Mon Sep 17 00:00:00 2001 From: Arne H Juul Date: Thu, 7 Apr 2022 12:41:38 +0000 Subject: handle different SDDocumentType instances with same name --- .../searchdefinition/SDDocumentTypeOrderer.java | 23 ++++++++++++---------- .../yahoo/searchdefinition/document/SDField.java | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'config-model/src/main/java') diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java b/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java index 5b1a9595b94..ce32f323f22 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java @@ -18,7 +18,7 @@ import java.util.logging.Level; public class SDDocumentTypeOrderer { private final Map createdSDTypes = new LinkedHashMap<>(); - private final Set seenTypes = new LinkedHashSet<>(); + private final Set seenTypes = Collections.newSetFromMap(new IdentityHashMap<>()); List processingOrder = new LinkedList<>(); private final DeployLogger deployLogger; @@ -27,7 +27,6 @@ public class SDDocumentTypeOrderer { for (SDDocumentType type : sdTypes) { createdSDTypes.put(type.getDocumentName(), type); } - seenTypes.add("document"); } List getOrdered() { return processingOrder; } @@ -40,16 +39,17 @@ public class SDDocumentTypeOrderer { private void process(SDDocumentType docOrStruct, SDDocumentType owningDocument) { resolveAndProcessInheritedTemporaryTypes(docOrStruct, owningDocument); - if (seenTypes.contains(docOrStruct.getName())) { + if (seenTypes.contains(docOrStruct)) { return; } - seenTypes.add(docOrStruct.getName()); + seenTypes.add(docOrStruct); for (Field field : docOrStruct.fieldSet()) { - String typeName = field.getDataType().getName(); - if (!seenTypes.contains(typeName)) { - seenTypes.add(typeName); + var type = field.getDataType(); + String typeName = type.getName(); + if (!seenTypes.contains(type)) { + seenTypes.add(type); //we haven't seen this before, do it - visit(field.getDataType(), owningDocument); + visit(type, owningDocument); } } processingOrder.add(docOrStruct); @@ -89,7 +89,7 @@ public class SDDocumentTypeOrderer { for(SDDocumentType sdoc : createdSDTypes.values()) { for (SDDocumentType stype : sdoc.getTypes()) { if (stype.getName().equals(name)) { - return stype; + return stype; } } } @@ -99,7 +99,10 @@ public class SDDocumentTypeOrderer { private void visit(DataType type, SDDocumentType owningDocument) { if (type instanceof StructuredDataType) { StructuredDataType structType = (StructuredDataType) type; - SDDocumentType sdDocType = find(structType.getName()); + SDDocumentType sdDocType = owningDocument.getType(structType.getName()); + if (sdDocType == null) { + sdDocType = find(structType.getName()); + } if (sdDocType == null) { throw new IllegalArgumentException("Could not find struct '" + type.getName() + "'"); } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java index 256c628a1cb..382c0d0ceb5 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java @@ -493,7 +493,7 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, @Override public boolean hasIndex() { - return (getIndexingScript() != null) && doesIndexing(); + return (getIndexingScript() != null) && doesIndexing(); } /** Sets the literal boost of this field */ @@ -712,7 +712,7 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, * @param create true to create the summary field and add it to this field before returning if it is missing * @return the summary field, or null if not present and create is false */ - public SummaryField getSummaryField(String name,boolean create) { + public SummaryField getSummaryField(String name, boolean create) { SummaryField summaryField=summaryFields.get(name); if (summaryField==null && create) { summaryField=new SummaryField(name, getDataType()); -- cgit v1.2.3