aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
diff options
context:
space:
mode:
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.java80
1 files changed, 32 insertions, 48 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 064897de8dc..bcbc7cc99e2 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
@@ -2,18 +2,24 @@
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.ImmutableSDField;
+import com.yahoo.searchdefinition.document.SDField;
import com.yahoo.searchdefinition.expressiontransforms.RankProfileTransformContext;
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;
@@ -33,10 +39,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
import java.util.Set;
-import java.util.stream.Collectors;
/**
* Represents a rank profile - a named set of ranking settings
@@ -360,14 +363,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);
}
@@ -582,11 +585,8 @@ public class RankProfile implements Serializable, Cloneable {
}
/**
- * Will take the parser-set textual ranking expressions and turn into ranking expression objects,
- * if not already done
+ * Will take the parser-set textual ranking expressions and turn into objects
*/
- // 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,23 +604,20 @@ public class RankProfile implements Serializable, Cloneable {
for (Map.Entry<String, Macro> e : getMacros().entrySet()) {
String macroName = e.getKey();
Macro macro = e.getValue();
- if (macro.getRankingExpression() == null) {
- RankingExpression expr = parseRankingExpression(macroName, macro.getTextualExpression());
- macro.setRankingExpression(expr);
- macro.setTextualExpression(expr.getRoot().toString());
- }
+ 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 && firstPhaseRanking == null)
+ if (getFirstPhaseRankingString() != null)
setFirstPhaseRanking(parseRankingExpression("firstphase", getFirstPhaseRankingString()));
- if (getSecondPhaseRankingString() != null && secondPhaseRanking == null)
+ if (getSecondPhaseRankingString() != null)
setSecondPhaseRanking(parseRankingExpression("secondphase", getSecondPhaseRankingString()));
}
@@ -751,50 +748,37 @@ public class RankProfile implements Serializable, Cloneable {
* referable from this rank profile.
*/
public TypeContext typeContext(QueryProfileRegistry queryProfiles) {
- MapEvaluationTypeContext context = new MapEvaluationTypeContext(getMacros().values().stream()
- .map(Macro::asExpressionFunction)
- .collect(Collectors.toList()));
+ TypeMapContext context = new TypeMapContext();
- // Add small and large constants, respectively
+ // Add small constants
getConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.type()));
+ // Add large constants
getSearch().getRankingConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.getTensorType()));
// Add attributes
- getSearch().allFields().forEach(field -> addAttributeFeatureTypes(field, context));
- getSearch().allImportedFields().forEach(field -> addAttributeFeatureTypes(field, context));
+ for (SDField field : getSearch().allConcreteFields()) {
+ field.getAttributes().forEach((k, a) -> context.setType(FeatureNames.asAttributeFeature(k), a.tensorType().orElse(TensorType.empty)));
+ }
// Add query features from rank profile types reached from the "default" profile
for (QueryProfileType queryProfileType : queryProfiles.getTypeRegistry().allComponents()) {
for (FieldDescription field : queryProfileType.declaredFields().values()) {
TensorType type = field.getType().asTensorType();
- Optional<Reference> feature = Reference.simple(field.getName());
- if ( ! feature.isPresent() || ! feature.get().name().equals("query")) continue;
-
- TensorType existingType = context.getType(feature.get());
- if ( ! Objects.equals(existingType, context.defaultTypeOf(feature.get())))
+ String feature = FeatureNames.asQueryFeature(field.getName());
+ TensorType existingType = context.getType(feature);
+ if (existingType != null)
type = existingType.dimensionwiseGeneralizationWith(type).orElseThrow( () ->
- new IllegalArgumentException(queryProfileType + " contains query feature " + feature.get() +
+ 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.get())));
- context.setType(feature.get(), type);
+ "in another query profile with type " + context.getType(feature)));
+ context.setType(feature, type);
}
}
return context;
}
- private void addAttributeFeatureTypes(ImmutableSDField field, MapEvaluationTypeContext context) {
- field.getAttributes().forEach((k, a) -> {
- String name = k;
- if (k.equals(field.getBackingField().getName())) // this attribute should take the fields name
- name = field.getName(); // switch to that - it is separate for imported fields
- context.setType(FeatureNames.asAttributeFeature(name),
- a.tensorType().orElse(TensorType.empty));
- });
- }
-
/**
* A rank setting. The identity of a rank setting is its field name and type (not value).
* A rank setting is immutable.
@@ -926,7 +910,7 @@ public class RankProfile implements Serializable, Cloneable {
*/
public static class Macro implements Serializable, Cloneable {
- private final String name;
+ private String name=null;
private String textualExpression=null;
private RankingExpression expression=null;
private List<String> formalParams = new ArrayList<>();
@@ -971,7 +955,7 @@ public class RankProfile implements Serializable, Cloneable {
return inline && formalParams.size() == 0; // only inline no-arg macros;
}
- public ExpressionFunction asExpressionFunction() {
+ public ExpressionFunction toExpressionMacro() {
return new ExpressionFunction(getName(), getFormalParams(), getRankingExpression());
}