Class AutomatonQuery

  extended by
      extended by
          extended by
All Implemented Interfaces:
Direct Known Subclasses:
RegexpQuery, WildcardQuery

public class AutomatonQuery
extends MultiTermQuery

A Query that will match terms against a finite-state machine.

This query will match documents that contain terms accepted by a given finite-state machine. The automaton can be constructed with the org.apache.lucene.util.automaton API. Alternatively, it can be created from a regular expression with RegexpQuery or from the standard Lucene wildcard syntax with WildcardQuery.

When the query is executed, it will create an equivalent DFA of the finite-state machine, and will enumerate the term dictionary in an intelligent way to reduce the number of comparisons. For example: the regular expression of [dl]og? will make approximately four comparisons: do, dog, lo, and log.

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

Nested Class Summary
Nested classes/interfaces inherited from class
MultiTermQuery.ConstantScoreAutoRewrite, MultiTermQuery.RewriteMethod, MultiTermQuery.TopTermsBoostOnlyBooleanQueryRewrite, MultiTermQuery.TopTermsScoringBooleanQueryRewrite
Field Summary
protected  Automaton automaton
          the automaton to match index terms against
protected  CompiledAutomaton compiled
protected  Term term
          term containing the field, and possibly some pattern structure
Fields inherited from class
Constructor Summary
AutomatonQuery(Term term, Automaton automaton)
          Create a new AutomatonQuery from an Automaton.
Method Summary
 boolean equals(Object obj)
protected  TermsEnum getTermsEnum(Terms terms, AttributeSource atts)
          Construct the enumeration to be used, expanding the pattern term.
 int hashCode()
 String toString(String field)
          Prints a query to a string, with field assumed to be the default field and omitted.
Methods inherited from class
getField, getRewriteMethod, getTermsEnum, rewrite, setRewriteMethod
Methods inherited from class
clone, createWeight, extractTerms, getBoost, setBoost, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait

Field Detail


protected final Automaton automaton
the automaton to match index terms against


protected final CompiledAutomaton compiled


protected final Term term
term containing the field, and possibly some pattern structure

Constructor Detail


public AutomatonQuery(Term term,
                      Automaton automaton)
Create a new AutomatonQuery from an Automaton.

term - Term containing field and possibly some pattern structure. The term text is ignored.
automaton - Automaton to run, terms that are accepted are considered a match.
Method Detail


protected TermsEnum getTermsEnum(Terms terms,
                                 AttributeSource atts)
                          throws IOException
Description copied from class: MultiTermQuery
Construct the enumeration to be used, expanding the pattern term. This method should only be called if the field exists (ie, implementations can assume the field does exist). This method should not return null (should instead return TermsEnum.EMPTY if no terms match). The TermsEnum must already be positioned to the first matching term. The given AttributeSource is passed by the MultiTermQuery.RewriteMethod to provide attributes, the rewrite method uses to inform about e.g. maximum competitive boosts. This is currently only used by TopTermsRewrite

Specified by:
getTermsEnum in class MultiTermQuery


public int hashCode()
hashCode in class MultiTermQuery


public boolean equals(Object obj)
equals in class MultiTermQuery


public String toString(String field)
Description copied from class: Query
Prints a query to a string, with field assumed to be the default field and omitted.

Specified by:
toString in class Query

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