org.apache.lucene.search

## Class TermAutomatonQuery

- java.lang.Object
- - org.apache.lucene.search.Query
  - - org.apache.lucene.search.TermAutomatonQuery

-     public class TermAutomatonQuery
      extends Query

  A proximity query that lets you express an automaton, whose transitions are terms, to match documents. This is a generalization of other proximity queries like `PhraseQuery`, `MultiPhraseQuery` and `SpanNearQuery`. It is likely slow, since it visits any document having any of the terms (i.e. it acts like a disjunction, not a conjunction like `PhraseQuery`), and then it must merge-sort all positions within each document to test whether/how many times the automaton matches.

  After creating the query, use `createState()`, `setAccept(int, boolean)`, `addTransition(int, int, java.lang.String)` and `addAnyTransition(int, int)` to build up the automaton. Once you are done, call `finish()` and then execute the query.

  This code is very new and likely has exciting bugs!

  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TermAutomatonQuery(String field)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addAnyTransition(int source, int dest)` Adds a transition matching any term.
    `void` | `addTransition(int source, int dest, BytesRef term)` Adds a transition to the automaton.
    `void` | `addTransition(int source, int dest, String term)` Adds a transition to the automaton.
    `int` | `createState()` Returns a new state; state 0 is always the initial state.
    `Weight` | `createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)`
    `boolean` | `equals(Object other)` Returns true iff `o` is equal to this.
    `void` | `finish()` Call this once you are done adding states/transitions.
    `void` | `finish(int maxDeterminizedStates)` Call this once you are done adding states/transitions.
    `int` | `hashCode()`
    `Query` | `rewrite(IndexReader reader)`
    `void` | `setAccept(int state, boolean accept)` Marks the specified state as accept or not.
    `String` | `toDot()` Returns the dot (graphviz) representation of this automaton.
    `String` | `toString(String field)`
    `void` | `visit(QueryVisitor visitor)`

    - ### Methods inherited from class org.apache.lucene.search.Query

      `classHash, sameClassAs, toString`

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### TermAutomatonQuery

          public TermAutomatonQuery(String field)

  - ### Method Detail

    - #### createState

          public int createState()

      Returns a new state; state 0 is always the initial state.

    - #### setAccept

          public void setAccept(int state,
                                boolean accept)

      Marks the specified state as accept or not.

    - #### addTransition

          public void addTransition(int source,
                                    int dest,
                                    String term)

      Adds a transition to the automaton.

    - #### addTransition

          public void addTransition(int source,
                                    int dest,
                                    BytesRef term)

      Adds a transition to the automaton.

    - #### addAnyTransition

          public void addAnyTransition(int source,
                                       int dest)

      Adds a transition matching any term.

    - #### finish

          public void finish()

      Call this once you are done adding states/transitions.

    - #### finish

          public void finish(int maxDeterminizedStates)

      Call this once you are done adding states/transitions.
      Parameters:
        `maxDeterminizedStates` - Maximum number of states created when determinizing the automaton. Higher numbers allow this operation to consume more memory but allow more complex automatons.

    - #### createWeight

          public Weight createWeight(IndexSearcher searcher,
                                     ScoreMode scoreMode,
                                     float boost)
                              throws IOException

      Overrides:
        `createWeight` in class `Query`
      Throws:
        `IOException`

    - #### toString

          public String toString(String field)

      Specified by:
        `toString` in class `Query`

    - #### equals

          public boolean equals(Object other)

      Returns true iff `o` is equal to this.
      Specified by:
        `equals` in class `Query`

    - #### hashCode

          public int hashCode()

      Specified by:
        `hashCode` in class `Query`

    - #### toDot

          public String toDot()

      Returns the dot (graphviz) representation of this automaton. This is extremely useful for visualizing the automaton.

    - #### rewrite

          public Query rewrite(IndexReader reader)
                        throws IOException

      Overrides:
        `rewrite` in class `Query`
      Throws:
        `IOException`

    - #### visit

          public void visit(QueryVisitor visitor)

      Overrides:
        `visit` in class `Query`

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