Package org.apache.lucene.search
Class AutomatonQuery
java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.MultiTermQuery
org.apache.lucene.search.AutomatonQuery
- All Implemented Interfaces:
Accountable
- Direct Known Subclasses:
PrefixQuery,RegexpQuery,TermRangeQuery,WildcardQuery
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.search.MultiTermQuery
MultiTermQuery.RewriteMethod, MultiTermQuery.TopTermsBlendedFreqScoringRewrite, MultiTermQuery.TopTermsBoostOnlyBooleanQueryRewrite, MultiTermQuery.TopTermsScoringBooleanQueryRewrite -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Automatonthe automaton to match index terms againstprotected final booleanprivate static final longprotected final CompiledAutomatonprivate final longprotected final Termterm containing the field, and possibly some pattern structureFields inherited from class org.apache.lucene.search.MultiTermQuery
CONSTANT_SCORE_BOOLEAN_REWRITE, CONSTANT_SCORE_REWRITE, field, rewriteMethod, SCORING_BOOLEAN_REWRITEFields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Constructor Summary
ConstructorsConstructorDescriptionAutomatonQuery(Term term, Automaton automaton) Create a new AutomatonQuery from anAutomaton.AutomatonQuery(Term term, Automaton automaton, int maxDeterminizedStates) Create a new AutomatonQuery from anAutomaton.AutomatonQuery(Term term, Automaton automaton, int maxDeterminizedStates, boolean isBinary) Create a new AutomatonQuery from anAutomaton. -
Method Summary
Modifier and TypeMethodDescriptionbooleanOverride and implement query instance equivalence properly in a subclass.Returns the automaton used to create this queryprotected TermsEnumgetTermsEnum(Terms terms, AttributeSource atts) Construct the enumeration to be used, expanding the pattern term.inthashCode()Override and implement query hash code properly in a subclass.booleanIs this a binary (byte) oriented automaton.longReturn the memory usage of this object in bytes.Prints a query to a string, withfieldassumed to be the default field and omitted.voidvisit(QueryVisitor visitor) Recurse through the query tree, visiting any child queriesMethods inherited from class org.apache.lucene.search.MultiTermQuery
getField, getRewriteMethod, getTermsEnum, rewrite, setRewriteMethodMethods inherited from class org.apache.lucene.search.Query
classHash, createWeight, sameClassAs, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
Field Details
-
BASE_RAM_BYTES
private static final long BASE_RAM_BYTES -
automaton
the automaton to match index terms against -
compiled
-
term
term containing the field, and possibly some pattern structure -
automatonIsBinary
protected final boolean automatonIsBinary -
ramBytesUsed
private final long ramBytesUsed
-
-
Constructor Details
-
AutomatonQuery
Create a new AutomatonQuery from anAutomaton.- Parameters:
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.
-
AutomatonQuery
Create a new AutomatonQuery from anAutomaton.- Parameters:
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.maxDeterminizedStates- maximum number of states in the resulting automata. If the automata would need more than this many states TooComplextToDeterminizeException is thrown. Higher number require more space but can process more complex automata.
-
AutomatonQuery
Create a new AutomatonQuery from anAutomaton.- Parameters:
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.maxDeterminizedStates- maximum number of states in the resulting automata. If the automata would need more than this many states TooComplextToDeterminizeException is thrown. Higher number require more space but can process more complex automata.isBinary- if true, this automaton is already binary and will not go through the UTF32ToUTF8 conversion
-
-
Method Details
-
getTermsEnum
Description copied from class:MultiTermQueryConstruct 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 returnTermsEnum.EMPTYif no terms match). The TermsEnum must already be positioned to the first matching term. The givenAttributeSourceis passed by theMultiTermQuery.RewriteMethodto share information between segments, for exampleTopTermsRewriteuses it to share maximum competitive boosts- Specified by:
getTermsEnumin classMultiTermQuery- Throws:
IOException
-
hashCode
public int hashCode()Description copied from class:QueryOverride and implement query hash code properly in a subclass. This is required so thatQueryCacheworks properly.- Overrides:
hashCodein classMultiTermQuery- See Also:
-
equals
Description copied from class:QueryOverride and implement query instance equivalence properly in a subclass. This is required so thatQueryCacheworks properly. Typically a query will be equal to another only if it's an instance of the same class and its document-filtering properties are identical that other instance. Utility methods are provided for certain repetitive code.- Overrides:
equalsin classMultiTermQuery- See Also:
-
toString
Description copied from class:QueryPrints a query to a string, withfieldassumed to be the default field and omitted. -
visit
Description copied from class:QueryRecurse through the query tree, visiting any child queries -
getAutomaton
Returns the automaton used to create this query -
isAutomatonBinary
public boolean isAutomatonBinary()Is this a binary (byte) oriented automaton. See the constructor. -
ramBytesUsed
public long ramBytesUsed()Description copied from interface:AccountableReturn the memory usage of this object in bytes. Negative values are illegal.- Specified by:
ramBytesUsedin interfaceAccountable
-