Package org.apache.lucene.search
Class RegexpQuery
java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.MultiTermQuery
org.apache.lucene.search.AutomatonQuery
org.apache.lucene.search.RegexpQuery
- All Implemented Interfaces:
Accountable
A fast regular expression query based on the
org.apache.lucene.util.automaton
package.
- Comparisons are fast
- The term dictionary is enumerated in an intelligent way, to avoid comparisons. See
AutomatonQuery
for more details.
The supported syntax is documented in the RegExp
class. Note this might be different
than other regular expression implementations. For some alternatives with different syntax, look
under the sandbox.
Note this query can be slow, as it needs to iterate over many terms. In order to prevent
extremely slow RegexpQueries, a Regexp term should not start with the expression .*
- See Also:
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
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 TypeFieldDescriptionstatic final AutomatonProvider
A provider that provides no named automataFields inherited from class org.apache.lucene.search.AutomatonQuery
automaton, automatonIsBinary, compiled, term
Fields inherited from class org.apache.lucene.search.MultiTermQuery
CONSTANT_SCORE_BLENDED_REWRITE, CONSTANT_SCORE_BOOLEAN_REWRITE, CONSTANT_SCORE_REWRITE, DOC_VALUES_REWRITE, field, rewriteMethod, SCORING_BOOLEAN_REWRITE
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE
-
Constructor Summary
ConstructorsConstructorDescriptionRegexpQuery
(Term term) Constructs a query for terms matchingterm
.RegexpQuery
(Term term, int flags) Constructs a query for terms matchingterm
.RegexpQuery
(Term term, int flags, int determinizeWorkLimit) Constructs a query for terms matchingterm
.RegexpQuery
(Term term, int syntaxFlags, int matchFlags, int determinizeWorkLimit) Constructs a query for terms matchingterm
.RegexpQuery
(Term term, int syntaxFlags, int matchFlags, AutomatonProvider provider, int determinizeWorkLimit, MultiTermQuery.RewriteMethod rewriteMethod) Constructs a query for terms matchingterm
.RegexpQuery
(Term term, int syntaxFlags, int matchFlags, AutomatonProvider provider, int determinizeWorkLimit, MultiTermQuery.RewriteMethod rewriteMethod, boolean doDeterminization) Constructs a query for terms matchingterm
.RegexpQuery
(Term term, int syntaxFlags, AutomatonProvider provider, int determinizeWorkLimit) Constructs a query for terms matchingterm
. -
Method Summary
Methods inherited from class org.apache.lucene.search.AutomatonQuery
equals, getAutomaton, getCompiled, getTermsEnum, hashCode, isAutomatonBinary, ramBytesUsed, visit
Methods inherited from class org.apache.lucene.search.MultiTermQuery
getField, getRewriteMethod, getTermsCount, getTermsEnum, rewrite
Methods inherited from class org.apache.lucene.search.Query
classHash, createWeight, 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 Details
-
DEFAULT_PROVIDER
A provider that provides no named automata
-
-
Constructor Details
-
RegexpQuery
Constructs a query for terms matchingterm
.By default, all regular expression features are enabled.
- Parameters:
term
- regular expression.
-
RegexpQuery
Constructs a query for terms matchingterm
.- Parameters:
term
- regular expression.flags
- optional RegExp features fromRegExp
-
RegexpQuery
Constructs a query for terms matchingterm
.- Parameters:
term
- regular expression.flags
- optional RegExp syntax features fromRegExp
determinizeWorkLimit
- maximum effort to spend while compiling the automaton from this regexp. Set higher to allow more complex queries and lower to prevent memory exhaustion. UseOperations.DEFAULT_DETERMINIZE_WORK_LIMIT
as a decent default if you don't otherwise know what to specify.
-
RegexpQuery
Constructs a query for terms matchingterm
.- Parameters:
term
- regular expression.syntaxFlags
- optional RegExp syntax features fromRegExp
automaton for the regexp can result in. Set higher to allow more complex queries and lower to prevent memory exhaustion.matchFlags
- boolean 'or' of match behavior options such as case insensitivitydeterminizeWorkLimit
- maximum effort to spend while compiling the automaton from this regexp. Set higher to allow more complex queries and lower to prevent memory exhaustion. UseOperations.DEFAULT_DETERMINIZE_WORK_LIMIT
as a decent default if you don't otherwise know what to specify.
-
RegexpQuery
public RegexpQuery(Term term, int syntaxFlags, AutomatonProvider provider, int determinizeWorkLimit) Constructs a query for terms matchingterm
.- Parameters:
term
- regular expression.syntaxFlags
- optional RegExp features fromRegExp
provider
- custom AutomatonProvider for named automatadeterminizeWorkLimit
- maximum effort to spend while compiling the automaton from this regexp. Set higher to allow more complex queries and lower to prevent memory exhaustion. UseOperations.DEFAULT_DETERMINIZE_WORK_LIMIT
as a decent default if you don't otherwise know what to specify.
-
RegexpQuery
public RegexpQuery(Term term, int syntaxFlags, int matchFlags, AutomatonProvider provider, int determinizeWorkLimit, MultiTermQuery.RewriteMethod rewriteMethod) Constructs a query for terms matchingterm
.- Parameters:
term
- regular expression.syntaxFlags
- optional RegExp features fromRegExp
matchFlags
- boolean 'or' of match behavior options such as case insensitivityprovider
- custom AutomatonProvider for named automatadeterminizeWorkLimit
- maximum effort to spend while compiling the automaton from this regexp. Set higher to allow more complex queries and lower to prevent memory exhaustion. UseOperations.DEFAULT_DETERMINIZE_WORK_LIMIT
as a decent default if you don't otherwise know what to specify.rewriteMethod
- the rewrite method to use to build the final query
-
RegexpQuery
public RegexpQuery(Term term, int syntaxFlags, int matchFlags, AutomatonProvider provider, int determinizeWorkLimit, MultiTermQuery.RewriteMethod rewriteMethod, boolean doDeterminization) Constructs a query for terms matchingterm
.- Parameters:
term
- regular expression.syntaxFlags
- optional RegExp features fromRegExp
matchFlags
- boolean 'or' of match behavior options such as case insensitivityprovider
- custom AutomatonProvider for named automatadeterminizeWorkLimit
- maximum effort to spend while compiling the automaton from this regexp. Set higher to allow more complex queries and lower to prevent memory exhaustion. UseOperations.DEFAULT_DETERMINIZE_WORK_LIMIT
as a decent default if you don't otherwise know what to specify.rewriteMethod
- the rewrite method to use to build the final querydoDeterminization
- whether do determinization to force the query to use DFA as runAutomaton, if false, the query will not try to determinize the generated automaton from regexp such that it might or might not be a DFA. In case it is an NFA, the query will eventually useNFARunAutomaton
to execute. Notice thatNFARunAutomaton
is not thread-safe, so better to avoid rewritten method likeMultiTermQuery.CONSTANT_SCORE_BLENDED_REWRITE
when searcher is configured with an executor service
-
-
Method Details
-
getRegexp
Returns the regexp of this query wrapped in a Term. -
toString
Prints a user-readable version of this query.- Overrides:
toString
in classAutomatonQuery
-