aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/grouping/GroupingRequest.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/grouping/GroupingRequest.java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/grouping/GroupingRequest.java92
1 files changed, 39 insertions, 53 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/grouping/GroupingRequest.java b/container-search/src/main/java/com/yahoo/search/grouping/GroupingRequest.java
index 754d3b562d3..8ce0d90dfc5 100644
--- a/container-search/src/main/java/com/yahoo/search/grouping/GroupingRequest.java
+++ b/container-search/src/main/java/com/yahoo/search/grouping/GroupingRequest.java
@@ -8,7 +8,6 @@ import com.yahoo.search.Result;
import com.yahoo.search.grouping.request.GroupingOperation;
import com.yahoo.search.grouping.result.Group;
import com.yahoo.search.grouping.result.RootGroup;
-import com.yahoo.search.query.Select;
import com.yahoo.search.result.Hit;
import java.util.*;
@@ -20,53 +19,35 @@ import java.util.*;
* result {@link Group} using the {@link #getResultGroup(Result)} method.
*
* @author Simon Thoresen Hult
- * @author bratseth
*/
public class GroupingRequest {
- private final Select parent;
+ private final static CompoundName PROP_REQUEST = new CompoundName(GroupingRequest.class.getName() + ".Request");
private final List<Continuation> continuations = new ArrayList<>();
+ private final int requestId;
private GroupingOperation root;
private TimeZone timeZone;
private URI resultId;
- private GroupingRequest(Select parent) {
- this.parent = parent;
- }
-
- private GroupingRequest(Select parent,
- List<Continuation> continuations,
- GroupingOperation root,
- TimeZone timeZone,
- URI resultId) {
- this.parent = parent;
- continuations.forEach(item -> this.continuations.add(item.copy()));
- this.root = root != null ? root.copy(null) : null;
- this.timeZone = timeZone;
- this.resultId = resultId;
- }
-
- /** Returns a deep copy of this */
- public GroupingRequest copy(Select parentOfCopy) {
- return new GroupingRequest(parentOfCopy, continuations, root, timeZone, resultId);
+ private GroupingRequest(int requestId) {
+ this.requestId = requestId;
}
/**
- * Returns the id of this GroupingRequest.
- * This id is injected into the {@link RootGroup} of the final result, and
+ * Returns the id of this GroupingRequest. This id is injected into the {@link RootGroup} of the final result, and
* allows tracking of per-request meta data.
*
- * @return the id of this request, or -1 if it has been removed from the query select statement
+ * @return The id of this.
*/
public int getRequestId() {
- return parent.getGrouping().indexOf(this);
+ return requestId;
}
/**
* Returns the root {@link GroupingOperation} that defines this request. As long as this remains unset, the request
* is void.
*
- * @return the root operation.
+ * @return The root operation.
*/
public GroupingOperation getRootOperation() {
return root;
@@ -76,8 +57,8 @@ public class GroupingRequest {
* Sets the root {@link GroupingOperation} that defines this request. As long as this remains unset, the request is
* void.
*
- * @param root the root operation to set.
- * @return this, to allow chaining.
+ * @param root The root operation to set.
+ * @return This, to allow chaining.
*/
public GroupingRequest setRootOperation(GroupingOperation root) {
this.root = root;
@@ -88,7 +69,7 @@ public class GroupingRequest {
* Returns the {@link TimeZone} used when resolving time expressions such as {@link
* com.yahoo.search.grouping.request.DayOfMonthFunction} and {@link com.yahoo.search.grouping.request.HourOfDayFunction}.
*
- * @return the time zone in use.
+ * @return The time zone in use.
*/
public TimeZone getTimeZone() {
return timeZone;
@@ -98,8 +79,8 @@ public class GroupingRequest {
* Sets the {@link TimeZone} used when resolving time expressions such as {@link
* com.yahoo.search.grouping.request.DayOfMonthFunction} and {@link com.yahoo.search.grouping.request.HourOfDayFunction}.
*
- * @param timeZone the time zone to set.
- * @return this, to allow chaining.
+ * @param timeZone The time zone to set.
+ * @return This, to allow chaining.
*/
public GroupingRequest setTimeZone(TimeZone timeZone) {
this.timeZone = timeZone;
@@ -111,8 +92,8 @@ public class GroupingRequest {
* search returns. Because searchers are allowed to modify both {@link Result} and {@link Hit} objects freely, this
* method requires that you pass it the current {@link Result} object as argument.
*
- * @param result the search result that contains the root group.
- * @return the result {@link RootGroup} of this request, or null if not found.
+ * @param result The search result that contains the root group.
+ * @return The result {@link RootGroup} of this request, or null if not found.
*/
public RootGroup getResultGroup(Result result) {
Hit root = result.hits().get(resultId, -1);
@@ -126,8 +107,8 @@ public class GroupingRequest {
* Sets the result {@link RootGroup} of this request. This is used by the executing grouping searcher, and should
* not be called by a requesting searcher.
*
- * @param group the result to set.
- * @return this, to allow chaining.
+ * @param group The result to set.
+ * @return This, to allow chaining.
*/
public GroupingRequest setResultGroup(RootGroup group) {
this.resultId = group.getId();
@@ -138,41 +119,46 @@ public class GroupingRequest {
* Returns the list of {@link Continuation}s of this request. This is used by the executing grouping searcher to
* allow pagination of grouping results.
*
- * @return the list of Continuations.
+ * @return The list of Continuations.
*/
public List<Continuation> continuations() {
return continuations;
}
/**
- * Creates a new grouping request and adds it to the query.getSelect().getGrouping() list
+ * Creates and attaches a new instance of this class to the given {@link Query}. This is necessary to allow {@link
+ * #getRequests(Query)} to return all created requests.
*
- * @param query the query to attach the request to.
+ * @param query The query to attach the request to.
* @return The created request.
*/
public static GroupingRequest newInstance(Query query) {
- GroupingRequest newRequest = new GroupingRequest(query.getSelect());
- query.getSelect().getGrouping().add(newRequest);
- return newRequest;
+ List<GroupingRequest> lst = getRequests(query);
+ if (lst.isEmpty()) {
+ lst = new LinkedList<>();
+ query.properties().set(PROP_REQUEST, lst);
+ }
+ GroupingRequest ret = new GroupingRequest(lst.size());
+ lst.add(ret);
+ return ret;
}
/**
* Returns all instances of this class that have been attached to the given {@link Query}. If no requests have been
* attached to the {@link Query}, this method returns an empty list.
*
- * @param query the query whose requests to return.
- * @return the list of grouping requests.
- * @deprecated use query.getSelect().getGrouping()
+ * @param query The query whose requests to return.
+ * @return The list of grouping requests.
*/
@SuppressWarnings({ "unchecked" })
- @Deprecated
public static List<GroupingRequest> getRequests(Query query) {
- return query.getSelect().getGrouping();
- }
-
- @Override
- public String toString() {
- return root == null ? "(empty)" : root.toString();
+ Object lst = query.properties().get(PROP_REQUEST);
+ if (lst == null) {
+ return Collections.emptyList();
+ }
+ if (!(lst instanceof List)) {
+ throw new IllegalArgumentException("Expected " + GroupingRequest.class + ", got " + lst.getClass() + ".");
+ }
+ return (List<GroupingRequest>)lst;
}
-
}