diff options
Diffstat (limited to 'config-model/src/main')
5 files changed, 96 insertions, 42 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/ImmutableSearch.java b/config-model/src/main/java/com/yahoo/searchdefinition/ImmutableSearch.java index 795ec9badbb..813be5ef0da 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/ImmutableSearch.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/ImmutableSearch.java @@ -1,9 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchdefinition; +import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.searchdefinition.document.ImmutableSDField; +import com.yahoo.searchdefinition.document.SDField; import com.yahoo.vespa.documentmodel.SummaryField; +import java.io.Reader; +import java.util.List; import java.util.Map; import java.util.stream.Stream; @@ -15,11 +19,22 @@ import java.util.stream.Stream; */ public interface ImmutableSearch { + String getName(); + Index getIndex(String name); + SDField getConcreteField(String name); + List<SDField> allConcreteFields(); + List<Index> getExplicitIndices(); + Reader getRankingExpression(String fileName); + ApplicationPackage applicationPackage(); + RankingConstants rankingConstants(); Stream<ImmutableSDField> allImportedFields(); ImmutableSDField getField(String name); - Stream<ImmutableSDField> allFields(); + default Stream<ImmutableSDField> allFields() { + return allFieldsList().stream(); + } + List<ImmutableSDField> allFieldsList(); Map<String, SummaryField> getSummaryFields(ImmutableSDField field); } 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 5c43428a5d7..34277b88252 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -49,13 +49,13 @@ import java.util.stream.Stream; * * @author bratseth */ -public class RankProfile implements Serializable, Cloneable { +public class RankProfile implements Cloneable { /** The search definition-unique name of this rank profile */ private final String name; /** The search definition owning this profile, or null if global (owned by a model) */ - private final Search search; + private final ImmutableSearch search; /** The model owning this profile if it is global, or null if it is owned by a search definition */ private final VespaModel model; @@ -64,7 +64,7 @@ public class RankProfile implements Serializable, Cloneable { private String inheritedName = null; /** The match settings of this profile */ - protected MatchPhaseSettings matchPhaseSettings = null; + private MatchPhaseSettings matchPhaseSettings = null; /** The rank settings of this profile */ protected Set<RankSetting> rankSettings = new java.util.LinkedHashSet<>(); @@ -112,6 +112,8 @@ public class RankProfile implements Serializable, Cloneable { private final TypeSettings queryFeatureTypes = new TypeSettings(); + private List<ImmutableSDField> allFieldsList; + /** * Creates a new rank profile for a particular search definition * @@ -143,7 +145,7 @@ public class RankProfile implements Serializable, Cloneable { public String getName() { return name; } /** Returns the search definition owning this, or null if it is global */ - public Search getSearch() { return search; } + public ImmutableSearch getSearch() { return search; } /** Returns the application this is part of */ public ApplicationPackage applicationPackage() { @@ -156,7 +158,11 @@ public class RankProfile implements Serializable, Cloneable { } private Stream<ImmutableSDField> allFields() { - return search != null ? search.allFields() : Stream.empty(); + if (search == null) return Stream.empty(); + if (allFieldsList == null) { + allFieldsList = search.allFieldsList(); + } + return allFieldsList.stream(); } private Stream<ImmutableSDField> allImportedFields() { @@ -237,7 +243,7 @@ public class RankProfile implements Serializable, Cloneable { * @param type the type that the field is required to be. * @return the rank setting found, or null. */ - public RankSetting getDeclaredRankSetting(String field, RankSetting.Type type) { + RankSetting getDeclaredRankSetting(String field, RankSetting.Type type) { for (Iterator<RankSetting> i = declaredRankSettingIterator(); i.hasNext();) { RankSetting setting = i.next(); if (setting.getFieldName().equals(field) && @@ -342,7 +348,7 @@ public class RankProfile implements Serializable, Cloneable { return null; } - public void setFirstPhaseRanking(RankingExpression rankingExpression) { + void setFirstPhaseRanking(RankingExpression rankingExpression) { this.firstPhaseRanking = rankingExpression; } @@ -385,7 +391,7 @@ public class RankProfile implements Serializable, Cloneable { return Collections.emptySet(); } - public void addSummaryFeature(ReferenceNode feature) { + private void addSummaryFeature(ReferenceNode feature) { if (summaryFeatures == null) summaryFeatures = new LinkedHashSet<>(); summaryFeatures.add(feature); @@ -409,7 +415,7 @@ public class RankProfile implements Serializable, Cloneable { return Collections.emptySet(); } - public void addRankFeature(ReferenceNode feature) { + private void addRankFeature(ReferenceNode feature) { if (rankFeatures == null) rankFeatures = new LinkedHashSet<>(); rankFeatures.add(feature); @@ -925,7 +931,7 @@ public class RankProfile implements Serializable, Cloneable { /** True if this should be inlined into calling expressions. Useful for very cheap functions. */ private final boolean inline; - public RankingExpressionFunction(ExpressionFunction function, boolean inline) { + RankingExpressionFunction(ExpressionFunction function, boolean inline) { this.function = function; this.inline = inline; } @@ -940,7 +946,7 @@ public class RankProfile implements Serializable, Cloneable { return inline && function.arguments().isEmpty(); // only inline no-arg functions; } - public RankingExpressionFunction withExpression(RankingExpression expression) { + RankingExpressionFunction withExpression(RankingExpression expression) { return new RankingExpressionFunction(function.withBody(expression), inline); } @@ -968,7 +974,7 @@ public class RankProfile implements Serializable, Cloneable { public double getCutoffFactor() { return cutoffFactor; } public Diversity.CutoffStrategy getCutoffStrategy() { return cutoffStrategy; } - public void checkValid() { + void checkValid() { if (attribute == null || attribute.isEmpty()) { throw new IllegalArgumentException("'diversity' did not set non-empty diversity attribute name."); } @@ -1026,7 +1032,7 @@ public class RankProfile implements Serializable, Cloneable { private final Map<String, String> types = new HashMap<>(); - public void addType(String name, String type) { + void addType(String name, String type) { types.put(name, type); } 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 53afebfd93b..bf585df9005 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfileRegistry.java @@ -20,8 +20,8 @@ import java.util.Set; */ public class RankProfileRegistry { - private final Map<RankProfile, Search> rankProfileToSearch = new LinkedHashMap<>(); - private final Map<Search, Map<String, RankProfile>> rankProfiles = new LinkedHashMap<>(); + private final Map<RankProfile, ImmutableSearch> rankProfileToSearch = new LinkedHashMap<>(); + private final Map<ImmutableSearch, Map<String, RankProfile>> rankProfiles = new LinkedHashMap<>(); /* 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")); @@ -65,7 +65,7 @@ public class RankProfileRegistry { * @param name the name of the rank profile * @return the RankProfile to return. */ - public RankProfile get(Search search, String name) { + public RankProfile get(ImmutableSearch search, String name) { Map<String, RankProfile> profiles = rankProfiles.get(search); if (profiles == null) return null; return profiles.get(name); @@ -85,7 +85,7 @@ public class RankProfileRegistry { * @param search {@link Search} to get rank profiles for * @return a collection of {@link RankProfile} instances */ - public Collection<RankProfile> rankProfilesOf(Search search) { + public Collection<RankProfile> rankProfilesOf(ImmutableSearch search) { Map<String, RankProfile> mapping = rankProfiles.get(search); if (mapping == null) { return Collections.emptyList(); 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 81c549a6f78..5a373cfc55f 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/Search.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/Search.java @@ -6,6 +6,7 @@ import com.yahoo.document.Field; import com.yahoo.searchdefinition.derived.SummaryClass; import com.yahoo.searchdefinition.document.Attribute; import com.yahoo.searchdefinition.document.ImmutableSDField; +import com.yahoo.searchdefinition.document.ImportedField; import com.yahoo.searchdefinition.document.ImportedFields; import com.yahoo.searchdefinition.document.SDDocumentType; import com.yahoo.searchdefinition.document.SDField; @@ -40,7 +41,7 @@ import java.util.stream.Stream; // TODO: Make a class owned by this, for each of these responsibilities: // Managing indexes, managing attributes, managing summary classes. // Ensure that after the processing step, all implicit instances of the above types are explicitly represented -public class Search implements Serializable, ImmutableSearch { +public class Search implements ImmutableSearch { private static final Logger log = Logger.getLogger(Search.class.getName()); private static final String SD_DOC_FIELD_NAME = "sddocname"; @@ -53,7 +54,7 @@ public class Search implements Serializable, ImmutableSearch { return RESERVED_NAMES.contains(name); } - private FieldSets fieldSets = new FieldSets(); + private final FieldSets fieldSets = new FieldSets(); /** The unique name of this search definition */ private String name; @@ -68,26 +69,27 @@ public class Search implements Serializable, ImmutableSearch { private SDDocumentType docType; /** The extra fields of this search definition */ - private Map<String, SDField> fields = new LinkedHashMap<>(); + private final Map<String, SDField> fields = new LinkedHashMap<>(); /** The explicitly defined indices of this search definition */ - private Map<String, Index> indices = new LinkedHashMap<>(); + private final Map<String, Index> indices = new LinkedHashMap<>(); /** The explicitly defined summaries of this search definition. _Must_ preserve order. */ - private Map<String, DocumentSummary> summaries = new LinkedHashMap<>(); + private final Map<String, DocumentSummary> summaries = new LinkedHashMap<>(); /** Ranking constants of this */ - private RankingConstants rankingConstants = new RankingConstants(); + private final RankingConstants rankingConstants = new RankingConstants(); private Optional<TemporaryImportedFields> temporaryImportedFields = Optional.of(new TemporaryImportedFields()); private Optional<ImportedFields> importedFields = Optional.empty(); - private ApplicationPackage applicationPackage; + private final ApplicationPackage applicationPackage; /** * Creates a search definition which just holds a set of documents which should not (here, directly) be searchable */ protected Search() { + applicationPackage = null; documentsOnly = true; } @@ -106,6 +108,7 @@ public class Search implements Serializable, ImmutableSearch { this.name = name; } + @Override public String getName() { return name; } @@ -154,6 +157,7 @@ public class Search implements Serializable, ImmutableSearch { docType = document; } + @Override public RankingConstants rankingConstants() { return rankingConstants; } public Optional<TemporaryImportedFields> temporaryImportedFields() { @@ -188,12 +192,18 @@ public class Search implements Serializable, ImmutableSearch { } @Override - public Stream<ImmutableSDField> allFields() { - Stream<ImmutableSDField> extraFields = extraFieldList().stream().map(ImmutableSDField.class::cast); - Stream<ImmutableSDField> documentFields = docType.fieldSet().stream().map(ImmutableSDField.class::cast); - return Stream.concat( - extraFields, - Stream.concat(documentFields, allImportedFields())); + public List<ImmutableSDField> allFieldsList() { + List<ImmutableSDField> all = new ArrayList<>(); + all.addAll(extraFieldList()); + for (Field field : docType.fieldSet()) { + all.add((ImmutableSDField) field); + } + if (importedFields.isPresent()) { + for (ImportedField imported : importedFields.get().fields().values()) { + all.add(imported.asImmutableSDField()); + } + } + return all; } /** @@ -228,6 +238,7 @@ public class Search implements Serializable, ImmutableSearch { * they inherit, and all extra fields. The caller receives ownership to the list - subsequent changes to it will not * impact this */ + @Override public List<SDField> allConcreteFields() { List<SDField> allFields = new ArrayList<>(); allFields.addAll(extraFieldList()); @@ -240,10 +251,12 @@ public class Search implements Serializable, ImmutableSearch { /** * Returns the content of a ranking expression file */ + @Override public Reader getRankingExpression(String fileName) { return applicationPackage.getRankingExpression(fileName); } + @Override public ApplicationPackage applicationPackage() { return applicationPackage; } /** @@ -253,6 +266,7 @@ public class Search implements Serializable, ImmutableSearch { * @param name of the field * @return the SDField representing the field */ + @Override public SDField getConcreteField(String name) { SDField field = getExtraField(name); if (field != null) { @@ -331,6 +345,7 @@ public class Search implements Serializable, ImmutableSearch { * @param name the name of the index to get * @return the index requested */ + @Override public Index getIndex(String name) { List<Index> sameIndices = new ArrayList<>(1); Index searchIndex = indices.get(name); @@ -405,6 +420,7 @@ public class Search implements Serializable, ImmutableSearch { * * @return The list of explicit defined indexes. */ + @Override public List<Index> getExplicitIndices() { List<Index> allIndices = new ArrayList<>(indices.values()); for (SDField field : allConcreteFields()) { 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 8b523211471..93b3ff29e13 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 @@ -1,7 +1,12 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchdefinition.document; -import com.yahoo.document.*; +import com.yahoo.document.CollectionDataType; +import com.yahoo.document.DataType; +import com.yahoo.document.DocumentType; +import com.yahoo.document.Field; +import com.yahoo.document.MapDataType; +import com.yahoo.document.StructDataType; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.searchdefinition.Index; @@ -12,12 +17,25 @@ import com.yahoo.vespa.documentmodel.SummaryField; import com.yahoo.vespa.indexinglanguage.ExpressionSearcher; import com.yahoo.vespa.indexinglanguage.ExpressionVisitor; import com.yahoo.vespa.indexinglanguage.ScriptParserContext; -import com.yahoo.vespa.indexinglanguage.expressions.*; +import com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression; +import com.yahoo.vespa.indexinglanguage.expressions.Expression; +import com.yahoo.vespa.indexinglanguage.expressions.IndexExpression; +import com.yahoo.vespa.indexinglanguage.expressions.LowerCaseExpression; +import com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression; +import com.yahoo.vespa.indexinglanguage.expressions.SummaryExpression; import com.yahoo.vespa.indexinglanguage.parser.IndexingInput; import com.yahoo.vespa.indexinglanguage.parser.ParseException; -import java.io.Serializable; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.TreeMap; + /** * The field class represents a document field. It is used in @@ -28,7 +46,7 @@ import java.util.*; * * @author bratseth */ -public class SDField extends Field implements TypedKey, FieldOperationContainer, ImmutableSDField, Serializable { +public class SDField extends Field implements TypedKey, FieldOperationContainer, ImmutableSDField { /** Use this field for modifying index-structure, even if it doesn't have any indexing code */ private boolean indexStructureField = false; @@ -89,7 +107,7 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, private Map<String,SDField> structFields = new java.util.LinkedHashMap<>(0); /** The document that this field was declared in, or null*/ - protected SDDocumentType ownerDocType = null; + private SDDocumentType ownerDocType = null; /** The aliases declared for this field. May pertain to indexes or attributes */ private Map<String, String> aliasToName = new HashMap<>(); @@ -235,7 +253,7 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, return findExpression(searchFor) != null; } - public <T extends Expression> T findExpression(Class<T> searchFor) { + private <T extends Expression> T findExpression(Class<T> searchFor) { return new ExpressionSearcher<>(searchFor).searchIn(indexingScript); } @@ -401,7 +419,7 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, return (dataType instanceof StructDataType) ? (StructDataType)dataType : null; } - public DataType getFirstStructOrMapRecursive() { + private DataType getFirstStructOrMapRecursive() { DataType dataType = getDataType(); while (dataType instanceof CollectionDataType) { // Currently no nesting of collections dataType = ((CollectionDataType)dataType).getNestedType(); @@ -409,7 +427,7 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, return (dataType instanceof StructDataType || dataType instanceof MapDataType) ? dataType : null; } - public boolean usesStruct() { + private boolean usesStruct() { DataType dt = getFirstStructRecursive(); return (dt != null); } @@ -421,7 +439,6 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, } /** Parse an indexing expression which will use the simple linguistics implementatino suitable for testing */ - @SuppressWarnings("deprecation") public void parseIndexingScript(String script) { parseIndexingScript(script, new SimpleLinguistics()); } @@ -770,7 +787,7 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, * The document that this field was declared in, or null * */ - public SDDocumentType getOwnerDocType() { + private SDDocumentType getOwnerDocType() { return ownerDocType; } |