summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-02-21 14:07:35 +0100
committerJon Bratseth <bratseth@oath.com>2018-02-21 14:07:35 +0100
commitf5a796313c118d62614d170f31286556ef6bb367 (patch)
treef5165fd69ecfb3d7b85848c2316738ecbe67be16 /config-model/src/main/java/com
parent96d16478b29443c420ff64acc8e5ff90271c5951 (diff)
Add types of includes fields
Diffstat (limited to 'config-model/src/main/java/com')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java19
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java8
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/Search.java6
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/ImmutableImportedSDField.java3
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/ImmutableSDField.java7
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java6
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidator.java2
7 files changed, 32 insertions, 19 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 bd645422d50..7020402f2c8 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
@@ -6,6 +6,7 @@ import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.search.query.profile.types.FieldDescription;
import com.yahoo.search.query.profile.types.QueryProfileType;
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;
@@ -754,15 +755,13 @@ public class RankProfile implements Serializable, Cloneable {
.map(Macro::asExpressionFunction)
.collect(Collectors.toList()));
- // Add small constants
+ // Add small and large constants, respectively
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
- for (SDField field : getSearch().allConcreteFields()) {
- field.getAttributes().forEach((k, a) -> context.setType(FeatureNames.asAttributeFeature(k), a.tensorType().orElse(TensorType.empty)));
- }
+ getSearch().allFields().forEach(field -> addAttributeTypes(field, context));
+ getSearch().allImportedFields().forEach(field -> addAttributeTypes(field, context));
// Add query features from rank profile types reached from the "default" profile
for (QueryProfileType queryProfileType : queryProfiles.getTypeRegistry().allComponents()) {
@@ -786,6 +785,16 @@ public class RankProfile implements Serializable, Cloneable {
return context;
}
+ private void addAttributeTypes(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.
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java
index a075b9d00fa..7b4d70d85b1 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java
@@ -16,8 +16,7 @@ import java.util.Set;
* Having both of these mappings consolidated here make it easier to remove dependencies on these mappings at
* run time, since it is essentially only used when building rank profile config at deployment time.
*
- * TODO: Reconsider the difference between local and global maps. Right now, the local maps might better be
- * served from a different class owned by SearchBuilder.
+ * TODO: Rank profiles should be stored under its owning Search instance.
*
* @author Ulf Lilleengen
*/
@@ -31,9 +30,6 @@ public class RankProfileRegistry {
/* These rank profiles can be overridden: 'default' rank profile, as that is documented to work. And 'unranked'. */
static final Set<String> overridableRankProfileNames = new HashSet<>(Arrays.asList("default", "unranked"));
- public RankProfileRegistry() {
- }
-
public static RankProfileRegistry createRankProfileRegistryWithBuiltinRankProfiles(Search search) {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
rankProfileRegistry.addRankProfile(new DefaultRankProfile(search, rankProfileRegistry));
@@ -47,7 +43,7 @@ public class RankProfileRegistry {
* @param rankProfile the rank profile to add
*/
public void addRankProfile(RankProfile rankProfile) {
- if (!rankProfiles.containsKey(rankProfile.getSearch())) {
+ if ( ! rankProfiles.containsKey(rankProfile.getSearch())) {
rankProfiles.put(rankProfile.getSearch(), new LinkedHashMap<>());
}
checkForDuplicateRankProfile(rankProfile);
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/Search.java b/config-model/src/main/java/com/yahoo/searchdefinition/Search.java
index f4a0365e36e..1ab76afc9c0 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/Search.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/Search.java
@@ -199,9 +199,7 @@ public class Search implements Serializable, ImmutableSearch {
@Override
public ImmutableSDField getField(String name) {
ImmutableSDField field = getConcreteField(name);
- if (field != null) {
- return field;
- }
+ if (field != null) return field;
return allImportedFields()
.filter(f -> f.getName().equals(name))
.findFirst()
@@ -248,8 +246,6 @@ public class Search implements Serializable, ImmutableSearch {
* Returns a list of all the fields of this search definition, that is all fields in all documents, in the documents
* they inherit, and all extra fields. The caller receives ownership to the list - subsequent changes to it will not
* impact this
- *
- * @return the list of fields in this searchdefinition
*/
public List<SDField> allConcreteFields() {
List<SDField> allFields = new ArrayList<>();
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/ImmutableImportedSDField.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/ImmutableImportedSDField.java
index 8b6df1a87db..4502468379f 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/document/ImmutableImportedSDField.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/ImmutableImportedSDField.java
@@ -63,6 +63,9 @@ public class ImmutableImportedSDField implements ImmutableSDField {
}
@Override
+ public ImmutableSDField getBackingField() { return importedField.targetField(); }
+
+ @Override
public boolean isIndexStructureField() {
return importedField.targetField().isIndexStructureField();
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/ImmutableSDField.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/ImmutableSDField.java
index 152690a6f56..70553d4b57c 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/document/ImmutableSDField.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/ImmutableSDField.java
@@ -19,6 +19,7 @@ import java.util.Map;
* @author bjorncs
*/
public interface ImmutableSDField {
+
<T extends Expression> boolean containsExpression(Class<T> searchFor);
boolean doesAttributing();
@@ -33,6 +34,12 @@ public interface ImmutableSDField {
boolean isImportedField();
+ /**
+ * Returns the field backing this - the field itself if this is a regular field,
+ * and the target field if this is imported.
+ */
+ ImmutableSDField getBackingField();
+
default boolean isConcreteField() {
return !isImportedField();
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java
index 593edc33370..6e7582a98c8 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java
@@ -209,6 +209,9 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer,
}
@Override
+ public ImmutableSDField getBackingField() { return this; }
+
+ @Override
public boolean doesAttributing() {
return containsExpression(AttributeExpression.class);
}
@@ -623,8 +626,7 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer,
public RankType getRankType() { return this.rankType; }
/**
- * <p>Returns the search-time attribute settings of this field
- * or null if none is set.</p>
+ * Returns the search-time attribute settings of this field or null if none is set.
*
* <p>TODO: Make unmodifiable.</p>
*/
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidator.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidator.java
index fa2610d77a1..baacceea667 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidator.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidator.java
@@ -34,7 +34,7 @@ public class RankingExpressionTypeValidator extends Processor {
@Override
public void process() {
- for (RankProfile profile : rankProfileRegistry.allRankProfiles()) {
+ for (RankProfile profile : rankProfileRegistry.localRankProfiles(search)) {
try {
validate(profile);
}