-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Add intervals query #36135
Merged
Merged
Add intervals query #36135
Changes from 20 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
6b7d175
Add IntervalQueryBuilder with support for match and combine intervals
romseygeek 7d9b9ef
Add relative intervals
romseygeek 1197fdf
Merge branch 'master' into interval-query
romseygeek b0439c3
feedback
romseygeek 6cb7fe8
YAML test - broekn
romseygeek df4d329
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek b0d28aa
yaml test; begin to add block source
romseygeek a8806e2
Add block; make disjunction its own source
romseygeek a4cecc9
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek 8489e86
WIP
romseygeek c8212f1
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek 2a2244d
Extract IntervalBuilder and add tests for it
romseygeek 6e5339d
Fix eq/hashcode in Disjunction
romseygeek 52bcf1f
New yaml test
romseygeek 872f913
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek 6f2c73c
checkstyle
romseygeek f044495
license headers
romseygeek 1377bcc
test fix
romseygeek 0368133
YAML format
romseygeek 9c2f035
YAML formatting again
romseygeek 7cde116
yaml tests; javadoc
romseygeek dabdd77
Add OR test -> requires fix from LUCENE-8586
romseygeek ba979e5
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek 122f192
Add docs
romseygeek 22f99b4
Re-do API
romseygeek 6de587d
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek 3146c47
Clint's API
romseygeek 3bf1b0d
Delete bash script
romseygeek 2d2df63
doc fixes
romseygeek 67bc11a
imports
romseygeek abf75bd
docs
romseygeek 0b14af3
test fix
romseygeek 45bf499
feedback
romseygeek 6780a57
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek a33d816
comma
romseygeek 9834a06
docs fixes
romseygeek a754165
Tidy up doc references to old rule
romseygeek File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
rest-api-spec/src/main/resources/rest-api-spec/test/search/230_interval_query.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
setup: | ||
- skip: | ||
version: " - 6.99.99" | ||
reason: "Implemented in 7.0" | ||
|
||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
mappings: | ||
test: | ||
properties: | ||
text: | ||
type: text | ||
analyzer: standard | ||
- do: | ||
bulk: | ||
refresh: true | ||
body: | ||
- '{"index": {"_index": "test", "_type": "test", "_id": "1"}}' | ||
- '{"text" : "Some like it hot, some like it cold"}' | ||
- '{"index": {"_index": "test", "_type": "test", "_id": "2"}}' | ||
- '{"text" : "Its cold outside, theres no kind of atmosphere"}' | ||
- '{"index": {"_index": "test", "_type": "test", "_id": "3"}}' | ||
- '{"text" : "Baby its cold there outside"}' | ||
- '{"index": {"_index": "test", "_type": "test", "_id": "4"}}' | ||
- '{"text" : "Outside it is cold and wet"}' | ||
|
||
--- | ||
"Test ordered matching": | ||
- do: | ||
search: | ||
index: test | ||
body: | ||
query: | ||
intervals: | ||
field: text | ||
source: | ||
match: | ||
text: "cold outside" | ||
type: ordered | ||
- match: { hits.total: 2 } | ||
|
||
--- | ||
"Test default unordered matching": | ||
- do: | ||
search: | ||
index: test | ||
body: | ||
query: | ||
intervals: | ||
field: text | ||
source: | ||
match: | ||
text: "cold outside" | ||
- match: { hits.total: 3 } | ||
|
||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
import org.apache.lucene.search.PhraseQuery; | ||
import org.apache.lucene.search.Query; | ||
import org.apache.lucene.search.TermQuery; | ||
import org.apache.lucene.search.intervals.IntervalsSource; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.collect.Iterators; | ||
import org.elasticsearch.common.settings.Settings; | ||
|
@@ -48,6 +49,7 @@ | |
import org.elasticsearch.index.analysis.NamedAnalyzer; | ||
import org.elasticsearch.index.fielddata.IndexFieldData; | ||
import org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData; | ||
import org.elasticsearch.index.query.IntervalBuilder; | ||
import org.elasticsearch.index.query.QueryShardContext; | ||
|
||
import java.io.IOException; | ||
|
@@ -579,6 +581,15 @@ public Query existsQuery(QueryShardContext context) { | |
} | ||
} | ||
|
||
@Override | ||
public IntervalsSource intervals(String text, IntervalType type) throws IOException { | ||
if (indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) { | ||
throw new IllegalArgumentException("Cannot create source against field [" + name() + "] with no positions indexed"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe say "intervals source" instead of just source? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ++ |
||
} | ||
IntervalBuilder builder = new IntervalBuilder(name(), searchAnalyzer()); | ||
return builder.analyzeText(text, type); | ||
} | ||
|
||
@Override | ||
public Query phraseQuery(String field, TokenStream stream, int slop, boolean enablePosIncrements) throws IOException { | ||
|
||
|
Oops, something went wrong.
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.
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.
Is this working ? I was not aware that the
skip
section can be set in thesetup
part but if it's working... ;)