Skip to content

Commit e4424fe

Browse files
committed
Addressed review comments (thanks @jpountz !)
Reordered constructor args and added arg validation.
1 parent 52788bc commit e4424fe

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

lucene/core/src/java/org/apache/lucene/search/RegexpQuery.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ public RegexpQuery(Term term, int flags, int maxDeterminizedStates) {
9696
* Constructs a query for terms matching <code>term</code>.
9797
*
9898
* @param term regular expression.
99-
* @param maxDeterminizedStates maximum number of states that compiling the
10099
* @param syntax_flags optional RegExp syntax features from {@link RegExp}
101100
* automaton for the regexp can result in. Set higher to allow more complex
102101
* queries and lower to prevent memory exhaustion.
103102
* @param match_flags boolean 'or' of match behavior options such as case insensitivity
103+
* @param maxDeterminizedStates maximum number of states that compiling the
104104
*/
105-
public RegexpQuery(Term term, int maxDeterminizedStates, int syntax_flags, int match_flags) {
106-
this(term, defaultProvider, maxDeterminizedStates, syntax_flags, match_flags);
105+
public RegexpQuery(Term term, int syntax_flags, int match_flags, int maxDeterminizedStates) {
106+
this(term, syntax_flags, match_flags, defaultProvider, maxDeterminizedStates);
107107
}
108108

109109
/**
@@ -118,22 +118,22 @@ public RegexpQuery(Term term, int maxDeterminizedStates, int syntax_flags, int
118118
*/
119119
public RegexpQuery(Term term, int syntax_flags, AutomatonProvider provider,
120120
int maxDeterminizedStates) {
121-
this(term, provider, maxDeterminizedStates, syntax_flags, 0);
121+
this(term, syntax_flags, 0, provider, maxDeterminizedStates);
122122
}
123123

124124
/**
125125
* Constructs a query for terms matching <code>term</code>.
126126
*
127127
* @param term regular expression.
128128
* @param syntax_flags optional RegExp features from {@link RegExp}
129+
* @param match_flags boolean 'or' of match behavior options such as case insensitivity
129130
* @param provider custom AutomatonProvider for named automata
130131
* @param maxDeterminizedStates maximum number of states that compiling the
131132
* automaton for the regexp can result in. Set higher to allow more complex
132133
* queries and lower to prevent memory exhaustion.
133-
* @param match_flags boolean 'or' of match behavior options such as case insensitivity
134134
*/
135-
public RegexpQuery(Term term, AutomatonProvider provider,
136-
int maxDeterminizedStates, int syntax_flags, int match_flags) {
135+
public RegexpQuery(Term term, int syntax_flags, int match_flags, AutomatonProvider provider,
136+
int maxDeterminizedStates) {
137137
super(term,
138138
new RegExp(term.text(), syntax_flags, match_flags).toAutomaton(
139139
provider, maxDeterminizedStates), maxDeterminizedStates);

lucene/core/src/java/org/apache/lucene/util/automaton/RegExp.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,9 @@ public RegExp(String s, int syntax_flags) throws IllegalArgumentException {
521521
* regular expression
522522
*/
523523
public RegExp(String s, int syntax_flags, int match_flags) throws IllegalArgumentException {
524-
// (for BWC reasons we don't validate invalid bits, just trim instead)
525-
syntax_flags = syntax_flags & 0xff;
524+
if (syntax_flags > ALL) {
525+
throw new IllegalArgumentException("Illegal syntax flag");
526+
}
526527

527528
if (match_flags > 0 && match_flags <= ALL) {
528529
throw new IllegalArgumentException("Illegal match flag");

lucene/core/src/test/org/apache/lucene/search/TestRegexpQuery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ private long regexQueryNrHits(String regex) throws IOException {
7474
}
7575

7676
private long caseInsensitiveRegexQueryNrHits(String regex) throws IOException {
77-
RegexpQuery query = new RegexpQuery(newTerm(regex), Operations.DEFAULT_MAX_DETERMINIZED_STATES,
78-
RegExp.ALL, RegExp.ASCII_CASE_INSENSITIVE);
77+
RegexpQuery query = new RegexpQuery(newTerm(regex), RegExp.ALL, RegExp.ASCII_CASE_INSENSITIVE,
78+
Operations.DEFAULT_MAX_DETERMINIZED_STATES);
7979
return searcher.count(query);
8080
}
8181

0 commit comments

Comments
 (0)