diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-08-24 12:40:33 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-08-24 12:40:33 +0200 |
commit | 0d36001a8827c287e0605f3be9b3ef2d6e53778c (patch) | |
tree | b0e3c03871d88e675bfada80d07bdb389d1d084f | |
parent | b88fd2c2b9c3e220b6884da0392a3602fb3aa994 (diff) |
Separate out ranking constants
15 files changed, 151 insertions, 118 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/DefaultRankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/DefaultRankProfile.java index 82d35c89e85..cbbcee0dcfa 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/DefaultRankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/DefaultRankProfile.java @@ -31,31 +31,27 @@ public class DefaultRankProfile extends RankProfile { public void setInherited(String inheritedName) { } - /** - * Returns null, the default rank profile can not inherit anything - */ + /** Returns null, the default rank profile can not inherit anything */ public String getInheritedName() { return null; } - /** - * Returns the rank boost value of the given field - */ + /** Returns the rank boost value of the given field */ public RankSetting getRankSetting(String fieldOrIndex,RankSetting.Type type) { - RankSetting setting=super.getRankSetting(fieldOrIndex,type); - if (setting!=null) return setting; + RankSetting setting = super.getRankSetting(fieldOrIndex,type); + if (setting != null) return setting; - SDField field=getSearch().getConcreteField(fieldOrIndex); - if (field!=null) { - setting=toRankSetting(field,type); - if (setting!=null) + SDField field = getSearch().getConcreteField(fieldOrIndex); + if (field != null) { + setting = toRankSetting(field,type); + if (setting != null) return setting; } - Index index=getSearch().getIndex(fieldOrIndex); - if (index!=null) { - setting=toRankSetting(index,type); - if (setting!=null) + Index index = getSearch().getIndex(fieldOrIndex); + if (index != null) { + setting = toRankSetting(index,type); + if (setting != null) return setting; } @@ -92,37 +88,36 @@ public class DefaultRankProfile extends RankProfile { * explicitly in this profile or in fields */ public Set<RankSetting> rankSettings() { - Set<RankSetting> settings=new LinkedHashSet<>(20); + Set<RankSetting> settings = new LinkedHashSet<>(20); settings.addAll(this.rankSettings); for (SDField field : getSearch().allConcreteFields() ) { - addSetting(field,RankSetting.Type.WEIGHT,settings); - addSetting(field,RankSetting.Type.RANKTYPE,settings); - addSetting(field,RankSetting.Type.LITERALBOOST,settings); - addSetting(field,RankSetting.Type.PREFERBITVECTOR,settings); + addSetting(field, RankSetting.Type.WEIGHT, settings); + addSetting(field, RankSetting.Type.RANKTYPE, settings); + addSetting(field, RankSetting.Type.LITERALBOOST, settings); + addSetting(field, RankSetting.Type.PREFERBITVECTOR, settings); } // Foer settings that really pertains to indexes do the explicit indexes too for (Index index : getSearch().getExplicitIndices()) { - addSetting(index,RankSetting.Type.PREFERBITVECTOR,settings); + addSetting(index, RankSetting.Type.PREFERBITVECTOR, settings); } return settings; } - private void addSetting(SDField field,RankSetting.Type type,Set<RankSetting> settings) { + private void addSetting(SDField field, RankSetting.Type type, Set<RankSetting> settings) { if (type.isIndexLevel()) { - addIndexSettings(field,type,settings); + addIndexSettings(field, type, settings); } else { - RankSetting setting=toRankSetting(field,type); - if (setting==null) return; + RankSetting setting = toRankSetting(field, type); + if (setting == null) return; settings.add(setting); } } - private void addIndexSettings(SDField field,RankSetting.Type type,Set<RankSetting> settings) { + private void addIndexSettings(SDField field, RankSetting.Type type, Set<RankSetting> settings) { for (Iterator i = field.getFieldNameAsIterator(); i.hasNext(); ) { - String indexName=(String)i.next(); - Index explicitIndex=field.getIndex(indexName); + String indexName = (String)i.next(); // TODO: Make a ranking object in the index override the field level ranking object if (type.equals(RankSetting.Type.PREFERBITVECTOR) && field.getRanking().isFilter()) { @@ -131,9 +126,9 @@ public class DefaultRankProfile extends RankProfile { } } - private void addSetting(Index index,RankSetting.Type type,Set<RankSetting> settings) { - RankSetting setting=toRankSetting(index,type); - if (setting==null) return; + private void addSetting(Index index, RankSetting.Type type, Set<RankSetting> settings) { + RankSetting setting = toRankSetting(index, type); + if (setting == null) return; settings.add(setting); } 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 2e66784527d..9a0f7aae1e7 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -51,7 +51,10 @@ public class RankProfile implements Serializable, Cloneable { private final String name; /** The search definition owning this profile, or null if none */ - private Search search = null; + private final Search search; + + /** The application package owning this */ + private final ApplicationPackage applicationPackage; /** The name of the rank profile inherited by this */ private String inheritedName = null; @@ -110,58 +113,60 @@ public class RankProfile implements Serializable, Cloneable { private final TypeSettings queryFeatureTypes = new TypeSettings(); /** - * Creates a new rank profile + * Creates a new rank profile for a particular search definition * * @param name the name of the new profile * @param search the search definition owning this profile - * @param rankProfileRegistry The {@link com.yahoo.searchdefinition.RankProfileRegistry} to use for storing + * @param rankProfileRegistry the {@link com.yahoo.searchdefinition.RankProfileRegistry} to use for storing * and looking up rank profiles. */ public RankProfile(String name, Search search, RankProfileRegistry rankProfileRegistry) { this.name = name; this.search = search; + this.applicationPackage = search.applicationPackage(); this.rankProfileRegistry = rankProfileRegistry; } - public String getName() { return name; } - /** - * Returns the search definition owning this, or null if none + * Creates a global rank profile * - * @return The search definition. + * @param name the name of the new profile + * @param applicationPackage the application package owning this profile */ - public Search getSearch() { - return search; + public RankProfile(String name, ApplicationPackage applicationPackage, RankProfileRegistry rankProfileRegistry) { + this.name = name; + this.search = null; + this.applicationPackage = applicationPackage; + this.rankProfileRegistry = rankProfileRegistry; } + public String getName() { return name; } + + /** Returns the search definition owning this, or null if it is global */ + public Search getSearch() { return search; } + + /** Returns the application this is part of */ + public ApplicationPackage applicationPackage() { return applicationPackage; } + /** * Sets the name of the rank profile this inherits. Both rank profiles must be present in the same search * definition - * - * @param inheritedName The name of the profile that this inherits from. */ public void setInherited(String inheritedName) { this.inheritedName = inheritedName; } - /** - * Returns the name of the profile this one inherits, or null if none is inherited - * - * @return The inherited name. - */ + /** Returns the name of the profile this one inherits, or null if none is inherited */ public String getInheritedName() { return inheritedName; } - /** - * Returns the inherited rank profile, or null if there is none - * - * @return The inherited profile. - */ + /** Returns the inherited rank profile, or null if there is none */ public RankProfile getInherited() { - if (getSearch()==null) return getInheritedFromRegistry(inheritedName); + if (getSearch() == null) return getInheritedFromRegistry(inheritedName); + RankProfile inheritedInThisSearch = rankProfileRegistry.getRankProfile(search, inheritedName); - if (inheritedInThisSearch!=null) return inheritedInThisSearch; + if (inheritedInThisSearch != null) return inheritedInThisSearch; return getInheritedFromRegistry(inheritedName); } @@ -177,8 +182,8 @@ public class RankProfile implements Serializable, Cloneable { /** * Returns whether this profile inherits (directly or indirectly) the given profile * - * @param name The profile name to compare this to. - * @return Whether or not this inherits from the named profile. + * @param name the profile name to compare this to. + * @return whether or not this inherits from the named profile. */ public boolean inherits(String name) { RankProfile parent = getInherited(); @@ -190,10 +195,6 @@ public class RankProfile implements Serializable, Cloneable { return false; } - /** - * change match settings - * @param settings The new match settings - **/ public void setMatchPhaseSettings(MatchPhaseSettings settings) { settings.checkValid(); this.matchPhaseSettings = settings; @@ -219,7 +220,7 @@ public class RankProfile implements Serializable, Cloneable { * * @param field The field whose settings to return. * @param type The type that the field is required to be. - * @return The rank setting found, or null. + * @return the rank setting found, or null. */ public RankSetting getDeclaredRankSetting(String field, RankSetting.Type type) { for (Iterator<RankSetting> i = declaredRankSettingIterator(); i.hasNext();) { @@ -236,9 +237,9 @@ public class RankProfile implements Serializable, Cloneable { * Returns a rank setting of field or index, or null if there is no such rank setting in this profile or one it * inherits * - * @param field The field whose settings to return. - * @param type The type that the field is required to be. - * @return The rank setting found, or null. + * @param field the field whose settings to return + * @param type the type that the field is required to be + * @return the rank setting found, or null */ public RankSetting getRankSetting(String field, RankSetting.Type type) { RankSetting rankSetting = getDeclaredRankSetting(field, type); @@ -252,7 +253,7 @@ public class RankProfile implements Serializable, Cloneable { /** * Returns the rank settings in this rank profile * - * @return An iterator for the declared rank setting. + * @return an iterator for the declared rank setting */ public Iterator<RankSetting> declaredRankSettingIterator() { return Collections.unmodifiableSet(rankSettings).iterator(); @@ -261,14 +262,14 @@ public class RankProfile implements Serializable, Cloneable { /** * Returns all settings in this profile or any profile it inherits * - * @return An iterator for all rank settings of this. + * @return an iterator for all rank settings of this */ public Iterator<RankSetting> rankSettingIterator() { return rankSettings().iterator(); } /** - * Returns a snapshot of the rank settings of this and everything it inherits + * Returns a snapshot of the rank settings of this and everything it inherits. * Changes to the returned set will not be reflected in this rank profile. */ public Set<RankSetting> rankSettings() { @@ -346,6 +347,7 @@ public class RankProfile implements Serializable, Cloneable { /** * Called by parser to store the expression string, for delayed evaluation + * * @param exp ranking expression for second phase */ public void setSecondPhaseRankingString(String exp) { @@ -354,6 +356,7 @@ public class RankProfile implements Serializable, Cloneable { /** * Called by parser to store the expression string, for delayed evaluation + * * @param exp ranking expression for first phase */ public void setFirstPhaseRankingString(String exp) { @@ -571,6 +574,7 @@ public class RankProfile implements Serializable, Cloneable { /** * Returns all filter fields in this profile and any profile it inherits. + * * @return the set of all filter fields */ public Set<String> allFilterFields() { @@ -770,7 +774,7 @@ public class RankProfile implements Serializable, Cloneable { // Add small and large constants, respectively getConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.type())); - getSearch().getRankingConstants().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.getTensorType())); + getSearch().rankingConstants().asMap().forEach((k, v) -> context.setType(FeatureNames.asConstantFeature(k), v.getTensorType())); // Add attributes getSearch().allFields().forEach(field -> addAttributeFeatureTypes(field, context)); @@ -868,7 +872,7 @@ public class RankProfile implements Serializable, Cloneable { public Object getValue() { return value; } - /** @return The value as an int, or a negative value if it is not an integer */ + /** Returns the value as an int, or a negative value if it is not an integer */ public int getIntValue() { if (value instanceof Integer) { return ((Integer)value); @@ -934,8 +938,6 @@ public class RankProfile implements Serializable, Cloneable { /** * Represents a declared macro in the profile. It is, after parsing, transformed into ExpressionMacro - * - * @author vegardh */ public static class Macro implements Serializable, Cloneable { @@ -1021,6 +1023,7 @@ public class RankProfile implements Serializable, Cloneable { public int getMinGroups() { return minGroups; } public double getCutoffFactor() { return cutoffFactor; } public Diversity.CutoffStrategy getCutoffStrategy() { return cutoffStrategy; } + public void checkValid() { if (attribute == null || attribute.isEmpty()) { throw new IllegalArgumentException("'diversity' did not set non-empty diversity attribute name."); @@ -1035,6 +1038,7 @@ public class RankProfile implements Serializable, Cloneable { } public static class MatchPhaseSettings { + private String attribute = null; private boolean ascending = false; private int maxHits = 0; // try to get this many hits before degrading the match phase @@ -1047,6 +1051,7 @@ public class RankProfile implements Serializable, Cloneable { value.checkValid(); diversity = value; } + public void setAscending(boolean value) { ascending = value; } public void setAttribute(String value) { attribute = value; } public void setMaxHits(int value) { maxHits = value; } 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 9e1e42e0821..8b1d6381a22 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java @@ -56,7 +56,7 @@ public class RankProfileRegistry { if ( ! overridableRankProfileNames.contains(rankProfileName)) { throw new IllegalArgumentException("Cannot add rank profile '" + rankProfileName + "' in search definition '" - + rankProfile.getSearch().getName() + "', since it already exists"); + + rankProfile.getSearch().getName() + "', since it already exists"); } } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java new file mode 100644 index 00000000000..164cb7f808e --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankingConstants.java @@ -0,0 +1,36 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * Constant values for ranking/model execution tied to a search definition, or globally to an application + * package + * + * @author bratseth + */ +public class RankingConstants { + + private final Map<String, RankingConstant> constants = new HashMap<>(); + + public void add(RankingConstant constant) { + constant.validate(); + String name = constant.getName(); + if (constants.containsKey(name)) + throw new IllegalArgumentException("Ranking constant '" + name + "' defined twice"); + constants.put(name, constant); + } + + /** Returns the ranking constant with the given name, or null if not present */ + public RankingConstant get(String name) { + return constants.get(name); + } + + /** Returns a read-only map of the ranking constants in this indexed by name */ + public Map<String, RankingConstant> asMap() { + return Collections.unmodifiableMap(constants); + } + +} 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 1ab76afc9c0..f42d5de21e8 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/Search.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/Search.java @@ -82,16 +82,16 @@ public class Search implements Serializable, ImmutableSearch { private Map<String, Index> indices = new LinkedHashMap<>(); // The explicitly defined summaries of this search definition. - private Map<String, DocumentSummary> summaries = new LinkedHashMap<>(); // _Must_ preserve order + private Map<String, DocumentSummary> summaries = new LinkedHashMap<>(); - // Ranking constants defined inside this s.d. - private Map<String, RankingConstant> rankingConstants = new HashMap<>(); + // Ranking constants of this + private RankingConstants rankingConstants = new RankingConstants(); private Optional<TemporaryImportedFields> temporaryImportedFields = Optional.of(new TemporaryImportedFields()); private Optional<ImportedFields> importedFields = Optional.empty(); - private ApplicationPackage sourceApplication; + private ApplicationPackage applicationPackage; /** * Creates a search definition which just holds a set of documents which should not (here, directly) be searchable @@ -103,10 +103,10 @@ public class Search implements Serializable, ImmutableSearch { /** * Creates a proper search definition * @param name of the the searchdefinition - * @param sourceApplication the application containing this + * @param applicationPackage the application containing this */ - public Search(String name, ApplicationPackage sourceApplication) { - this.sourceApplication = sourceApplication; + public Search(String name, ApplicationPackage applicationPackage) { + this.applicationPackage = applicationPackage; this.name = name; } @@ -162,18 +162,7 @@ public class Search implements Serializable, ImmutableSearch { docType = document; } - public void addRankingConstant(RankingConstant constant) { - constant.validate(); - String name = constant.getName(); - if (rankingConstants.containsKey(name)) - throw new IllegalArgumentException("Ranking constant '" + name + "' defined twice"); - rankingConstants.put(name, constant); - } - - /** Returns a read-only map of the ranking constants in this indexed by name */ - public Map<String, RankingConstant> getRankingConstants() { - return Collections.unmodifiableMap(rankingConstants); - } + public RankingConstants rankingConstants() { return rankingConstants; } public Optional<TemporaryImportedFields> temporaryImportedFields() { return temporaryImportedFields; @@ -260,10 +249,10 @@ public class Search implements Serializable, ImmutableSearch { * Returns the content of a ranking expression file */ public Reader getRankingExpression(String fileName) { - return sourceApplication.getRankingExpression(fileName); + return applicationPackage.getRankingExpression(fileName); } - public ApplicationPackage sourceApplication() { return sourceApplication; } + public ApplicationPackage applicationPackage() { return applicationPackage; } /** * Returns a field defined in this search definition or one if its documents. Fields in this search definition takes diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConvertedModel.java b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConvertedModel.java index 0dcba922ee3..766cda8994a 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConvertedModel.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/expressiontransforms/ConvertedModel.java @@ -81,7 +81,7 @@ public class ConvertedModel { public ConvertedModel(Path modelPath, RankProfileTransformContext context) { this.modelPath = modelPath; this.modelName = toModelName(modelPath); - ModelStore store = new ModelStore(context.rankProfile().getSearch().sourceApplication(), modelPath); + ModelStore store = new ModelStore(context.rankProfile().applicationPackage(), modelPath); if ( store.hasSourceModel()) expressions = convertModel(store, context.rankProfile(), context.queryProfiles(), context.importedModels()); else @@ -181,8 +181,8 @@ public class ConvertedModel { profile.addConstant(constant.getFirst(), asValue(constant.getSecond())); for (RankingConstant constant : store.readLargeConstants()) { - if ( ! profile.getSearch().getRankingConstants().containsKey(constant.getName())) - profile.getSearch().addRankingConstant(constant); + if ( ! profile.getSearch().rankingConstants().asMap().containsKey(constant.getName())) + profile.getSearch().rankingConstants().add(constant); } for (Pair<String, RankingExpression> macro : store.readMacros()) { @@ -210,9 +210,9 @@ public class ConvertedModel { } else { Path constantPath = store.writeLargeConstant(constantName, constantValue); - if ( ! profile.getSearch().getRankingConstants().containsKey(constantName)) { - profile.getSearch().addRankingConstant(new RankingConstant(constantName, constantValue.type(), - constantPath.toString())); + if ( ! profile.getSearch().rankingConstants().asMap().containsKey(constantName)) { + profile.getSearch().rankingConstants().add(new RankingConstant(constantName, constantValue.type(), + constantPath.toString())); } } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java index 1ebcc73027d..1eb5d92e0a4 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.model; import com.google.common.collect.ImmutableList; +import com.yahoo.collections.Pair; import com.yahoo.config.ConfigBuilder; import com.yahoo.config.ConfigInstance; import com.yahoo.config.ConfigInstance.Builder; @@ -19,7 +20,6 @@ import com.yahoo.config.model.NullConfigModelRegistry; import com.yahoo.config.model.api.FileDistribution; import com.yahoo.config.model.api.HostInfo; import com.yahoo.config.model.api.Model; -import com.yahoo.config.model.api.ValidationParameters; import com.yahoo.config.model.deploy.DeployState; import com.yahoo.config.model.producer.AbstractConfigProducer; import com.yahoo.config.model.producer.AbstractConfigProducerRoot; @@ -196,7 +196,13 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri * Creates a rank profile not attached to any search definition, for each imported model in the application package */ private ImmutableList<RankProfile> createGlobalRankProfiles(ImportedModels importedModels) { - return ImmutableList.of(); + List<RankProfile> profiles = new ArrayList<>(); + for (ImportedModel model : importedModels.all()) { + for (Pair<String, RankingExpression> entry : model.outputExpressions(model.name())) { + //RankProfile profile = new RankProfile(entry.getFirst()); + } + } + return ImmutableList.copyOf(profiles); } private void setupRouting() { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidator.java index d022b2cf8ab..907418ea9f0 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidator.java @@ -48,7 +48,7 @@ public class RankingConstantsValidator extends Validator { ExceptionMessageCollector exceptionMessageCollector = new ExceptionMessageCollector("Invalid constant tensor file(s):"); for (SearchDefinition sd : deployState.getSearchDefinitions()) { - for (RankingConstant rc : sd.getSearch().getRankingConstants().values()) { + for (RankingConstant rc : sd.getSearch().rankingConstants().asMap().values()) { try { validateRankingConstant(rc, applicationPackage); } catch (InvalidConstantTensor | FileNotFoundException ex) { diff --git a/config-model/src/main/java/com/yahoo/vespa/model/search/AbstractSearchCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/search/AbstractSearchCluster.java index 9550cd82b22..83da5d96418 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/search/AbstractSearchCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/search/AbstractSearchCluster.java @@ -37,7 +37,7 @@ public abstract class AbstractSearchCluster extends AbstractConfigProducer public void prepareToDistributeFiles(List<SearchNode> backends) { for (SearchDefinitionSpec sds : localSDS) { - for (RankingConstant constant : sds.getSearchDefinition().getSearch().getRankingConstants().values()) { + for (RankingConstant constant : sds.getSearchDefinition().getSearch().rankingConstants().asMap().values()) { FileReference reference = (constant.getPathType() == RankingConstant.PathType.FILE) ? FileSender.sendFileToServices(constant.getFileName(), backends) : FileSender.sendUriToServices(constant.getUri(), backends); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/search/DocumentDatabase.java b/config-model/src/main/java/com/yahoo/vespa/model/search/DocumentDatabase.java index 1413d515103..a6bf51a2503 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/search/DocumentDatabase.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/search/DocumentDatabase.java @@ -75,7 +75,7 @@ public class DocumentDatabase extends AbstractConfigProducer implements @Override public void getConfig(RankingConstantsConfig.Builder builder) { - for (RankingConstant constant : derivedCfg.getSearch().getRankingConstants().values()) { + for (RankingConstant constant : derivedCfg.getSearch().rankingConstants().asMap().values()) { if ("".equals(constant.getFileReference())) { System.err.println("INVALID rank constant "+constant.getName()+" [missing file reference]"); // TODO: Throw or log warning continue; diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj index fc4cbd0a495..17fc46b9f36 100644 --- a/config-model/src/main/javacc/SDParser.jj +++ b/config-model/src/main/javacc/SDParser.jj @@ -1801,7 +1801,7 @@ void rankingConstant(Search search) : } lbrace() (rankingConstantItem(constant) (<NL>)*)+ <RBRACE> ) { - search.addRankingConstant(constant); + search.rankingConstants().add(constant); } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java index 9e1fdd258e2..fd69e282fcb 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java @@ -44,7 +44,7 @@ public class RankingConstantTest { searchBuilder.build(); Search search = searchBuilder.getSearch(); - Iterator<RankingConstant> constantIterator = search.getRankingConstants().values().iterator(); + Iterator<RankingConstant> constantIterator = search.rankingConstants().asMap().values().iterator(); RankingConstant constant = constantIterator.next(); assertEquals(TENSOR_NAME, constant.getName()); assertEquals(TENSOR_FILE, constant.getFileName()); @@ -101,7 +101,7 @@ public class RankingConstantTest { )); searchBuilder.build(); Search search = searchBuilder.getSearch(); - RankingConstant constant = search.getRankingConstants().values().iterator().next(); + RankingConstant constant = search.rankingConstants().asMap().values().iterator().next(); assertEquals("simplename", constant.getFileName()); } @@ -120,7 +120,7 @@ public class RankingConstantTest { )); searchBuilder.build(); Search search = searchBuilder.getSearch(); - RankingConstant constant = search.getRankingConstants().values().iterator().next(); + RankingConstant constant = search.rankingConstants().asMap().values().iterator().next(); assertEquals(RankingConstant.PathType.URI, constant.getPathType()); assertEquals("http://somewhere.far.away/in/another-galaxy", constant.getUri()); } @@ -140,7 +140,7 @@ public class RankingConstantTest { )); searchBuilder.build(); Search search = searchBuilder.getSearch(); - RankingConstant constant = search.getRankingConstants().values().iterator().next(); + RankingConstant constant = search.rankingConstants().asMap().values().iterator().next(); assertEquals(RankingConstant.PathType.URI, constant.getPathType()); assertEquals("https://somewhere.far.away:4443/in/another-galaxy", constant.getUri()); } @@ -160,7 +160,7 @@ public class RankingConstantTest { )); searchBuilder.build(); Search search = searchBuilder.getSearch(); - RankingConstant constant = search.getRankingConstants().values().iterator().next(); + RankingConstant constant = search.rankingConstants().asMap().values().iterator().next(); assertEquals(RankingConstant.PathType.URI, constant.getPathType()); assertEquals("http://somewhere.far.away:4080/in/another-galaxy", constant.getUri()); } @@ -180,7 +180,7 @@ public class RankingConstantTest { )); searchBuilder.build(); Search search = searchBuilder.getSearch(); - RankingConstant constant = search.getRankingConstants().values().iterator().next(); + RankingConstant constant = search.rankingConstants().asMap().values().iterator().next(); assertEquals(RankingConstant.PathType.URI, constant.getPathType()); assertEquals("http:somewhere.far.away/in/another-galaxy", constant.getUri()); } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java index 77d20657f64..7acf0aced0c 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java @@ -230,7 +230,7 @@ public class RankingExpressionWithOnnxTestCase { search.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile"); assertNull("Constant overridden by macro is not added", - search.search().getRankingConstants().get( name + "_Variable")); + search.search().rankingConstants().get( name + "_Variable")); assertLargeConstant( name + "_Variable_1", search, Optional.of(10L)); // At this point the expression is stored - copy application to another location which do not have a models dir @@ -244,7 +244,7 @@ public class RankingExpressionWithOnnxTestCase { searchFromStored.compileRankProfile("my_profile", applicationDir.append("models")); searchFromStored.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile"); assertNull("Constant overridden by macro is not added", - searchFromStored.search().getRankingConstants().get( name + "_Variable")); + searchFromStored.search().rankingConstants().get( name + "_Variable")); assertLargeConstant( name + "_Variable_1", searchFromStored, Optional.of(10L)); } finally { IOUtils.recursiveDeleteDir(storedApplicationDirectory.toFile()); @@ -258,7 +258,7 @@ public class RankingExpressionWithOnnxTestCase { private void assertLargeConstant(String name, RankProfileSearchFixture search, Optional<Long> expectedSize) { try { Path constantApplicationPackagePath = Path.fromString("models.generated/mnist_softmax.onnx/constants").append(name + ".tbf"); - RankingConstant rankingConstant = search.search().getRankingConstants().get(name); + RankingConstant rankingConstant = search.search().rankingConstants().get(name); assertEquals(name, rankingConstant.getName()); assertTrue(rankingConstant.getFileName().endsWith(constantApplicationPackagePath.toString())); diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java index cf37864b73a..e38af991ec1 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java @@ -286,7 +286,7 @@ public class RankingExpressionWithTensorFlowTestCase { search.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile_child"); assertNull("Constant overridden by macro is not added", - search.search().getRankingConstants().get("mnist_softmax_saved_layer_Variable_read")); + search.search().rankingConstants().get("mnist_softmax_saved_layer_Variable_read")); assertLargeConstant(name + "_layer_Variable_1_read", search, Optional.of(10L)); // At this point the expression is stored - copy application to another location which do not have a models dir @@ -302,7 +302,7 @@ public class RankingExpressionWithTensorFlowTestCase { searchFromStored.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile"); searchFromStored.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile_child"); assertNull("Constant overridden by macro is not added", - searchFromStored.search().getRankingConstants().get("mnist_softmax_saved_layer_Variable_read")); + searchFromStored.search().rankingConstants().get("mnist_softmax_saved_layer_Variable_read")); assertLargeConstant(name + "_layer_Variable_1_read", searchFromStored, Optional.of(10L)); } finally { @@ -404,7 +404,7 @@ public class RankingExpressionWithTensorFlowTestCase { private void assertLargeConstant(String name, RankProfileSearchFixture search, Optional<Long> expectedSize) { try { Path constantApplicationPackagePath = Path.fromString("models.generated/mnist_softmax/saved/constants").append(name + ".tbf"); - RankingConstant rankingConstant = search.search().getRankingConstants().get(name); + RankingConstant rankingConstant = search.search().rankingConstants().get(name); assertEquals(name, rankingConstant.getName()); assertTrue(rankingConstant.getFileName().endsWith(constantApplicationPackagePath.toString())); diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ImportedModel.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ImportedModel.java index 0ddc202a3e0..aa33a71ef74 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ImportedModel.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/integration/ml/ImportedModel.java @@ -103,6 +103,8 @@ public class ImportedModel { * if signatures are used, or the expression name if signatures are not used and there are multiple * expressions, and the third is the output name if signature names are used. */ + // TODO: Get rids of name argument, which is needed to get the right name in unit tests using a mock package + // with a non-standard application package layout public List<Pair<String, RankingExpression>> outputExpressions(String modelName) { List<Pair<String, RankingExpression>> names = new ArrayList<>(); for (Map.Entry<String, Signature> signatureEntry : signatures().entrySet()) { |