Add overlapping, before, after filters to intervals query (#38999)

Lucene recently added `overlapping`, `before` and `after` filters to the intervals package. This
commit exposes them in elasticsearch.
This commit is contained in:
Alan Woodward 2019-02-18 14:44:07 +00:00 committed by Alan Woodward
parent 2947ccf5c3
commit ab4d5f404f
4 changed files with 79 additions and 1 deletions

View File

@ -151,8 +151,14 @@ Produces intervals that are contained by an interval from the filter rule
Produces intervals that do not contain an interval from the filter rule
`not_contained_by`::
Produces intervals that are not contained by an interval from the filter rule
`overlapping`::
Produces intervals that overlap with an interval from the filter rule
`not_overlapping`::
Produces intervals that do not overlap with an interval from the filter rule
`before`::
Produces intervals that appear before an interval from the filter role
`after`::
Produces intervals that appear after an interval from the filter role
[[interval-script-filter]]
==== Script filters

View File

@ -322,3 +322,68 @@ setup:
query: "there"
ordered: false
- match: { hits.total.value: 1 }
---
"Test overlapping":
- skip:
version: " - 7.9.99"
reason: "Implemented in 7.1"
- do:
search:
index: test
body:
query:
intervals:
text:
match:
query: "cold outside"
ordered: true
filter:
overlapping:
match:
query: "baby there"
ordered: false
- match: { hits.total.value: 1 }
- match: { hits.hits.0._id: "3" }
---
"Test before":
- skip:
version: " - 7.9.99"
reason: "Implemented in 7.1"
- do:
search:
index: test
body:
query:
intervals:
text:
match:
query: "cold"
filter:
before:
match:
query: "outside"
- match: { hits.total.value: 2 }
---
"Test after":
- skip:
version: " - 7.9.99"
reason: "Implemented in 7.1"
- do:
search:
index: test
body:
query:
intervals:
text:
match:
query: "cold"
filter:
after:
match:
query: "outside"
- match: { hits.total.value: 1 }
- match: { hits.hits.0._id: "4" }

View File

@ -453,8 +453,14 @@ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXCont
return Intervals.notContaining(input, filterSource);
case "not_contained_by":
return Intervals.notContainedBy(input, filterSource);
case "overlapping":
return Intervals.overlapping(input, filterSource);
case "not_overlapping":
return Intervals.nonOverlapping(input, filterSource);
case "before":
return Intervals.before(input, filterSource);
case "after":
return Intervals.after(input, filterSource);
default:
throw new IllegalArgumentException("Unknown filter type [" + type + "]");
}

View File

@ -53,7 +53,8 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
}
private static final String[] filters = new String[]{
"containing", "contained_by", "not_containing", "not_contained_by", "not_overlapping"
"containing", "contained_by", "not_containing", "not_contained_by",
"overlapping", "not_overlapping", "before", "after"
};
private IntervalsSourceProvider.IntervalFilter createRandomFilter() {