-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LUCENE-9099: Correctly handle repeats in ORDERED and UNORDERED intervals #1097
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…e gaps; IS.matches() now returns IntervalMatchesIterator to propagate width correctly
jimczi
approved these changes
Feb 6, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, the code becomes a bit difficult to follow but it's great that we can handle repeats correctly. This is another advantage over Span queries so +1 to merge.
asfgit
pushed a commit
that referenced
this pull request
Feb 6, 2020
…als (#1097) If you have repeating intervals in an ordered or unordered interval source, you currently get somewhat confusing behaviour: * `ORDERED(a, a, b)` will return an extra interval over just a b if it first matches a a b, meaning that you can get incorrect results if used in a `CONTAINING` filter - `CONTAINING(ORDERED(x, y), ORDERED(a, a, b))` will match on the document `a x a b y` * `UNORDERED(a, a)` will match on documents that just containg a single a. This commit adds a RepeatingIntervalsSource that correctly handles repeats within ordered and unordered sources. It also changes the way that gaps are calculated within ordered and unordered sources, by using a new width() method on IntervalIterator. The default implementation just returns end() - start() + 1, but RepeatingIntervalsSource instead returns the sum of the widths of its child iterators. This preserves maxgaps filtering on ordered and unordered sources that contain repeats. In order to correctly handle matches in this scenario, IntervalsSource#matches now always returns an explicit IntervalsMatchesIterator rather than a plain MatchesIterator, which adds gaps() and width() methods so that submatches can be combined in the same way that subiterators are. Extra checks have been added to checkIntervals() to ensure that the same intervals are returned by both iterator and matches, and a fix to DisjunctionIntervalIterator#matches() is also included - DisjunctionIntervalIterator minimizes its intervals, while MatchesUtils.disjunction does not, so there was a discrepancy between the two methods.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If you have repeating intervals in an ordered or unordered interval source, you currently get somewhat confusing behaviour:
ORDERED(a, a, b)
will return an extra interval over justa b
if it first matchesa a b
, meaning that you can get incorrect results if used in aCONTAINING
filter -CONTAINING(ORDERED(x, y), ORDERED(a, a, b))
will match on the documenta x a b y
UNORDERED(a, a)
will match on documents that just containg a singlea
.This commit adds a
RepeatingIntervalsSource
that correctly handles repeats within ordered and unordered sources. It also changes the way that gaps are calculated within ordered and unordered sources, by using a newwidth()
method onIntervalIterator
. The default implementation just returnsend() - start() + 1
, butRepeatingIntervalsSource
instead returns the sum of the widths of its child iterators. This preservesmaxgaps
filtering on ordered and unordered sources that contain repeats.In order to correctly handle matches in this scenario,
IntervalsSource#matches
now always returns an explicitIntervalsMatchesIterator
rather than a plainMatchesIterator
, which addsgaps()
andwidth()
methods so that submatches can be combined in the same way that subiterators are. Extra checks have been added tocheckIntervals()
to ensure that the same intervals are returned by both iterator and matches, and a fix toDisjunctionIntervalIterator#matches()
is also included -DisjunctionIntervalIterator
minimizes its intervals, whileMatchesUtils.disjunction
does not, so there was a discrepancy between the two methods.