Skip to content

Commit

Permalink
Add overlapping, before, after filters to intervals query (#38999)
Browse files Browse the repository at this point in the history
Lucene recently added `overlapping`, `before` and `after` filters to the intervals package. This
commit exposes them in elasticsearch.
  • Loading branch information
romseygeek committed Feb 18, 2019
1 parent 2947ccf commit ab4d5f4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/reference/query-dsl/intervals-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,14 @@ public IntervalsSource filter(IntervalsSource input, QueryShardContext context,
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 + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public void testUnknownField() throws IOException {
}

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() {
Expand Down

0 comments on commit ab4d5f4

Please sign in to comment.