diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-26 15:12:49 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-26 15:12:49 +0200 |
commit | 5f35f84715de58bfcfe0c5332f60e76ca96c6f7d (patch) | |
tree | 83192060f6616e33656318c981a045bd0f9adcd5 /container-search/src/main/java | |
parent | d11721c9bb7b532a2c3471232e68a95ce442d895 (diff) |
Cleanup some unmaintainable mess
Diffstat (limited to 'container-search/src/main/java')
4 files changed, 52 insertions, 42 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/Query.java b/container-search/src/main/java/com/yahoo/search/Query.java index c6ce9dc404a..4e4a4822064 100644 --- a/container-search/src/main/java/com/yahoo/search/Query.java +++ b/container-search/src/main/java/com/yahoo/search/Query.java @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.yahoo.collections.Tuple2; import com.yahoo.component.Version; @@ -47,9 +48,11 @@ import com.yahoo.yolean.Exceptions; import edu.umd.cs.findbugs.annotations.Nullable; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Logger; @@ -243,6 +246,25 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { registry.register(DefaultProperties.argumentType.unfrozen()); } + /** Returns an unmodifiable list of all the native properties under a Query */ + public static final List<CompoundName> nativeProperties = + ImmutableList.copyOf(namesUnder(CompoundName.empty, Query.getArgumentType())); + + private static List<CompoundName> namesUnder(CompoundName prefix, QueryProfileType type) { + if ( type == null) return Collections.emptyList(); // Names not known statically + List<CompoundName> names = new ArrayList<>(); + for (Map.Entry<String, FieldDescription> field : type.fields().entrySet()) { + if (field.getValue().getType() instanceof QueryProfileFieldType) { + names.addAll(namesUnder(prefix.append(field.getKey()), + ((QueryProfileFieldType) field.getValue().getType()).getQueryProfileType())); + } + else { + names.add(prefix.append(field.getKey())); + } + } + return names; + } + //---------------- Construction ------------------------------------ /** diff --git a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java index 9034484b022..686c019688e 100644 --- a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.federation; +import com.google.common.collect.ImmutableList; import com.google.inject.Inject; import com.yahoo.collections.Pair; import com.yahoo.component.ComponentId; @@ -93,6 +94,8 @@ public class FederationSearcher extends ForkingSearcher { private final Clock clock = Clock.systemUTC(); + private static final List<CompoundName> queryAndHits = ImmutableList.of(Query.OFFSET, Query.HITS); + @Inject public FederationSearcher(FederationConfig config, StrictContractsConfig strict, ComponentRegistry<TargetSelector> targetSelectors) { @@ -277,11 +280,11 @@ public class FederationSearcher extends ForkingSearcher { switch (propagateSourceProperties) { case ALL: propagatePerSourceQueryProperties(query, outgoing, window, sourceName, providerName, - QueryProperties.PER_SOURCE_QUERY_PROPERTIES); + Query.nativeProperties); break; case OFFSET_HITS: propagatePerSourceQueryProperties(query, outgoing, window, sourceName, providerName, - new CompoundName[]{Query.OFFSET, Query.HITS}); + queryAndHits); break; } @@ -293,7 +296,7 @@ public class FederationSearcher extends ForkingSearcher { private void propagatePerSourceQueryProperties(Query original, Query outgoing, Window window, String sourceName, String providerName, - CompoundName[] queryProperties) { + List<CompoundName> queryProperties) { for (CompoundName key : queryProperties) { Object value = getSourceOrProviderProperty(original, key, sourceName, providerName, window.get(key)); if (value != null) diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java index c826d834d47..2ec3df4a976 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java @@ -299,20 +299,20 @@ public class QueryProfileType extends FreezableSimpleComponent { } } - private void addAlias(String alias,String field) { + private void addAlias(String alias, String field) { ensureNotFrozen(); - if (aliases==null) - aliases=new HashMap<>(); - aliases.put(toLowerCase(alias),field); + if (aliases == null) + aliases = new HashMap<>(); + aliases.put(toLowerCase(alias), field); } /** Returns all the fields of this profile type and all types it inherits as a read-only map */ - public Map<String,FieldDescription> fields() { + public Map<String, FieldDescription> fields() { if (isFrozen()) return fields; - if (inherited().size()==0) return Collections.unmodifiableMap(fields); + if (inherited().size() == 0) return Collections.unmodifiableMap(fields); // Collapse inherited - Map<String,FieldDescription> allFields=new HashMap<>(fields); + Map<String, FieldDescription> allFields = new HashMap<>(fields); for (QueryProfileType inheritedType : inherited) allFields.putAll(inheritedType.fields()); return Collections.unmodifiableMap(allFields); @@ -322,7 +322,7 @@ public class QueryProfileType extends FreezableSimpleComponent { * Returns the alias to field mapping of this type as a read-only map. This is never null. * Note that all keys are lower-cased because aliases are case-insensitive */ - public Map<String,String> aliases() { + public Map<String, String> aliases() { if (isFrozen()) return aliases; if (aliases == null) return Collections.emptyMap(); return Collections.unmodifiableMap(aliases); @@ -330,9 +330,9 @@ public class QueryProfileType extends FreezableSimpleComponent { /** Returns the field name of an alias or field name */ public String unalias(String aliasOrField) { - if (aliases==null || aliases.isEmpty()) return aliasOrField; - String field=aliases.get(toLowerCase(aliasOrField)); - if (field!=null) return field; + if (aliases == null || aliases.isEmpty()) return aliasOrField; + String field = aliases.get(toLowerCase(aliasOrField)); + if (field != null) return field; return aliasOrField; } diff --git a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java index 1422194ebdd..0aea5e96161 100644 --- a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java +++ b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java @@ -6,6 +6,7 @@ import com.yahoo.search.Query; import com.yahoo.search.query.*; import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry; import com.yahoo.search.query.profile.types.FieldDescription; +import com.yahoo.search.query.profile.types.QueryProfileFieldType; import com.yahoo.search.query.profile.types.QueryProfileType; import com.yahoo.search.query.ranking.Diversity; import com.yahoo.search.query.ranking.MatchPhase; @@ -13,6 +14,9 @@ import com.yahoo.search.query.ranking.Matching; import com.yahoo.search.query.ranking.SoftTimeout; import com.yahoo.tensor.Tensor; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.Map; /** @@ -24,33 +28,13 @@ import java.util.Map; */ public class QueryProperties extends Properties { - public static final CompoundName[] PER_SOURCE_QUERY_PROPERTIES = new CompoundName[] { - Query.HITS, - Query.OFFSET, - Query.TRACE_LEVEL, - Query.TIMEOUT, - Query.NO_CACHE, - Query.GROUPING_SESSION_CACHE, - CompoundName.fromComponents(Model.MODEL, Model.QUERY_STRING), - CompoundName.fromComponents(Model.MODEL, Model.TYPE), - CompoundName.fromComponents(Model.MODEL, Model.FILTER), - CompoundName.fromComponents(Model.MODEL, Model.DEFAULT_INDEX), - CompoundName.fromComponents(Model.MODEL, Model.LANGUAGE), - CompoundName.fromComponents(Model.MODEL, Model.ENCODING), - CompoundName.fromComponents(Model.MODEL, Model.SOURCES), - CompoundName.fromComponents(Model.MODEL, Model.SEARCH_PATH), - CompoundName.fromComponents(Model.MODEL, Model.RESTRICT), - CompoundName.fromComponents(Ranking.RANKING, Ranking.LOCATION), - CompoundName.fromComponents(Ranking.RANKING, Ranking.PROFILE), - CompoundName.fromComponents(Ranking.RANKING, Ranking.SORTING), - CompoundName.fromComponents(Ranking.RANKING, Ranking.FRESHNESS), - CompoundName.fromComponents(Ranking.RANKING, Ranking.QUERYCACHE), - CompoundName.fromComponents(Ranking.RANKING, Ranking.LIST_FEATURES), - CompoundName.fromComponents(Presentation.PRESENTATION, Presentation.BOLDING), - CompoundName.fromComponents(Presentation.PRESENTATION, Presentation.SUMMARY), - CompoundName.fromComponents(Presentation.PRESENTATION, Presentation.REPORT_COVERAGE), - CompoundName.fromComponents(Presentation.PRESENTATION, Presentation.FORMAT), - CompoundName.fromComponents(Presentation.PRESENTATION, Presentation.SUMMARY_FIELDS)}; + /** + * TODO: Remove on Vespa 7 + * @deprecated use Query.nativeProperties + */ + @Deprecated + public static final CompoundName[] PER_SOURCE_QUERY_PROPERTIES = + Query.nativeProperties.toArray(new CompoundName[] {}); private Query query; private final CompiledQueryProfileRegistry profileRegistry; @@ -299,7 +283,7 @@ public class QueryProperties extends Properties { Map<String,String> context, com.yahoo.processing.request.Properties substitution) { Map<String, Object> properties = super.listProperties(prefix, context, substitution); - for (CompoundName queryProperty : PER_SOURCE_QUERY_PROPERTIES) { + for (CompoundName queryProperty : Query.nativeProperties) { if (queryProperty.hasPrefix(prefix)) { Object value = this.get(queryProperty, context, substitution); if (value != null) @@ -333,4 +317,5 @@ public class QueryProperties extends Properties { public final Query getParentQuery() { return query; } + } |