- All Implemented Interfaces:
Accountable
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!
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class(package private) final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate static final longprivate final Automaton.Builder(package private) Automatonprivate final Stringprivate final IntObjectHashMap<BytesRef> Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnyTransition(int source, int dest) Adds a transition matching any term.voidaddTransition(int source, int dest, String term) Adds a transition to the automaton.voidaddTransition(int source, int dest, BytesRef term) Adds a transition to the automaton.private static booleanintReturns a new state; state 0 is always the initial state.createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) Expert: Constructs an appropriate Weight implementation for this query.booleanReturns true iffois equal to this.private booleanequalsTo(TermAutomatonQuery other) voidfinish()Call this once you are done adding states/transitions.voidfinish(int determinizeWorkLimit) Call this once you are done adding states/transitions.private intinthashCode()Override and implement query hash code properly in a subclass.longReturn the memory usage of this object in bytes.rewrite(IndexSearcher indexSearcher) Expert: called to re-write queries into primitive queries.voidsetAccept(int state, boolean accept) Marks the specified state as accept or not.toDot()Returns the dot (graphviz) representation of this automaton.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 queries.Methods inherited from class org.apache.lucene.search.Query
classHash, rewrite, 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 -
field
-
builder
-
det
Automaton det -
termToID
-
idToTerm
-
anyTermID
private int anyTermID
-
-
Constructor Details
-
TermAutomatonQuery
-
-
Method Details
-
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
Adds a transition to the automaton. -
addTransition
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 determinizeWorkLimit) Call this once you are done adding states/transitions.- Parameters:
determinizeWorkLimit- Maximum effort to spend determinizing the automaton. Higher numbers allow this operation to consume more memory but allow more complex automatons. UseOperations.DEFAULT_DETERMINIZE_WORK_LIMITas a decent default if you don't otherwise know what to specify.
-
createWeight
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException Description copied from class:QueryExpert: Constructs an appropriate Weight implementation for this query.Only implemented by primitive queries, which re-write to themselves.
- Overrides:
createWeightin classQuery- Parameters:
scoreMode- How the produced scorers will be consumed.boost- The boost that is propagated by the parent queries.- Throws:
IOException
-
toString
Description copied from class:QueryPrints a query to a string, withfieldassumed to be the default field and omitted. -
getTermID
-
equals
Returns true iffois equal to this. -
checkFinished
-
equalsTo
-
hashCode
public int hashCode()Description copied from class:QueryOverride and implement query hash code properly in a subclass. This is required so thatQueryCacheworks properly. -
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
-
toDot
Returns the dot (graphviz) representation of this automaton. This is extremely useful for visualizing the automaton. -
rewrite
Description copied from class:QueryExpert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.Callers are expected to call
rewritemultiple times if necessary, until the rewritten query is the same as the original query.The rewrite process may be able to make use of IndexSearcher's executor and be executed in parallel if the executor is provided.
However, if any of the intermediary queries do not satisfy the new API, parallel rewrite is not possible for any subsequent sub-queries. To take advantage of this API, the entire query tree must override this method.
- Overrides:
rewritein classQuery- Throws:
IOException- See Also:
-
visit
Description copied from class:QueryRecurse through the query tree, visiting any child queries.
-