Class QueryBuilder


  • public class QueryBuilder
    extends java.lang.Object
    Created by mnunberg on 2/23/18. This class contains methods to construct query nodes. These query nodes can be added to parent query nodes (building a chain) or used as the root query node. You can use
     import static
     
    for these helper methods.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static QueryNode disjunct​(Node... n)
      Create a disjunct node.
      static QueryNode disjunct​(java.lang.String field, Value... values)
      Create a disjunct node using one or more values.
      static QueryNode disjunct​(java.lang.String field, java.lang.String... values)
      Create a disjunct node using one or more values.
      static QueryNode disjunctUnion​(Node... n)
      Create a disjunct union node.
      static QueryNode disjunctUnion​(java.lang.String field, Value... values)  
      static QueryNode disjunctUnion​(java.lang.String field, java.lang.String... values)  
      static QueryNode intersect​(Node... n)
      Create a new intersection node with child nodes.
      static QueryNode intersect​(java.lang.String field, Value... values)
      Create a new intersection node with a field-value pair.
      static QueryNode intersect​(java.lang.String field, java.lang.String stringValue)
      Helper method to create a new intersection node with a string value.
      static QueryNode optional​(Node... n)
      Create an optional node.
      static QueryNode optional​(java.lang.String field, Value... values)  
      static QueryNode union​(Node... n)
      Create a union node.
      static QueryNode union​(java.lang.String field, Value... values)
      Create a union node which can match an one or more values
      static QueryNode union​(java.lang.String field, java.lang.String... values)
      Convenience method to match one or more strings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • intersect

        public static QueryNode intersect​(Node... n)
        Create a new intersection node with child nodes. An intersection node is true if all its children are also true
        Parameters:
        n - sub-condition to add
        Returns:
        The node
      • intersect

        public static QueryNode intersect​(java.lang.String field,
                                          Value... values)
        Create a new intersection node with a field-value pair.
        Parameters:
        field - The field that should contain this value. If this value is empty, then any field will be checked.
        values - Value to check for. The node will be true only if the field (or any field) contains all of the values
        Returns:
        The node
      • intersect

        public static QueryNode intersect​(java.lang.String field,
                                          java.lang.String stringValue)
        Helper method to create a new intersection node with a string value.
        Parameters:
        field - The field to check. If left null or empty, all fields will be checked.
        stringValue - The value to check
        Returns:
        The node
      • union

        public static QueryNode union​(Node... n)
        Create a union node. Union nodes evaluate to true if any of its children are true
        Parameters:
        n - Child node
        Returns:
        The union node
      • union

        public static QueryNode union​(java.lang.String field,
                                      Value... values)
        Create a union node which can match an one or more values
        Parameters:
        field - Field to check. If empty, all fields are checked
        values - Values to search for. The node evaluates to true if field matches any of the values
        Returns:
        The union node
      • union

        public static QueryNode union​(java.lang.String field,
                                      java.lang.String... values)
        Convenience method to match one or more strings. This is equivalent to union(field, value(v1), value(v2), value(v3)) ...
        Parameters:
        field - Field to match
        values - Strings to check for
        Returns:
        The union node
      • disjunct

        public static QueryNode disjunct​(Node... n)
        Create a disjunct node. Disjunct nodes are true iff any of its children are not true. Conversely, this node evaluates to false if all its children are true.
        Parameters:
        n - Child nodes to add
        Returns:
        The disjunct node
      • disjunct

        public static QueryNode disjunct​(java.lang.String field,
                                         Value... values)
        Create a disjunct node using one or more values. The node will evaluate to true iff the field does not match any of the values.
        Parameters:
        field - Field to check for (empty or null for any field)
        values - The values to check for
        Returns:
        The node
      • disjunct

        public static QueryNode disjunct​(java.lang.String field,
                                         java.lang.String... values)
        Create a disjunct node using one or more values. The node will evaluate to true iff the field does not match any of the values.
        Parameters:
        field - Field to check for (empty or null for any field)
        values - The values to check for
        Returns:
        The node
      • disjunctUnion

        public static QueryNode disjunctUnion​(Node... n)
        Create a disjunct union node. This node evaluates to true if all of its children are not true. Conversely, this node evaluates as false if any of its children are true.
        Parameters:
        n -
        Returns:
        The node
      • disjunctUnion

        public static QueryNode disjunctUnion​(java.lang.String field,
                                              Value... values)
      • disjunctUnion

        public static QueryNode disjunctUnion​(java.lang.String field,
                                              java.lang.String... values)
      • optional

        public static QueryNode optional​(Node... n)
        Create an optional node. Optional nodes do not affect which results are returned but they influence ordering and scoring.
        Parameters:
        n - The node to evaluate as optional
        Returns:
        The new node
      • optional

        public static QueryNode optional​(java.lang.String field,
                                         Value... values)