Class GroupingOperation
java.lang.Object
com.yahoo.search.grouping.request.GroupingNode
com.yahoo.search.grouping.request.GroupingOperation
- Direct Known Subclasses:
AllOperation
,EachOperation
A single node in a grouping operation tree. You may manually construct this tree, or you may
use the
fromString(String)
method to generate one from a query-string. To execute, assign it to a GroupingRequest
using the
GroupingRequest.setRootOperation(GroupingOperation)
method.- Author:
- Simon Thoresen Hult
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
GroupingOperation
(GroupingOperation parentOfCopy, String image, String label, List<GroupingExpression> orderBy, List<GroupingExpression> outputs, List<GroupingOperation> children, Map<String, GroupingExpression> aliases, Set<String> hints, GroupingExpression groupBy, String where, boolean forceSinglePass, double accuracy, int precision, int level, int max) protected
GroupingOperation
(String image, String label) -
Method Summary
Modifier and TypeMethodDescriptionAdds a child grouping node to this.addChildren
(List<GroupingOperation> lst) Convenience method to calladdChild(GroupingOperation)
for each element in the given list.Adds a hint to this.Adds an expression to the order-by clause of this operation.addOrderBy
(List<GroupingExpression> list) Convenience method to calladdOrderBy(GroupingExpression)
for each element in the given list.Adds an expression to the output clause of this operation.addOutputs
(List<GroupingExpression> lst) Convenience method to calladdOutput(GroupingExpression)
for each element in the given list.boolean
containsHint
(String hint) Returns whether the given hint has been added to this.abstract GroupingOperation
copy
(GroupingOperation parentOfCopy) Returns a deep copy of thisstatic GroupingOperation
fromString
(String str) Convenience method to callfromStringAsList(String)
and assert that the list contains exactly one grouping operation.static List<GroupingOperation>
fromStringAsList
(String string) Parses the given string as a list of grouping operations.double
Return the accuracy of this.Returns the alias associated with the given name.protected Map<String,
GroupingExpression> Returns a direct, mutable copy of the aliases of this, never nullgetChild
(int i) Returns the child operation at the given index.Returns an immutable view to the child list of this node.boolean
Returns the expression assigned as the group-by clause of this.getHints()
Returns an immutable view to the hint list of this node.int
getLevel()
Returns the conceptual level of this node.static String
getLevelDesc
(int level) Returns a description of the given level.int
getMax()
Returns the max value of this.int
Returns the number of child operations of this.int
Returns the number of expressions in the order-by clause of this.int
Returns the number of expressions in the output clause of this.Returns an immutable view to the order-by clause of this.getOrderBy
(int i) Returns the group-by expression at the given index.getOutput
(int i) Returns the output expression at the given index.Returns an immutable view to the output clause of this.protected GroupingOperation
Returns the parent of this, or null if noneint
Returns the precision value of this.getWhere()
Returns the where clause assigned to this operation.boolean
hasMax()
Indicates if the 'max' value has been set.boolean
putAlias
(String id, GroupingExpression exp) Registers an alias with this operation.void
resolveLevel
(int level) Resolves the conceptual level of this operation.setAccuracy
(double accuracy) Assigns an accuracy value for this.setForceSinglePass
(boolean forceSinglePass) Assigns an expressions as the group-by clause of this operation.Assigns a label to this grouping expression.setMax
(int max) Sets the maximum number of groups to return for this operation.setPrecision
(int precision) Assigns the precision clause of this.Assigns a string as the where clause of this operation.toString()
void
visitExpressions
(ExpressionVisitor visitor) Recursively callsGroupingExpression.visit(ExpressionVisitor)
on allGroupingExpression
objects in this operation and in all of its child operations.Methods inherited from class com.yahoo.search.grouping.request.GroupingNode
getImage, getLabel
-
Field Details
-
UNLIMITED_MAX
public static final int UNLIMITED_MAX- See Also:
-
-
Constructor Details
-
GroupingOperation
-
GroupingOperation
protected GroupingOperation(GroupingOperation parentOfCopy, String image, String label, List<GroupingExpression> orderBy, List<GroupingExpression> outputs, List<GroupingOperation> children, Map<String, GroupingExpression> aliases, Set<String> hints, GroupingExpression groupBy, String where, boolean forceSinglePass, double accuracy, int precision, int level, int max)
-
-
Method Details
-
copy
Returns a deep copy of this -
putAlias
Registers an alias with this operation. An alias is made available to expressions in both this node and all child nodes.- Parameters:
id
- the id of the alias to putexp
- the expression to associate with the id- Returns:
- this, to allow chaining
-
getAlias
Returns the alias associated with the given name. If no alias can be found in this node, this method queries its parent grouping node. If the alias still can not be found, this method returns null.- Parameters:
id
- the id of the alias to return- Returns:
- the expression associated with the id
-
getAliases
Returns a direct, mutable copy of the aliases of this, never null -
addHint
Adds a hint to this. -
containsHint
Returns whether the given hint has been added to this. -
getHints
Returns an immutable view to the hint list of this node. -
addChild
Adds a child grouping node to this. This will also set the parent of the child so that it points to this node.- Parameters:
op
- the child node to add- Returns:
- this, to allow chaining
-
addChildren
Convenience method to calladdChild(GroupingOperation)
for each element in the given list.- Parameters:
lst
- the list of operations to add- Returns:
- this, to allow chaining
-
getNumChildren
public int getNumChildren()Returns the number of child operations of this. -
getChild
Returns the child operation at the given index.- Parameters:
i
- the index of the child to return- Returns:
- the child at the given index
- Throws:
IndexOutOfBoundsException
- if the index is out of range
-
getChildren
Returns an immutable view to the child list of this node. -
setGroupBy
Assigns an expressions as the group-by clause of this operation.- Parameters:
exp
- the expression to assign to this- Returns:
- this, to allow chaining
-
getGroupBy
Returns the expression assigned as the group-by clause of this. -
getLevel
public int getLevel()Returns the conceptual level of this node.- Returns:
- the level, or -1 if not resolved
- See Also:
-
resolveLevel
public void resolveLevel(int level) Resolves the conceptual level of this operation. This level represents the type of data that is consumed by this operation, where level 0 is a single hit, level 1 is a group, level 2 is a list of groups, and so forth. This method verifies the input level against the operation type, and recursively resolves the level of all argument expressions.- Parameters:
level
- the level of the input data- Throws:
IllegalArgumentException
- thrown if a contained expression is invalid for the given level
-
getParent
Returns the parent of this, or null if none -
setForceSinglePass
-
getForceSinglePass
public boolean getForceSinglePass() -
setMax
Sets the maximum number of groups to return for this operation. -
getMax
public int getMax()Returns the max value of this. -
hasMax
public boolean hasMax()Indicates if the 'max' value has been set. -
hasUnlimitedMax
public boolean hasUnlimitedMax() -
setAccuracy
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, at the sacrifice if a (possible) imprecise result.- Parameters:
accuracy
- the accuracy to assign to this- Returns:
- this, to allow chaining
- Throws:
IllegalArgumentException
- if the accuracy is outside the allowed value range
-
getAccuracy
public double getAccuracy()Return the accuracy of this. -
addOrderBy
Adds an expression to the order-by clause of this operation.- Parameters:
exp
- the expressions to add to this- Returns:
- this, to allow chaining
-
addOrderBy
Convenience method to calladdOrderBy(GroupingExpression)
for each element in the given list.- Parameters:
list
- the list of expressions to add- Returns:
- this, to allow chaining
-
getNumOrderBy
public int getNumOrderBy()Returns the number of expressions in the order-by clause of this.- Returns:
- the expression count
-
getOrderBy
Returns the group-by expression at the given index.- Parameters:
i
- the index of the expression to return- Returns:
- the expression at the given index
- Throws:
IndexOutOfBoundsException
- if the index is out of range
-
getOrderBy
Returns an immutable view to the order-by clause of this.- Returns:
- the expression list
-
addOutput
Adds an expression to the output clause of this operation.- Parameters:
exp
- the expressions to add to this- Returns:
- this, to allow chaining
-
addOutputs
Convenience method to calladdOutput(GroupingExpression)
for each element in the given list.- Parameters:
lst
- the list of expressions to add- Returns:
- this, to allow chaining
-
getNumOutputs
public int getNumOutputs()Returns the number of expressions in the output clause of this.- Returns:
- the expression count
-
getOutput
Returns the output expression at the given index.- Parameters:
i
- the index of the expression to return- Returns:
- the expression at the given index
- Throws:
IndexOutOfBoundsException
- If the index is out of range
-
getOutputs
Returns an immutable view to the output clause of this.- Returns:
- the expression list
-
setPrecision
Assigns the precision clause of this. This is the number of intermediate groups returned from each content node during expression evaluation to give the container node more data to consider when selecting the N groups that are to be evaluated further.- Parameters:
precision
- the precision to set- Returns:
- this, to allow chaining
- See Also:
-
getPrecision
public int getPrecision()Returns the precision value of this. -
setWhere
Assigns a string as the where clause of this operation.- Parameters:
string
- the string to assign to this- Returns:
- this, to allow chaining
-
getWhere
Returns the where clause assigned to this operation.- Returns:
- The where clause.
-
visitExpressions
Recursively callsGroupingExpression.visit(ExpressionVisitor)
on allGroupingExpression
objects in this operation and in all of its child operations.- Parameters:
visitor
- The visitor to call.
-
setLabel
Description copied from class:GroupingNode
Assigns a label to this grouping expression. The label is applied to the results of this expression so that they can be identified by the caller when processing the output.- Overrides:
setLabel
in classGroupingNode
- Parameters:
label
- The label to assign to this.- Returns:
- This, to allow chaining.
-
toString
- Overrides:
toString
in classGroupingNode
-
getLevelDesc
Returns a description of the given level. This allows for more descriptive errors being passed back to the user.- Parameters:
level
- The level to describe.- Returns:
- A description of the given level.
-
fromString
Convenience method to callfromStringAsList(String)
and assert that the list contains exactly one grouping operation.- Parameters:
str
- the string to parse- Returns:
- a grouping operation that corresponds to the string
- Throws:
IllegalArgumentException
- thrown if the string could not be parsed as a single operation
-
fromStringAsList
Parses the given string as a list of grouping operations. This method never returns null, it either returns a list of valid grouping requests or it throws an exception.- Parameters:
string
- the string to parse- Returns:
- a list of grouping operations that corresponds to the string
- Throws:
IllegalArgumentException
- thrown if the string could not be parsed
-