Class QueryTree


  • public abstract class QueryTree
    extends Object
    A representation of a node in a query tree

    Queries are analyzed and converted into an abstract tree, consisting of conjunction and disjunction nodes, and leaf nodes containing terms.

    Terms may be collected from a node, which will use the weights of its sub-nodes to determine which paths are followed. The path may be changed by calling advancePhase(double)

    • Constructor Detail

      • QueryTree

        public QueryTree()
    • Method Detail

      • weight

        public abstract double weight()
        The weight of this node
      • collectTerms

        public abstract void collectTerms​(BiConsumer<String,​BytesRef> termCollector)
        Collect terms from the most highly-weighted path below this node
      • advancePhase

        public abstract boolean advancePhase​(double minWeight)
        Find the next-most highly-weighted path below this node
        Parameters:
        minWeight - do not advance if the next path has a weight below this value
        Returns:
        false if there are no more paths above the minimum weight
      • toString

        public abstract String toString​(int depth)
        Returns a string representation of the node
        Parameters:
        depth - the current depth of this node in the overall query tree
      • space

        protected String space​(int width)
        Returns a string of width spaces
      • term

        public static QueryTree term​(Term term,
                                     double weight)
        Returns a leaf node for a particular term and weight

        The weight must be greater than 0

      • term

        public static QueryTree term​(String field,
                                     BytesRef term,
                                     double weight)
        Returns a leaf node for a particular term and weight

        The weight must be greater than 0

      • anyTerm

        public static QueryTree anyTerm​(String reason)
        Returns a leaf node that will match any document