Skip to content
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 37 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
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 Jul 26, 2018
7d9b9ef
Add relative intervals
romseygeek Jul 26, 2018
1197fdf
Merge branch 'master' into interval-query
romseygeek Aug 30, 2018
b0439c3
feedback
romseygeek Aug 31, 2018
6cb7fe8
YAML test - broekn
romseygeek Sep 5, 2018
df4d329
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek Sep 30, 2018
b0d28aa
yaml test; begin to add block source
romseygeek Oct 1, 2018
a8806e2
Add block; make disjunction its own source
romseygeek Oct 2, 2018
a4cecc9
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek Nov 7, 2018
8489e86
WIP
romseygeek Nov 12, 2018
c8212f1
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek Nov 30, 2018
2a2244d
Extract IntervalBuilder and add tests for it
romseygeek Dec 1, 2018
6e5339d
Fix eq/hashcode in Disjunction
romseygeek Dec 1, 2018
52bcf1f
New yaml test
romseygeek Dec 1, 2018
872f913
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek Dec 1, 2018
6f2c73c
checkstyle
romseygeek Dec 2, 2018
f044495
license headers
romseygeek Dec 2, 2018
1377bcc
test fix
romseygeek Dec 2, 2018
0368133
YAML format
romseygeek Dec 2, 2018
9c2f035
YAML formatting again
romseygeek Dec 2, 2018
7cde116
yaml tests; javadoc
romseygeek Dec 3, 2018
dabdd77
Add OR test -> requires fix from LUCENE-8586
romseygeek Dec 3, 2018
ba979e5
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek Dec 5, 2018
122f192
Add docs
romseygeek Dec 5, 2018
22f99b4
Re-do API
romseygeek Dec 11, 2018
6de587d
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek Dec 11, 2018
3146c47
Clint's API
romseygeek Dec 11, 2018
3bf1b0d
Delete bash script
romseygeek Dec 11, 2018
2d2df63
doc fixes
romseygeek Dec 11, 2018
67bc11a
imports
romseygeek Dec 11, 2018
abf75bd
docs
romseygeek Dec 11, 2018
0b14af3
test fix
romseygeek Dec 12, 2018
45bf499
feedback
romseygeek Dec 13, 2018
6780a57
Merge remote-tracking branch 'origin/master' into interval-query
romseygeek Dec 13, 2018
a33d816
comma
romseygeek Dec 13, 2018
9834a06
docs fixes
romseygeek Dec 13, 2018
a754165
Tidy up doc references to old rule
romseygeek Dec 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
setup:
- skip:
Copy link
Contributor

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 the setup part but if it's working... ;)

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 }


Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermInSetQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.intervals.IntervalsSource;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Nullable;
Expand Down Expand Up @@ -374,6 +375,15 @@ public Query multiPhraseQuery(String field, TokenStream stream, int slop, boolea
+ "] which is of type [" + typeName() + "]");
}

public enum IntervalType {
ORDERED, UNORDERED, PHRASE
}

public IntervalsSource intervals(String text, IntervalType type) throws IOException {
throw new IllegalArgumentException("Can only use interval queries on text fields - not on [" + name
+ "] which is of type [" + typeName() + "]");
}

/**
* An enum used to describe the relation between the range of terms in a
* shard when compared with a query range
Expand Down Expand Up @@ -465,4 +475,5 @@ public static Term extractTerm(Query termQuery) {
}
return ((TermQuery) termQuery).getTerm();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe say "intervals source" instead of just source?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 {

Expand Down