diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-05-23 17:22:23 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-05-23 17:38:18 +0200 |
commit | 32777b8b9544e775689ba25c63280fa91a00dadd (patch) | |
tree | be7c0946a3b78a5be70660a8af1ff84ec0a2bb7e /config-model/src | |
parent | b69550e1edffb04beca59352303cf6b116d03079 (diff) |
Add currently unused config to interface
Diffstat (limited to 'config-model/src')
4 files changed, 24 insertions, 27 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 be246a143b2..74a9ef25615 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -52,6 +52,8 @@ import java.util.stream.Stream; */ public class RankProfile implements Cloneable { + public final static String FIRST_PHASE = "firstphase"; + public final static String SECOND_PHASE = "secondphase"; /** The search definition-unique name of this rank profile */ private final String name; @@ -312,7 +314,7 @@ public class RankProfile implements Cloneable { public void addConstant(String name, Value value) { if (value instanceof TensorValue) { - TensorType type = ((TensorValue)value).type(); + TensorType type = value.type(); if (type.dimensions().stream().anyMatch(d -> d.isIndexed() && d.size().isEmpty())) throw new IllegalArgumentException("Illegal type of constant " + name + " type " + type + ": Dense tensor dimensions must have a size"); @@ -385,13 +387,9 @@ public class RankProfile implements Cloneable { return null; } - public void setSecondPhaseRanking(RankingExpression rankingExpression) { - this.secondPhaseRanking = rankingExpression; - } - public void setSecondPhaseRanking(String expression) { try { - this.secondPhaseRanking = parseRankingExpression("secondphase", expression); + this.secondPhaseRanking = parseRankingExpression(SECOND_PHASE, expression); } catch (ParseException e) { throw new IllegalArgumentException("Illegal second phase ranking function", e); @@ -432,7 +430,6 @@ public class RankProfile implements Cloneable { * the final (with inheritance included) summary features of the given parent. * The profile must be the profile which is directly inherited by this. * - * @param parentProfile */ public void setInheritedSummaryFeatures(String parentProfile) { if ( ! parentProfile.equals(inheritedName)) @@ -492,12 +489,7 @@ public class RankProfile implements Cloneable { private void addRankProperty(RankProperty rankProperty) { // Just the usual multimap semantics here - List<RankProperty> properties = rankProperties.get(rankProperty.getName()); - if (properties == null) { - properties = new ArrayList<>(1); - rankProperties.put(rankProperty.getName(), properties); - } - properties.add(rankProperty); + rankProperties.computeIfAbsent(rankProperty.getName(), (String key) -> new ArrayList<>(1)).add(rankProperty); } @Override @@ -914,12 +906,12 @@ public class RankProfile implements Cloneable { */ public static class RankSetting implements Serializable { - private String fieldName; + private final String fieldName; - private Type type; + private final Type type; /** The rank value */ - private Object value; + private final Object value; public enum Type { @@ -928,10 +920,10 @@ public class RankProfile implements Cloneable { WEIGHT("weight"), PREFERBITVECTOR("preferbitvector",true); - private String name; + private final String name; /** True if this setting really pertains to an index, not a field within an index */ - private boolean isIndexLevel; + private final boolean isIndexLevel; Type(String name) { this(name,false); @@ -1004,8 +996,8 @@ public class RankProfile implements Cloneable { /** A rank property. Rank properties are Value Objects */ public static class RankProperty implements Serializable { - private String name; - private String value; + private final String name; + private final String value; public RankProperty(String name, String value) { this.name = name; @@ -1080,7 +1072,6 @@ public class RankProfile implements Cloneable { public void setMinGroups(int value) { minGroups = value; } public void setCutoffFactor(double value) { cutoffFactor = value; } public void setCutoffStrategy(Diversity.CutoffStrategy strategy) { cutoffStrategy = strategy; } - public void setCutoffStrategy(String strategy) { cutoffStrategy = Diversity.CutoffStrategy.valueOf(strategy); } public String getAttribute() { return attribute; } public int getMinGroups() { return minGroups; } public double getCutoffFactor() { return cutoffFactor; } 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 adefa5566ab..82381aa63fc 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java @@ -40,5 +40,4 @@ public class RankingConstants { public void sendTo(Collection<? extends AbstractService> services) { constants.values().forEach(constant -> constant.sendTo(services)); } - } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java index c656a426b61..4aa0a9daaca 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/RawRankProfile.java @@ -125,8 +125,8 @@ public class RawRankProfile implements RankProfilesConfig.Producer { */ private Map<String, FieldRankSettings> fieldRankSettings = new java.util.LinkedHashMap<>(); + private final RankProfile rankProfile; private RankingExpression firstPhaseRanking = null; - private RankingExpression secondPhaseRanking = null; private Set<ReferenceNode> summaryFeatures = new LinkedHashSet<>(); @@ -166,8 +166,9 @@ public class RawRankProfile implements RankProfilesConfig.Producer { * Creates a raw rank profile from the given rank profile */ Deriver(RankProfile rankProfile, QueryProfileRegistry queryProfiles, ImportedMlModels importedModels, - AttributeFields attributeFields, ModelContext.Properties deployProperties) + AttributeFields attributeFields, ModelContext.Properties deployProperties) { + this.rankProfile = rankProfile; RankProfile compiled = rankProfile.compile(queryProfiles, importedModels); attributeTypes = compiled.getAttributeTypes(); queryFeatureTypes = compiled.getQueryFeatureTypes(); @@ -333,7 +334,7 @@ public class RawRankProfile implements RankProfilesConfig.Producer { public List<Pair<String, String>> derive() { List<Pair<String, String>> properties = new ArrayList<>(); for (RankProfile.RankProperty property : rankProperties) { - if ("rankingExpression(firstphase).rankingScript".equals(property.getName())) { + if (("rankingExpression(" + RankProfile.FIRST_PHASE + ").rankingScript").equals(property.getName())) { // Could have been set by function expansion. Set expressions, then skip this property. try { firstPhaseRanking = new RankingExpression(property.getValue()); @@ -341,7 +342,7 @@ public class RawRankProfile implements RankProfilesConfig.Producer { throw new IllegalArgumentException("Could not parse first phase expression", e); } } - else if ("rankingExpression(secondphase).rankingScript".equals(property.getName())) { + else if (("rankingExpression(" + RankProfile.SECOND_PHASE + ").rankingScript").equals(property.getName())) { try { secondPhaseRanking = new RankingExpression(property.getValue()); } catch (ParseException e) { diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java index 8861432d97b..0695ae6a249 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java @@ -2,16 +2,22 @@ package com.yahoo.searchdefinition.processing; import com.yahoo.collections.Pair; +import com.yahoo.config.FileReference; import com.yahoo.config.model.application.provider.BaseDeployLogger; import com.yahoo.config.model.deploy.TestProperties; import com.yahoo.search.query.profile.QueryProfileRegistry; -import com.yahoo.searchdefinition.*; +import com.yahoo.searchdefinition.RankProfile; +import com.yahoo.searchdefinition.RankProfileRegistry; +import com.yahoo.searchdefinition.SchemaTestCase; +import com.yahoo.searchdefinition.Search; +import com.yahoo.searchdefinition.SearchBuilder; import com.yahoo.searchdefinition.derived.DerivedConfiguration; import com.yahoo.searchdefinition.derived.AttributeFields; import com.yahoo.searchdefinition.derived.RawRankProfile; import com.yahoo.searchdefinition.derived.TestableDeployLogger; import com.yahoo.searchdefinition.parser.ParseException; import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlModels; +import com.yahoo.vespa.config.search.core.RankingExpressionsConfig; import org.junit.Test; import java.io.IOException; |