Class GroupingOperation

java.lang.Object
com.yahoo.search.grouping.request.GroupingNode
com.yahoo.search.grouping.request.GroupingOperation
Direct Known Subclasses:
AllOperation, EachOperation

public abstract class GroupingOperation extends GroupingNode
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 Details

  • Constructor Details

  • Method Details

    • copy

      public abstract GroupingOperation copy(GroupingOperation parentOfCopy)
      Returns a deep copy of this
    • putAlias

      public GroupingOperation putAlias(String id, GroupingExpression exp)
      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 put
      exp - the expression to associate with the id
      Returns:
      this, to allow chaining
    • getAlias

      public GroupingExpression getAlias(String id)
      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

      protected Map<String,GroupingExpression> getAliases()
      Returns a direct, mutable copy of the aliases of this, never null
    • addHint

      public GroupingOperation addHint(String hint)
      Adds a hint to this.
    • containsHint

      public boolean containsHint(String hint)
      Returns whether the given hint has been added to this.
    • getHints

      public Set<String> getHints()
      Returns an immutable view to the hint list of this node.
    • addChild

      public GroupingOperation addChild(GroupingOperation op)
      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

      public GroupingOperation addChildren(List<GroupingOperation> lst)
      Convenience method to call addChild(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

      public GroupingOperation getChild(int i)
      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

      public List<GroupingOperation> getChildren()
      Returns an immutable view to the child list of this node.
    • setGroupBy

      public GroupingOperation setGroupBy(GroupingExpression exp)
      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

      public GroupingExpression 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

      protected GroupingOperation getParent()
      Returns the parent of this, or null if none
    • setForceSinglePass

      public GroupingOperation setForceSinglePass(boolean forceSinglePass)
    • getForceSinglePass

      public boolean getForceSinglePass()
    • setMax

      public GroupingOperation setMax(int max)
      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

      public GroupingOperation setAccuracy(double accuracy)
      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

      public GroupingOperation addOrderBy(GroupingExpression exp)
      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

      public GroupingOperation addOrderBy(List<GroupingExpression> list)
      Convenience method to call addOrderBy(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

      public GroupingExpression getOrderBy(int i)
      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

      public List<GroupingExpression> getOrderBy()
      Returns an immutable view to the order-by clause of this.
      Returns:
      the expression list
    • addOutput

      public GroupingOperation addOutput(GroupingExpression exp)
      Adds an expression to the output clause of this operation.
      Parameters:
      exp - the expressions to add to this
      Returns:
      this, to allow chaining
    • addOutputs

      public GroupingOperation addOutputs(List<GroupingExpression> lst)
      Convenience method to call addOutput(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

      public GroupingExpression getOutput(int i)
      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

      public List<GroupingExpression> getOutputs()
      Returns an immutable view to the output clause of this.
      Returns:
      the expression list
    • setPrecision

      public GroupingOperation setPrecision(int precision)
      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

      public GroupingOperation setWhere(String string)
      Assigns a string as the where clause of this operation.
      Parameters:
      string - the string to assign to this
      Returns:
      this, to allow chaining
    • getWhere

      public String getWhere()
      Returns the where clause assigned to this operation.
      Returns:
      The where clause.
    • visitExpressions

      public void visitExpressions(ExpressionVisitor visitor)
      Recursively calls GroupingExpression.visit(ExpressionVisitor) on all GroupingExpression objects in this operation and in all of its child operations.
      Parameters:
      visitor - The visitor to call.
    • setLabel

      public GroupingOperation setLabel(String label)
      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 class GroupingNode
      Parameters:
      label - The label to assign to this.
      Returns:
      This, to allow chaining.
    • toString

      public String toString()
      Overrides:
      toString in class GroupingNode
    • getLevelDesc

      public static String getLevelDesc(int level)
      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

      public static GroupingOperation fromString(String str)
      Convenience method to call fromStringAsList(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

      public static List<GroupingOperation> fromStringAsList(String string)
      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