org.apache.lucene.search

## Class QueryVisitor

- java.lang.Object
- - org.apache.lucene.search.QueryVisitor

-     public abstract class QueryVisitor
      extends Object

  Allows recursion through a query tree
  See Also:
    `Query.visit(QueryVisitor)`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static QueryVisitor` | `EMPTY_VISITOR` A QueryVisitor implementation that does nothing

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `QueryVisitor()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `acceptField(String field)` Whether or not terms from this field are of interest to the visitor Implement this to avoid collecting terms from heavy queries such as `TermInSetQuery` that are not running on fields of interest
    `void` | `consumeTerms(Query query, Term... terms)` Called by leaf queries that match on specific terms
    `void` | `consumeTermsMatching(Query query, String field, Supplier<ByteRunAutomaton> automaton)` Called by leaf queries that match on a class of terms
    `QueryVisitor` | `getSubVisitor(BooleanClause.Occur occur, Query parent)` Pulls a visitor instance for visiting child clauses of a query The default implementation returns `this`, unless `occur` is equal to `BooleanClause.Occur.MUST_NOT` in which case it returns `EMPTY_VISITOR`
    `static QueryVisitor` | `termCollector(Set<Term> termSet)` Builds a `QueryVisitor` instance that collects all terms that may match a query
    `void` | `visitLeaf(Query query)` Called by leaf queries that do not match on terms

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

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

- - ### Field Detail

    - #### EMPTY_VISITOR

          public static final QueryVisitor EMPTY_VISITOR

      A QueryVisitor implementation that does nothing

  - ### Constructor Detail

    - #### QueryVisitor

          public QueryVisitor()

  - ### Method Detail

    - #### consumeTerms

          public void consumeTerms(Query query,
                                   Term... terms)

      Called by leaf queries that match on specific terms
      Parameters:
        `query` - the leaf query
        `terms` - the terms the query will match on

    - #### consumeTermsMatching

          public void consumeTermsMatching(Query query,
                                           String field,
                                           Supplier<ByteRunAutomaton> automaton)

      Called by leaf queries that match on a class of terms
      Parameters:
        `query` - the leaf query
        `field` - the field queried against
        `automaton` - a supplier for an automaton defining which terms match
      WARNING: This API is experimental and might change in incompatible ways in the next release.

    - #### visitLeaf

          public void visitLeaf(Query query)

      Called by leaf queries that do not match on terms
      Parameters:
        `query` - the query

    - #### acceptField

          public boolean acceptField(String field)

      Whether or not terms from this field are of interest to the visitor Implement this to avoid collecting terms from heavy queries such as `TermInSetQuery` that are not running on fields of interest

    - #### getSubVisitor

          public QueryVisitor getSubVisitor(BooleanClause.Occur occur,
                                            Query parent)

      Pulls a visitor instance for visiting child clauses of a query The default implementation returns `this`, unless `occur` is equal to `BooleanClause.Occur.MUST_NOT` in which case it returns `EMPTY_VISITOR`
      Parameters:
        `occur` - the relationship between the parent and its children
        `parent` - the query visited

    - #### termCollector

          public static QueryVisitor termCollector(Set<Term> termSet)

      Builds a `QueryVisitor` instance that collects all terms that may match a query
      Parameters:
        `termSet` - a `Set` to add collected terms to

Copyright © 2000-2024 Apache Software Foundation. All Rights Reserved.