Skip to content

Commit

Permalink
Fix multiple repeat operators. Rewrite redundant repetitions.
Browse files Browse the repository at this point in the history
[]{3,4}? didn't work before (only one repetition operator could be applied);
now it should work properly.

Also recognized redundantly making a clause optional, e.g. []{0,2}? ;
will be rewritten to the simpler and faster []{0,2}.
  • Loading branch information
jan-niestadt committed May 13, 2024
1 parent 85f238b commit a38df95
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public BLSpanQuery rewrite(IndexReader reader) throws IOException {
if (tp.min == 1 && tp.max == 1) {
// Repeat of a single any token
return new SpanQueryAnyToken(queryInfo, min, max, base.getRealField());
} else if (min == 0 && max == 1 && tp.min == 0) {
// Making an already optional (tp.min == 0) anytoken clause optional again
return tp;
} else if (min == max && tp.min == tp.max) {
// Exact number of any tokens
int n = min * tp.min;
Expand All @@ -134,8 +137,8 @@ public BLSpanQuery rewrite(IndexReader reader) throws IOException {
return new SpanQueryRepetition(tp.clauses.get(0), min * tp.min, max);
}
} else {
if (min == 0 && max == 1 && tp.min == 0 && tp.max == 1) {
// A?? == A?
if (min == 0 && max == 1 && tp.min == 0) {
// Making an already optional (tp.min == 0) anytoken clause optional again
return tp;
}
// (A{x,y}{1,1} == A{x,y} has been rewritten above already)
Expand Down
Loading

0 comments on commit a38df95

Please sign in to comment.