diff options
author | Lester Solbakken <lesters@users.noreply.github.com> | 2022-04-25 09:02:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-25 09:02:12 +0200 |
commit | d6dfe99249b8e07458bdc362aad50162ebe4f153 (patch) | |
tree | 624c3877f66d9c6f47133c2cdc2159201ba476ae /container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java | |
parent | c69d6e411a0a558be23810c87b38270570e12589 (diff) | |
parent | 41d2f4de02bbfcaaeb975229e91c57c1fe5f1f84 (diff) |
Merge pull request #22201 from vespa-engine/bratseth/inputs-2
Bratseth/inputs 2
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java index 8b6470996d5..02a4199d32e 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java @@ -12,6 +12,7 @@ import com.yahoo.search.query.profile.QueryProfile; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -48,7 +49,7 @@ public class QueryProfileType extends FreezableSimpleComponent { } public QueryProfileType(ComponentId id) { - this(id, new HashMap<>(), new ArrayList<>()); + this(id, new LinkedHashMap<>(), new ArrayList<>()); } private QueryProfileType(ComponentId id, Map<String, FieldDescription> fields, List<QueryProfileType> inherited) { @@ -61,7 +62,7 @@ public class QueryProfileType extends FreezableSimpleComponent { private QueryProfileType(ComponentId id, Map<String, FieldDescription> fields, List<QueryProfileType> inherited, boolean strict, boolean matchAsPath, boolean builtin, Map<String,String> aliases) { - this(id, new HashMap<>(fields), new ArrayList<>(inherited)); + this(id, new LinkedHashMap<>(fields), new ArrayList<>(inherited)); this.strict = strict; this.matchAsPath = matchAsPath; this.builtin = builtin; @@ -79,7 +80,7 @@ public class QueryProfileType extends FreezableSimpleComponent { } // Unfreeze nested query profile references - Map<String, FieldDescription> unfrozenFields = new HashMap<>(); + Map<String, FieldDescription> unfrozenFields = new LinkedHashMap<>(); for (Map.Entry<String, FieldDescription> field : fields.entrySet()) { FieldDescription unfrozenFieldValue = field.getValue(); if (field.getValue().getType() instanceof QueryProfileFieldType) { @@ -196,8 +197,8 @@ public class QueryProfileType extends FreezableSimpleComponent { * Default: true (so all non-declared fields returns true) */ public boolean isOverridable(String fieldName) { - FieldDescription field=getField(fieldName); - if (field==null) return true; + FieldDescription field = getField(fieldName); + if (field == null) return true; return field.isOverridable(); } @@ -208,8 +209,8 @@ public class QueryProfileType extends FreezableSimpleComponent { * null if no types are legal (i.e if the name is not legal) */ public Class<?> getValueClass(String name) { - FieldDescription fieldDescription=getField(name); - if (fieldDescription==null) { + FieldDescription fieldDescription = getField(name); + if (fieldDescription == null) { if (strict) return null; // Undefined -> Not legal else @@ -226,7 +227,7 @@ public class QueryProfileType extends FreezableSimpleComponent { return ((QueryProfileFieldType) fieldDescription.getType()).getQueryProfileType(); } - /** Returns the field type of the given name under this, of null if none */ + /** Returns the type of the given name under this, of null if none */ public FieldType getFieldType(CompoundName name) { FieldDescription field = getField(name.first()); if (field == null) return null; @@ -239,18 +240,31 @@ public class QueryProfileType extends FreezableSimpleComponent { return ((QueryProfileFieldType)fieldType).getQueryProfileType().getFieldType(name.rest()); } + /** Returns the description of the given name under this, of null if none */ + public FieldDescription getField(CompoundName globalName) { + FieldDescription field = getField(globalName.first()); + if (field == null) return null; + + if (globalName.size() == 1) return field; + + FieldType fieldType = field.getType(); + if ( ! (fieldType instanceof QueryProfileFieldType)) return null; + + return ((QueryProfileFieldType)fieldType).getQueryProfileType().getField(globalName.rest()); + } + /** * Returns the description of the field with the given name in this type or an inherited type * (depth first left to right search). Returns null if the field is not defined in this or an inherited profile. */ - public FieldDescription getField(String name) { - FieldDescription field = fields.get(name); + public FieldDescription getField(String localName) { + FieldDescription field = fields.get(localName); if ( field != null ) return field; if ( isFrozen() ) return null; // Inherited are collapsed into this for (QueryProfileType inheritedType : this.inherited() ) { - field = inheritedType.getField(name); + field = inheritedType.getField(localName); if (field != null) return field; } @@ -322,7 +336,7 @@ public class QueryProfileType extends FreezableSimpleComponent { // found in registry but not already added in *this* type (getField also checks parents): extend it if (type != null && ! fields.containsKey(name)) { type = new QueryProfileType(registry.createAnonymousId(type.getIdString()), - new HashMap<>(), + new LinkedHashMap<>(), List.of(type)); } @@ -355,7 +369,7 @@ public class QueryProfileType extends FreezableSimpleComponent { if (inherited().size() == 0) return Collections.unmodifiableMap(fields); // Collapse inherited - Map<String, FieldDescription> allFields = new HashMap<>(); + Map<String, FieldDescription> allFields = new LinkedHashMap<>(); for (QueryProfileType inheritedType : inherited) allFields.putAll(inheritedType.fields()); allFields.putAll(fields); |