diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-02-21 13:10:38 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-02-21 13:10:38 +0100 |
commit | 96d16478b29443c420ff64acc8e5ff90271c5951 (patch) | |
tree | 15f2795f55a02055f4e01057cb41c4f194bca49a /config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java | |
parent | 108ab8eb0781fb59b8cbc13281816d5f7425b064 (diff) |
Revert "Merge pull request #5091 from vespa-engine/revert-5065-bratseth/typecheck-all-2"
This reverts commit f15c8a6384031adfe0764f20e6448be4eccd517b, reversing
changes made to 2a343e5a88a023a3f3246db2f47726e229d28fac.
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java')
-rw-r--r-- | config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java | 55 |
1 files changed, 31 insertions, 24 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 bcbc7cc99e2..bd645422d50 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -2,15 +2,9 @@ package com.yahoo.searchdefinition; import com.yahoo.config.application.api.ApplicationPackage; -import com.yahoo.config.model.deploy.DeployState; -import com.yahoo.io.reader.NamedReader; -import com.yahoo.processing.request.CompoundName; -import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileRegistry; -import com.yahoo.search.query.profile.config.QueryProfileXMLReader; import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.QueryProfileType; -import com.yahoo.search.query.profile.types.TensorFieldType; import com.yahoo.search.query.ranking.Diversity; import com.yahoo.searchdefinition.document.SDField; import com.yahoo.searchdefinition.expressiontransforms.RankProfileTransformContext; @@ -18,8 +12,8 @@ import com.yahoo.searchdefinition.parser.ParseException; import com.yahoo.searchlib.rankingexpression.ExpressionFunction; import com.yahoo.searchlib.rankingexpression.FeatureList; import com.yahoo.searchlib.rankingexpression.RankingExpression; +import com.yahoo.searchlib.rankingexpression.Reference; import com.yahoo.searchlib.rankingexpression.evaluation.TensorValue; -import com.yahoo.searchlib.rankingexpression.evaluation.TypeMapContext; import com.yahoo.searchlib.rankingexpression.evaluation.Value; import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode; import com.yahoo.tensor.TensorType; @@ -39,7 +33,9 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; /** * Represents a rank profile - a named set of ranking settings @@ -363,14 +359,14 @@ public class RankProfile implements Serializable, Cloneable { /** Returns a read-only view of the summary features to use in this profile. This is never null */ public Set<ReferenceNode> getSummaryFeatures() { - if (summaryFeatures!=null) return Collections.unmodifiableSet(summaryFeatures); - if (getInherited()!=null) return getInherited().getSummaryFeatures(); + if (summaryFeatures != null) return Collections.unmodifiableSet(summaryFeatures); + if (getInherited() != null) return getInherited().getSummaryFeatures(); return Collections.emptySet(); } public void addSummaryFeature(ReferenceNode feature) { - if (summaryFeatures==null) - summaryFeatures=new LinkedHashSet<>(); + if (summaryFeatures == null) + summaryFeatures = new LinkedHashSet<>(); summaryFeatures.add(feature); } @@ -585,8 +581,11 @@ public class RankProfile implements Serializable, Cloneable { } /** - * Will take the parser-set textual ranking expressions and turn into objects + * Will take the parser-set textual ranking expressions and turn into ranking expression objects, + * if not already done */ + // TODO: There doesn't appear to be any good reason to defer parsing of ranking expressions + // until this is called. Simplify by parsing them right away. public void parseExpressions() { try { parseRankingExpressions(); @@ -604,20 +603,23 @@ public class RankProfile implements Serializable, Cloneable { for (Map.Entry<String, Macro> e : getMacros().entrySet()) { String macroName = e.getKey(); Macro macro = e.getValue(); - RankingExpression expr = parseRankingExpression(macroName, macro.getTextualExpression()); - macro.setRankingExpression(expr); - macro.setTextualExpression(expr.getRoot().toString()); + if (macro.getRankingExpression() == null) { + RankingExpression expr = parseRankingExpression(macroName, macro.getTextualExpression()); + macro.setRankingExpression(expr); + macro.setTextualExpression(expr.getRoot().toString()); + } } } /** * Passes ranking expressions on to parser + * * @throws ParseException if either of the ranking expressions could not be parsed */ private void parseRankingExpressions() throws ParseException { - if (getFirstPhaseRankingString() != null) + if (getFirstPhaseRankingString() != null && firstPhaseRanking == null) setFirstPhaseRanking(parseRankingExpression("firstphase", getFirstPhaseRankingString())); - if (getSecondPhaseRankingString() != null) + if (getSecondPhaseRankingString() != null && secondPhaseRanking == null) setSecondPhaseRanking(parseRankingExpression("secondphase", getSecondPhaseRankingString())); } @@ -748,7 +750,9 @@ public class RankProfile implements Serializable, Cloneable { * referable from this rank profile. */ public TypeContext typeContext(QueryProfileRegistry queryProfiles) { - TypeMapContext context = new TypeMapContext(); + MapEvaluationTypeContext context = new MapEvaluationTypeContext(getMacros().values().stream() + .map(Macro::asExpressionFunction) + .collect(Collectors.toList())); // Add small constants getConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.type())); @@ -764,15 +768,18 @@ public class RankProfile implements Serializable, Cloneable { for (QueryProfileType queryProfileType : queryProfiles.getTypeRegistry().allComponents()) { for (FieldDescription field : queryProfileType.declaredFields().values()) { TensorType type = field.getType().asTensorType(); - String feature = FeatureNames.asQueryFeature(field.getName()); - TensorType existingType = context.getType(feature); + Optional<Reference> feature = Reference.simple(field.getName()); + if ( ! feature.isPresent() || ! feature.get().name().equals("query")) continue; + + TensorType existingType = context.getType(feature.get()); if (existingType != null) type = existingType.dimensionwiseGeneralizationWith(type).orElseThrow( () -> new IllegalArgumentException(queryProfileType + " contains query feature " + feature + " with type " + field.getType().asTensorType() + ", but this is already defined " + - "in another query profile with type " + context.getType(feature))); - context.setType(feature, type); + "in another query profile with type " + + context.getType(feature.get()))); + context.setType(feature.get(), type); } } @@ -910,7 +917,7 @@ public class RankProfile implements Serializable, Cloneable { */ public static class Macro implements Serializable, Cloneable { - private String name=null; + private final String name; private String textualExpression=null; private RankingExpression expression=null; private List<String> formalParams = new ArrayList<>(); @@ -955,7 +962,7 @@ public class RankProfile implements Serializable, Cloneable { return inline && formalParams.size() == 0; // only inline no-arg macros; } - public ExpressionFunction toExpressionMacro() { + public ExpressionFunction asExpressionFunction() { return new ExpressionFunction(getName(), getFormalParams(), getRankingExpression()); } |