diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-29 12:25:00 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-29 12:34:00 +0200 |
commit | 656e755c584897d298fcf95bea5376f1fb1c13f5 (patch) | |
tree | a7f7423e01ae62a46c33abbcb6f658d8ef16014c /container-search/src/main/java/com/yahoo/search/grouping | |
parent | 7ac642eefd2be2b52aa0878ad8d926521fe00a20 (diff) |
Use CompoundName.from in tests and construction of static objects.
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/grouping')
3 files changed, 23 insertions, 33 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java b/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java index 54194221958..180687d5274 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java @@ -38,13 +38,13 @@ import java.util.TimeZone; public class GroupingQueryParser extends Searcher { public static final String SELECT_PARAMETER_PARSING = "SelectParameterParsing"; - public static final CompoundName PARAM_CONTINUE = new CompoundName("continue"); - public static final CompoundName PARAM_REQUEST = new CompoundName(Select.SELECT); - public static final CompoundName PARAM_TIMEZONE = new CompoundName("timezone"); - @Beta public static final CompoundName PARAM_DEFAULT_MAX_HITS = new CompoundName("grouping.defaultMaxHits"); - @Beta public static final CompoundName PARAM_DEFAULT_MAX_GROUPS = new CompoundName("grouping.defaultMaxGroups"); - @Beta public static final CompoundName PARAM_DEFAULT_PRECISION_FACTOR = new CompoundName("grouping.defaultPrecisionFactor"); - @Beta public static final CompoundName GROUPING_GLOBAL_MAX_GROUPS = new CompoundName("grouping.globalMaxGroups"); + public static final CompoundName PARAM_CONTINUE = CompoundName.from("continue"); + public static final CompoundName PARAM_REQUEST = CompoundName.from(Select.SELECT); + public static final CompoundName PARAM_TIMEZONE = CompoundName.from("timezone"); + @Beta public static final CompoundName PARAM_DEFAULT_MAX_HITS = CompoundName.from("grouping.defaultMaxHits"); + @Beta public static final CompoundName PARAM_DEFAULT_MAX_GROUPS = CompoundName.from("grouping.defaultMaxGroups"); + @Beta public static final CompoundName PARAM_DEFAULT_PRECISION_FACTOR = CompoundName.from("grouping.defaultPrecisionFactor"); + @Beta public static final CompoundName GROUPING_GLOBAL_MAX_GROUPS = CompoundName.from("grouping.globalMaxGroups"); private static final ThreadLocal<ZoneCache> zoneCache = new ThreadLocal<>(); @Override @@ -121,7 +121,6 @@ public class GroupingQueryParser extends Searcher { return val != null ? OptionalDouble.of(val) : OptionalDouble.empty(); } - @SuppressWarnings("serial") private static class ZoneCache extends LinkedHashMap<String, TimeZone> { ZoneCache() { diff --git a/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java b/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java index 35cf72d6124..878fbbb733d 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java @@ -37,7 +37,7 @@ import static com.yahoo.search.grouping.GroupingQueryParser.SELECT_PARAMETER_PAR public class GroupingValidator extends Searcher { public static final String GROUPING_VALIDATED = "GroupingValidated"; - public static final CompoundName PARAM_ENABLED = new CompoundName("validate_" + GroupingQueryParser.PARAM_REQUEST); + public static final CompoundName PARAM_ENABLED = CompoundName.from("validate_" + GroupingQueryParser.PARAM_REQUEST); private final HashMap<String, AttributesConfig.Attribute> attributes = new HashMap<>(); private final String clusterName; private final boolean enabled; diff --git a/container-search/src/main/java/com/yahoo/search/grouping/UniqueGroupingSearcher.java b/container-search/src/main/java/com/yahoo/search/grouping/UniqueGroupingSearcher.java index a1446367f79..27d8a76511d 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/UniqueGroupingSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/UniqueGroupingSearcher.java @@ -42,7 +42,7 @@ import java.util.logging.Logger; @Before(PhaseNames.TRANSFORMED_QUERY) public class UniqueGroupingSearcher extends Searcher { - public static final CompoundName PARAM_UNIQUE = new CompoundName("unique"); + public static final CompoundName PARAM_UNIQUE = CompoundName.from("unique"); private static final Logger log = Logger.getLogger(UniqueGroupingSearcher.class.getName()); private static final HitOrderer NOP_ORDERER = new HitOrderer() { @@ -144,17 +144,13 @@ public class UniqueGroupingSearcher extends Searcher { for (Sorting.FieldOrder fieldOrder : sortingSpec.fieldOrders()) { Sorting.Order sortOrder = fieldOrder.getSortOrder(); switch (sortOrder) { - case ASCENDING: - case UNDEFINED: - // When we want ascending order, the hit with the smallest value should come first (and be surfaced). - orderingClause.add(new MinAggregator(new AttributeValue(fieldOrder.getFieldName()))); - break; - case DESCENDING: - // When we sort in descending order, the hit with the largest value should come first (and be surfaced). - orderingClause.add(new NegFunction(new MaxAggregator(new AttributeValue(fieldOrder.getFieldName())))); - break; - default: - throw new UnsupportedOperationException("Can not handle sort order " + sortOrder + "."); + case ASCENDING, UNDEFINED -> + // When we want ascending order, the hit with the smallest value should come first (and be surfaced). + orderingClause.add(new MinAggregator(new AttributeValue(fieldOrder.getFieldName()))); + case DESCENDING -> + // When we sort in descending order, the hit with the largest value should come first (and be surfaced). + orderingClause.add(new NegFunction(new MaxAggregator(new AttributeValue(fieldOrder.getFieldName())))); + default -> throw new UnsupportedOperationException("Can not handle sort order " + sortOrder + "."); } } return orderingClause; @@ -170,18 +166,13 @@ public class UniqueGroupingSearcher extends Searcher { GroupingExpression groupingClause = null; for (Sorting.FieldOrder fieldOrder : sortingSpec.fieldOrders()) { Sorting.Order sortOrder = fieldOrder.getSortOrder(); - switch (sortOrder) { - case ASCENDING: - case UNDEFINED: - groupingClause = new AttributeValue(fieldOrder.getFieldName()); - break; - case DESCENDING: - // To sort descending, just take the negative. This is the most common case - groupingClause = new NegFunction(new AttributeValue(fieldOrder.getFieldName())); - break; - default: - throw new UnsupportedOperationException("Can not handle sort order " + sortOrder + "."); - } + groupingClause = switch (sortOrder) { + case ASCENDING, UNDEFINED -> new AttributeValue(fieldOrder.getFieldName()); + case DESCENDING -> + // To sort descending, just take the negative. This is the most common case + new NegFunction(new AttributeValue(fieldOrder.getFieldName())); + default -> throw new UnsupportedOperationException("Can not handle sort order " + sortOrder + "."); + }; } return groupingClause; } |