Skip to content

Commit

Permalink
Addressed review comments (thanks @jpountz !)
Browse files Browse the repository at this point in the history
Reordered constructor args and added arg validation.
  • Loading branch information
markharwood committed Jul 8, 2020
1 parent 52788bc commit e4424fe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions lucene/core/src/java/org/apache/lucene/search/RegexpQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ public RegexpQuery(Term term, int flags, int maxDeterminizedStates) {
* Constructs a query for terms matching <code>term</code>.
*
* @param term regular expression.
* @param maxDeterminizedStates maximum number of states that compiling the
* @param syntax_flags optional RegExp syntax features from {@link RegExp}
* automaton for the regexp can result in. Set higher to allow more complex
* queries and lower to prevent memory exhaustion.
* @param match_flags boolean 'or' of match behavior options such as case insensitivity
* @param maxDeterminizedStates maximum number of states that compiling the
*/
public RegexpQuery(Term term, int maxDeterminizedStates, int syntax_flags, int match_flags) {
this(term, defaultProvider, maxDeterminizedStates, syntax_flags, match_flags);
public RegexpQuery(Term term, int syntax_flags, int match_flags, int maxDeterminizedStates) {
this(term, syntax_flags, match_flags, defaultProvider, maxDeterminizedStates);
}

/**
Expand All @@ -118,22 +118,22 @@ public RegexpQuery(Term term, int maxDeterminizedStates, int syntax_flags, int
*/
public RegexpQuery(Term term, int syntax_flags, AutomatonProvider provider,
int maxDeterminizedStates) {
this(term, provider, maxDeterminizedStates, syntax_flags, 0);
this(term, syntax_flags, 0, provider, maxDeterminizedStates);
}

/**
* Constructs a query for terms matching <code>term</code>.
*
* @param term regular expression.
* @param syntax_flags optional RegExp features from {@link RegExp}
* @param match_flags boolean 'or' of match behavior options such as case insensitivity
* @param provider custom AutomatonProvider for named automata
* @param maxDeterminizedStates maximum number of states that compiling the
* automaton for the regexp can result in. Set higher to allow more complex
* queries and lower to prevent memory exhaustion.
* @param match_flags boolean 'or' of match behavior options such as case insensitivity
*/
public RegexpQuery(Term term, AutomatonProvider provider,
int maxDeterminizedStates, int syntax_flags, int match_flags) {
public RegexpQuery(Term term, int syntax_flags, int match_flags, AutomatonProvider provider,
int maxDeterminizedStates) {
super(term,
new RegExp(term.text(), syntax_flags, match_flags).toAutomaton(
provider, maxDeterminizedStates), maxDeterminizedStates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,9 @@ public RegExp(String s, int syntax_flags) throws IllegalArgumentException {
* regular expression
*/
public RegExp(String s, int syntax_flags, int match_flags) throws IllegalArgumentException {
// (for BWC reasons we don't validate invalid bits, just trim instead)
syntax_flags = syntax_flags & 0xff;
if (syntax_flags > ALL) {
throw new IllegalArgumentException("Illegal syntax flag");
}

if (match_flags > 0 && match_flags <= ALL) {
throw new IllegalArgumentException("Illegal match flag");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ private long regexQueryNrHits(String regex) throws IOException {
}

private long caseInsensitiveRegexQueryNrHits(String regex) throws IOException {
RegexpQuery query = new RegexpQuery(newTerm(regex), Operations.DEFAULT_MAX_DETERMINIZED_STATES,
RegExp.ALL, RegExp.ASCII_CASE_INSENSITIVE);
RegexpQuery query = new RegexpQuery(newTerm(regex), RegExp.ALL, RegExp.ASCII_CASE_INSENSITIVE,
Operations.DEFAULT_MAX_DETERMINIZED_STATES);
return searcher.count(query);
}

Expand Down

0 comments on commit e4424fe

Please sign in to comment.