public class TermAutomatonQuery extends Query
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!
Modifier and Type | Class and Description |
---|---|
(package private) static class |
TermAutomatonQuery.EnumAndScorer |
(package private) class |
TermAutomatonQuery.TermAutomatonWeight |
Modifier and Type | Field and Description |
---|---|
private int |
anyTermID |
private Automaton.Builder |
builder |
(package private) Automaton |
det |
private java.lang.String |
field |
private java.util.Map<java.lang.Integer,BytesRef> |
idToTerm |
private java.util.Map<BytesRef,java.lang.Integer> |
termToID |
Constructor and Description |
---|
TermAutomatonQuery(java.lang.String field) |
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,
java.lang.String term)
Adds a transition to the automaton.
|
private static boolean |
checkFinished(TermAutomatonQuery q) |
int |
createState()
Returns a new state; state 0 is always the initial state.
|
Weight |
createWeight(IndexSearcher searcher,
ScoreMode scoreMode,
float boost)
Expert: Constructs an appropriate Weight implementation for this query.
|
boolean |
equals(java.lang.Object other)
Returns true iff
o is equal to this. |
private boolean |
equalsTo(TermAutomatonQuery other) |
void |
finish()
Call this once you are done adding states/transitions.
|
void |
finish(int maxDeterminizedStates)
Call this once you are done adding states/transitions.
|
private int |
getTermID(BytesRef term) |
int |
hashCode()
Override and implement query hash code properly in a subclass.
|
Query |
rewrite(IndexReader reader)
Expert: called to re-write queries into primitive queries.
|
void |
setAccept(int state,
boolean accept)
Marks the specified state as accept or not.
|
java.lang.String |
toDot()
Returns the dot (graphviz) representation of this automaton.
|
java.lang.String |
toString(java.lang.String field)
Prints a query to a string, with
field assumed to be the
default field and omitted. |
void |
visit(QueryVisitor visitor)
Recurse through the query tree, visiting any child queries
|
classHash, sameClassAs, toString
private final java.lang.String field
private final Automaton.Builder builder
Automaton det
private final java.util.Map<BytesRef,java.lang.Integer> termToID
private final java.util.Map<java.lang.Integer,BytesRef> idToTerm
private int anyTermID
public int createState()
public void setAccept(int state, boolean accept)
public void addTransition(int source, int dest, java.lang.String term)
public void addTransition(int source, int dest, BytesRef term)
public void addAnyTransition(int source, int dest)
public void finish()
public void finish(int maxDeterminizedStates)
maxDeterminizedStates
- Maximum number of states created when
determinizing the automaton. Higher numbers allow this operation to
consume more memory but allow more complex automatons.public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws java.io.IOException
Query
Only implemented by primitive queries, which re-write to themselves.
createWeight
in class Query
scoreMode
- How the produced scorers will be consumed.boost
- The boost that is propagated by the parent queries.java.io.IOException
public java.lang.String toString(java.lang.String field)
Query
field
assumed to be the
default field and omitted.private int getTermID(BytesRef term)
public boolean equals(java.lang.Object other)
o
is equal to this.equals
in class Query
Query.sameClassAs(Object)
,
Query.classHash()
private static boolean checkFinished(TermAutomatonQuery q)
private boolean equalsTo(TermAutomatonQuery other)
public int hashCode()
Query
QueryCache
works properly.hashCode
in class Query
Query.equals(Object)
public java.lang.String toDot()
public Query rewrite(IndexReader reader) throws java.io.IOException
Query
public void visit(QueryVisitor visitor)
Query