QueryTreeBuilder (Lucene 10.5.1 queryparser API)
Description: declaration: package: org.apache.lucene.queryparser.flexible.core.builders, class: QueryTreeBuilder

Package org.apache.lucene.queryparser.flexible.core.builders

# Class QueryTreeBuilder

java.lang.Object
org.apache.lucene.queryparser.flexible.core.builders.QueryTreeBuilder

All Implemented Interfaces:
  `QueryBuilder`

Direct Known Subclasses:
  `StandardQueryTreeBuilder`

public class QueryTreeBuilder extends Object implements QueryBuilder
This class should be used when there is a builder for each type of node.

The type of node may be defined in 2 different ways: - by the field name, when the node implements the `FieldableNode` interface - by its class, it keeps checking the class and all the interfaces and classes this class implements/extends until it finds a builder for that class/interface

This class always check if there is a builder for the field name before it checks for the node class. So, field name builders have precedence over class builders.

When a builder is found for a node, it's called and the node is passed to the builder. If the returned built object is not `null`, it's tagged on the node using the tag `QUERY_TREE_BUILDER_TAGID`.

The children are usually built before the parent node. However, if a builder associated to a node is an instance of `QueryTreeBuilder`, the node is delegated to this builder and it's responsible to build the node and its children.

See Also:
  - `QueryBuilder`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `QUERY_TREE_BUILDER_TAGID`
  This tag is used to tag the nodes in a query tree with the built objects produced from their own associated builder.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `QueryTreeBuilder()`
  `QueryTreeBuilder` constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `build(QueryNode queryNode)`
  Builds some kind of object from a query tree.
  `void`
  `setBuilder(CharSequence fieldName, QueryBuilder builder)`
  Associates a field name with a builder.
  `void`
  `setBuilder(Class<? extends QueryNode> queryNodeClass, QueryBuilder builder)`
  Associates a class with a builder

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### QUERY_TREE_BUILDER_TAGID

    public static final String QUERY_TREE_BUILDER_TAGID
    This tag is used to tag the nodes in a query tree with the built objects produced from their own associated builder.

- ## Constructor Details

  - ### QueryTreeBuilder

    public QueryTreeBuilder()
    `QueryTreeBuilder` constructor.

- ## Method Details

  - ### setBuilder

    public void setBuilder(CharSequence fieldName, QueryBuilder builder)
    Associates a field name with a builder.
    Parameters:
      `fieldName` - the field name
      `builder` - the builder to be associated

  - ### setBuilder

    public void setBuilder(Class<? extends QueryNode> queryNodeClass, QueryBuilder builder)
    Associates a class with a builder
    Parameters:
      `queryNodeClass` - the class
      `builder` - the builder to be associated

  - ### build

    public Object build(QueryNode queryNode) throws QueryNodeException
    Builds some kind of object from a query tree. Each node in the query tree is built using an specific builder associated to it.
    Specified by:
      `build` in interface `QueryBuilder`
    Parameters:
      `queryNode` - the query tree root node
    Returns:
      the built object
    Throws:
      `QueryNodeException` - if some node builder throws a `QueryNodeException` or if there is a node which had no builder associated to it