diff options
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition')
9 files changed, 33 insertions, 31 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java index 13f9028cc0a..3abf4ec3596 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -116,13 +116,12 @@ public class RankProfile implements Cloneable { private Map<Reference, Input> inputs = new LinkedHashMap<>(); + private Map<Reference, Constant> constants = new HashMap<>(); + private Set<String> filterFields = new HashSet<>(); private final RankProfileRegistry rankProfileRegistry; - /** Constants in ranking expressions */ - private Map<String, Constant> constants = new HashMap<>(); - private final TypeSettings attributeTypes = new TypeSettings(); private List<ImmutableSDField> allFieldsList; @@ -416,15 +415,15 @@ public class RankProfile implements Cloneable { return finalSettings; } - public void addConstant(String name, Constant value) { + public void addConstant(Reference name, Constant value) { constants.put(name, value); } /** Returns an unmodifiable view of the constants available in this */ - public Map<String, Constant> getConstants() { + public Map<Reference, Constant> getConstants() { if (inherited().isEmpty()) return new HashMap<>(constants); - Map<String, Constant> allConstants = new HashMap<>(); + Map<Reference, Constant> allConstants = new HashMap<>(); for (var inheritedProfile : inherited()) { for (var constant : inheritedProfile.getConstants().entrySet()) { if (allConstants.containsKey(constant.getKey())) @@ -960,9 +959,9 @@ public class RankProfile implements Cloneable { allFunctionsCached = null; } - private void checkNameCollisions(Map<String, RankingExpressionFunction> functions, Map<String, Constant> constants) { - for (Map.Entry<String, RankingExpressionFunction> functionEntry : functions.entrySet()) { - if (constants.containsKey(functionEntry.getKey())) + private void checkNameCollisions(Map<String, RankingExpressionFunction> functions, Map<Reference, Constant> constants) { + for (var functionEntry : functions.entrySet()) { + if (constants.containsKey(FeatureNames.asConstantFeature(functionEntry.getKey()))) throw new IllegalArgumentException("Cannot have both a constant and function named '" + functionEntry.getKey() + "'"); } @@ -1007,7 +1006,7 @@ public class RankProfile implements Cloneable { QueryProfileRegistry queryProfiles, Map<Reference, TensorType> featureTypes, ImportedMlModels importedModels, - Map<String, Constant> constants, + Map<Reference, Constant> constants, Map<String, RankingExpressionFunction> inlineFunctions, ExpressionTransforms expressionTransforms) { if (function == null) return null; @@ -1048,7 +1047,7 @@ public class RankProfile implements Cloneable { MapEvaluationTypeContext context = new MapEvaluationTypeContext(getExpressionFunctions(), featureTypes); // Add small and large constants, respectively - getConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.type())); + getConstants().forEach((k, v) -> context.setType(k, v.type())); rankingConstants().asMap().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.getTensorType())); // Add query features from all rank profile types diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java index 377e19eedf2..7a2765de852 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstant.java @@ -12,6 +12,7 @@ import com.yahoo.tensor.TensorType; * @author bratseth */ public class RankingConstant extends DistributableResource { + private TensorType tensorType = null; public RankingConstant(String name) { @@ -43,10 +44,9 @@ public class RankingConstant extends DistributableResource { ": Dense tensor dimensions must have a size"); } + @Override public String toString() { - StringBuilder b = new StringBuilder(super.toString()) - .append("' of type '").append(tensorType).append("'"); - return b.toString(); + return super.toString() + "' of type '" + tensorType + "'"; } } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java index 5020e9a061c..339840f66ce 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java @@ -5,14 +5,14 @@ import com.yahoo.config.application.api.FileRegistry; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; /** - * Constant values for ranking/model execution tied to a search definition, or globally to an application - * package + * Constant values for ranking/model execution tied to a schema, or globally to an application package * * @author bratseth */ @@ -23,7 +23,7 @@ public class RankingConstants { /** The schema this belongs to, or empty if it is global */ private final Optional<Schema> owner; - private final Map<String, RankingConstant> constants = new ConcurrentHashMap<>(); + private final Map<String, RankingConstant> constants = new LinkedHashMap<>(); public RankingConstants(FileRegistry fileRegistry, Optional<Schema> owner) { this.fileRegistry = fileRegistry; @@ -36,7 +36,7 @@ public class RankingConstants { String name = constant.getName(); RankingConstant prev = constants.putIfAbsent(name, constant); if ( prev != null ) - throw new IllegalArgumentException("Ranking constant '" + name + "' defined twice"); + throw new IllegalArgumentException("Constant '" + name + "' defined twice"); } public void putIfAbsent(RankingConstant constant) { @@ -70,7 +70,7 @@ public class RankingConstants { if (owner.isEmpty() || owner.get().inherited().isEmpty()) return Collections.unmodifiableMap(constants); if (constants.isEmpty()) return owner.get().inherited().get().rankingConstants().asMap(); - var allConstants = new HashMap<>(owner.get().inherited().get().rankingConstants().asMap()); + var allConstants = new LinkedHashMap<>(owner.get().inherited().get().rankingConstants().asMap()); allConstants.putAll(constants); return Collections.unmodifiableMap(allConstants); } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RankProfileList.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RankProfileList.java index 4c9e65f16c8..c36bd96d309 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RankProfileList.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RankProfileList.java @@ -50,7 +50,7 @@ public class RankProfileList extends Derived implements RankProfilesConfig.Produ } /** - * Creates a rank profile + * Creates a rank profile list * * @param schema the schema this is a rank profile from * @param attributeFields the attribute fields to create a ranking for diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/RankProfileTransformContext.java b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/RankProfileTransformContext.java index 9a732a63519..b284f9df325 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/RankProfileTransformContext.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/RankProfileTransformContext.java @@ -33,7 +33,7 @@ public class RankProfileTransformContext extends TransformContext { QueryProfileRegistry queryProfiles, Map<Reference, TensorType> featureTypes, ImportedMlModels importedModels, - Map<String, RankProfile.Constant> constants, + Map<Reference, RankProfile.Constant> constants, Map<String, RankProfile.RankingExpressionFunction> inlineFunctions) { super(valuesOf(constants), rankProfile.typeContext(queryProfiles, featureTypes)); this.rankProfile = rankProfile; @@ -48,7 +48,7 @@ public class RankProfileTransformContext extends TransformContext { public Map<String, RankProfile.RankingExpressionFunction> inlineFunctions() { return inlineFunctions; } public Map<String, String> rankProperties() { return rankProperties; } - private static Map<String, Value> valuesOf(Map<String, RankProfile.Constant> constants) { + private static Map<String, Value> valuesOf(Map<Reference, RankProfile.Constant> constants) { return constants.values().stream() .filter(constant -> constant.value().isPresent()) .collect(Collectors.toMap(constant -> constant.name().simpleArgument().get(), diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedSchemas.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedSchemas.java index 9c2d29282ae..d3c24fa9924 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedSchemas.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedSchemas.java @@ -80,7 +80,7 @@ public class ConvertParsedSchemas { this.typeConverter = new ConvertParsedTypes(orderedInput, docMan); } - private Map<String, SDDocumentType> convertedDocuments = new LinkedHashMap(); + private final Map<String, SDDocumentType> convertedDocuments = new LinkedHashMap<>(); public List<Schema> convertToSchemas() { typeConverter.convert(false); diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertSchemaCollection.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertSchemaCollection.java index 8f25a586aa6..e46a6882bc7 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertSchemaCollection.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertSchemaCollection.java @@ -118,7 +118,7 @@ public class ConvertSchemaCollection { } private void resolveStructInheritance() { - List<ParsedStruct> all = new ArrayList(); + List<ParsedStruct> all = new ArrayList<>(); for (var schema : orderedInput) { var doc = schema.getDocument(); for (var struct : doc.getStructs()) { diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedRankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedRankProfile.java index 67f3672b2ac..bead0215b7d 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedRankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedRankProfile.java @@ -52,7 +52,7 @@ class ParsedRankProfile extends ParsedBlock { private final Map<String, ParsedRankFunction> functions = new LinkedHashMap<>(); private final Map<String, String> fieldsRankType = new LinkedHashMap<>(); private final Map<String, List<String>> rankProperties = new LinkedHashMap<>(); - private final Map<String, RankProfile.Constant> constants = new LinkedHashMap<>(); + private final Map<Reference, RankProfile.Constant> constants = new LinkedHashMap<>(); private final Map<Reference, RankProfile.Input> inputs = new LinkedHashMap<>(); ParsedRankProfile(String name) { @@ -83,7 +83,7 @@ class ParsedRankProfile extends ParsedBlock { Map<String, Integer> getFieldsWithRankWeight() { return Collections.unmodifiableMap(fieldsRankWeight); } Map<String, String> getFieldsWithRankType() { return Collections.unmodifiableMap(fieldsRankType); } Map<String, List<String>> getRankProperties() { return Collections.unmodifiableMap(rankProperties); } - Map<String, RankProfile.Constant> getConstants() { return Collections.unmodifiableMap(constants); } + Map<Reference, RankProfile.Constant> getConstants() { return Collections.unmodifiableMap(constants); } Map<Reference, RankProfile.Input> getInputs() { return Collections.unmodifiableMap(inputs); } Optional<String> getInheritedSummaryFeatures() { return Optional.ofNullable(this.inheritedSummaryFeatures); } @@ -101,7 +101,7 @@ class ParsedRankProfile extends ParsedBlock { this.inheritedSummaryFeatures = other; } - void addConstant(String name, RankProfile.Constant value) { + void addConstant(Reference name, RankProfile.Constant value) { verifyThat(! constants.containsKey(name), "already has constant", name); constants.put(name, value); } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java index 599dd6e2a7a..e4f312e98e3 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java @@ -14,9 +14,12 @@ import java.util.Optional; /** * This class holds the extracted information after parsing * one schema (.sd) file, using simple data structures - * as far as possible. Do not put advanced logic here! + * as far as possible. + * + * Do not put advanced logic here! + * * @author arnej27959 - **/ + */ public class ParsedSchema extends ParsedBlock { public static class ImportedField { @@ -39,8 +42,8 @@ public class ParsedSchema extends ParsedBlock { private final List<RankingConstant> rankingConstants = new ArrayList<>(); private final List<String> inherited = new ArrayList<>(); private final List<String> inheritedByDocument = new ArrayList<>(); - private final Map<String, ParsedSchema> resolvedInherits = new LinkedHashMap(); - private final Map<String, ParsedSchema> allResolvedInherits = new LinkedHashMap(); + private final Map<String, ParsedSchema> resolvedInherits = new LinkedHashMap<>(); + private final Map<String, ParsedSchema> allResolvedInherits = new LinkedHashMap<>(); private final Map<String, ParsedAnnotation> extraAnnotations = new LinkedHashMap<>(); private final Map<String, ParsedDocumentSummary> docSums = new LinkedHashMap<>(); private final Map<String, ParsedField> extraFields = new LinkedHashMap<>(); |