Package org.apache.lucene.search
Class TermAutomatonQuery
- java.lang.Object
-
- org.apache.lucene.search.Query
-
- org.apache.lucene.search.TermAutomatonQuery
-
- All Implemented Interfaces:
Accountable
public class TermAutomatonQuery extends Query implements Accountable
A proximity query that lets you express an automaton, whose transitions are terms, to match documents. This is a generalization of other proximity queries likePhraseQuery,MultiPhraseQueryandSpanNearQuery. It is likely slow, since it visits any document having any of the terms (i.e. it acts like a disjunction, not a conjunction likePhraseQuery), 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)andaddAnyTransition(int, int)to build up the automaton. Once you are done, callfinish()and then execute the query.This code is very new and likely has exciting bugs!
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classTermAutomatonQuery.EnumAndScorer(package private) classTermAutomatonQuery.TermAutomatonWeight
-
Field Summary
Fields Modifier and Type Field Description private intanyTermIDprivate static longBASE_RAM_BYTESprivate Automaton.Builderbuilder(package private) Automatondetprivate java.lang.Stringfieldprivate java.util.Map<java.lang.Integer,BytesRef>idToTermprivate java.util.Map<BytesRef,java.lang.Integer>termToID-
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE
-
-
Constructor Summary
Constructors Constructor Description TermAutomatonQuery(java.lang.String field)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAnyTransition(int source, int dest)Adds a transition matching any term.voidaddTransition(int source, int dest, java.lang.String term)Adds a transition to the automaton.voidaddTransition(int source, int dest, BytesRef term)Adds a transition to the automaton.private static booleancheckFinished(TermAutomatonQuery q)intcreateState()Returns a new state; state 0 is always the initial state.WeightcreateWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)Expert: Constructs an appropriate Weight implementation for this query.booleanequals(java.lang.Object other)Returns true iffois equal to this.private booleanequalsTo(TermAutomatonQuery other)voidfinish()Call this once you are done adding states/transitions.voidfinish(int maxDeterminizedStates)Call this once you are done adding states/transitions.private intgetTermID(BytesRef term)inthashCode()Override and implement query hash code properly in a subclass.longramBytesUsed()Return the memory usage of this object in bytes.Queryrewrite(IndexReader reader)Expert: called to re-write queries into primitive queries.voidsetAccept(int state, boolean accept)Marks the specified state as accept or not.java.lang.StringtoDot()Returns the dot (graphviz) representation of this automaton.java.lang.StringtoString(java.lang.String field)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, sameClassAs, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
-
-
-
Field Detail
-
BASE_RAM_BYTES
private static final long BASE_RAM_BYTES
-
field
private final java.lang.String field
-
builder
private final Automaton.Builder builder
-
det
Automaton det
-
termToID
private final java.util.Map<BytesRef,java.lang.Integer> termToID
-
idToTerm
private final java.util.Map<java.lang.Integer,BytesRef> idToTerm
-
anyTermID
private int anyTermID
-
-
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, java.lang.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 java.io.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 classQueryscoreMode- How the produced scorers will be consumed.boost- The boost that is propagated by the parent queries.- Throws:
java.io.IOException
-
toString
public java.lang.String toString(java.lang.String field)
Description copied from class:QueryPrints a query to a string, withfieldassumed to be the default field and omitted.
-
getTermID
private int getTermID(BytesRef term)
-
equals
public boolean equals(java.lang.Object other)
Returns true iffois equal to this.- Specified by:
equalsin classQuery- See Also:
Query.sameClassAs(Object),Query.classHash()
-
checkFinished
private static boolean checkFinished(TermAutomatonQuery q)
-
equalsTo
private boolean equalsTo(TermAutomatonQuery other)
-
hashCode
public int hashCode()
Description copied from class:QueryOverride and implement query hash code properly in a subclass. This is required so thatQueryCacheworks properly.- Specified by:
hashCodein classQuery- See Also:
Query.equals(Object)
-
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
public java.lang.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 java.io.IOException
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.
-
visit
public void visit(QueryVisitor visitor)
Description copied from class:QueryRecurse through the query tree, visiting any child queries
-
-