diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2022-03-23 14:10:50 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2022-03-23 15:06:03 +0100 |
commit | da82f0eb66032d2e2de918bc60fe0dfb2a45d610 (patch) | |
tree | 8ad1b816b80eede0ff578757d4b9ecc83ce15bed /container-search/src/main/java | |
parent | 4a6506e8e721d75d91e1398a876653df1e749d2b (diff) |
Allow 'inf' as value to max()
Diffstat (limited to 'container-search/src/main/java')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/grouping/request/GroupingOperation.java | 5 | ||||
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/grouping/vespa/RequestBuilder.java | 15 |
2 files changed, 13 insertions, 7 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/grouping/request/GroupingOperation.java b/container-search/src/main/java/com/yahoo/search/grouping/request/GroupingOperation.java index a4934586b3f..db9585e0637 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/request/GroupingOperation.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/request/GroupingOperation.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.grouping.request; +import com.yahoo.api.annotations.Beta; import com.yahoo.collections.LazyMap; import com.yahoo.collections.LazySet; import com.yahoo.search.grouping.request.parser.GroupingParser; @@ -25,6 +26,8 @@ import java.util.Set; */ public abstract class GroupingOperation extends GroupingNode { + @Beta public static final int UNLIMITED_MAX = Integer.MAX_VALUE; + private final List<GroupingExpression> orderBy = new ArrayList<>(); private final List<GroupingExpression> outputs = new ArrayList<>(); private final List<GroupingOperation> children = new ArrayList<>(); @@ -269,6 +272,8 @@ public abstract class GroupingOperation extends GroupingNode { /** Indicates if the 'max' value has been set. */ public boolean hasMax() { return max >= 0; } + @Beta public boolean hasUnlimitedMax() { return max == Integer.MAX_VALUE; } + /** * Assigns an accuracy value for this. This is a number between 0 and 1 describing the accuracy of the result, which * again determines the speed of the grouping request. A low value will make sure the grouping operation runs fast, diff --git a/container-search/src/main/java/com/yahoo/search/grouping/vespa/RequestBuilder.java b/container-search/src/main/java/com/yahoo/search/grouping/vespa/RequestBuilder.java index 5ee6f7bc604..a77e83e0078 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/vespa/RequestBuilder.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/vespa/RequestBuilder.java @@ -179,14 +179,14 @@ class RequestBuilder { grpLevel.setPrecision(frame.state.precision + offset); frame.state.precision = null; } - int max = -1; + int max = GroupingOperation.UNSPECIFIED_MAX; if (frame.state.max != null) { max = frame.state.max; frame.state.max = null; } else if (defaultMaxGroups >= 0) { max = defaultMaxGroups; } - if (max >= 0) { + if (max >= 0 && max != GroupingOperation.UNLIMITED_MAX) { transform.putMax(tag, max, "group list"); grpLevel.setMaxGroups(LOOKAHEAD + max + offset); } @@ -246,11 +246,12 @@ class RequestBuilder { } private void resolveMax(BuildFrame frame) { if (frame.astNode.hasMax()) { - int max = frame.astNode.getMax(); if (isTopNAllowed(frame)) { - frame.grouping.setTopN(computeNewTopN(frame.grouping.getTopN(), max)); + if (!frame.astNode.hasUnlimitedMax()) { + frame.grouping.setTopN(computeNewTopN(frame.grouping.getTopN(), frame.astNode.getMax())); + } } else { - frame.state.max = max; + frame.state.max = frame.astNode.getMax(); } } } @@ -297,14 +298,14 @@ class RequestBuilder { throw new UnsupportedOperationException("Can not label expression '" + exp + "'."); } HitsAggregationResult hits = (HitsAggregationResult)result; - int max = -1; + int max = GroupingOperation.UNSPECIFIED_MAX; if (frame.state.max != null) { max = frame.state.max; frame.state.max = null; } else if (defaultMaxHits >= 0) { max = defaultMaxHits; } - if (max >= 0) { + if (max >= 0 && max != GroupingOperation.UNLIMITED_MAX) { transform.putMax(tag, max, "hit list"); int offset = transform.getOffset(tag); hits.setMaxHits(LOOKAHEAD + max + offset); |