Skip to content

Commit

Permalink
Fix ordered intervals query over interleaved terms (#12214)
Browse files Browse the repository at this point in the history
Given an input text 'A B A C A B C' and search ORDERED(A, B, C), we should 
retrieve hits [0,3] and [4,6]; currently [4,6] is skipped.

After finding the first interval [0, 3], the subintervals will become A[0,0], B[1,1], 
C[3,3]; then the algorithm will try to minimize it and the subintervals will 
become: A:[2,2], B:[5,5], C:[3,3] (after finding 5 > 3 it breaks the minimization)

And when finding next interval, it will do advance(B) before checking whether 
it is after A(the do-while loop), so subintervals will become A[2,2], B[inf, inf], 
C[3,3] and return NO_MORE_INTERVAL.

This commit instead continues advancing subintervals from where the last
`nextInterval` call stopped, rather than always advancing all subintervals.
  • Loading branch information
hongyuyan97 authored and romseygeek committed Mar 27, 2023
1 parent 8a81515 commit e7648cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Bug Fixes

* GITHUB#12202: Fix MultiFieldQueryParser to apply boosts to regexp, wildcard, prefix, range, fuzzy queries. (Jasir KT)

* GITHUB#12214: Fix ordered intervals query to avoid skipping some of the results over interleaved terms. (Hongyu Yan)

Build
---------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public String toString() {

private static class OrderedIntervalIterator extends ConjunctionIntervalIterator {

int start = -1, end = -1, i;
int start = -1, end = -1, i = 1;
int slop;
final MatchCallback onMatch;

Expand All @@ -136,7 +136,6 @@ public int nextInterval() throws IOException {
start = end = slop = IntervalIterator.NO_MORE_INTERVALS;
int lastStart = Integer.MAX_VALUE;
boolean minimizing = false;
i = 1;
while (true) {
while (true) {
if (subIterators.get(i - 1).end() >= lastStart) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public void tearDown() throws Exception {
"greater new york",
"x x x x x intend x x x message x x x message x x x addressed x x",
"issue with intervals queries from search engine. So it's a big issue for us as we need to do ordered searches. Thank you to help us concerning that issue",
"場外好朋友"
"場外好朋友",
"alice bob alice alice carl alice bob alice carl"
};

private void checkHits(Query query, int[] results) throws IOException {
Expand Down Expand Up @@ -348,6 +349,17 @@ public void testOrderedWithGaps() throws IOException {
checkHits(q, new int[] {});
}

public void testOrderedWithGaps2() throws IOException {
Query q =
new IntervalQuery(
field,
Intervals.maxgaps(
1,
Intervals.ordered(
Intervals.term("alice"), Intervals.term("bob"), Intervals.term("carl"))));
checkHits(q, new int[] {12});
}

public void testNestedOrInContainedBy() throws IOException {
Query q =
new IntervalQuery(
Expand Down

0 comments on commit e7648cf

Please sign in to comment.