RegexpQueryBuilder now implements MultiTermQueryBuilder
This allows the RegexpQueryBuilder to be used in span queries Added tests for all span multi term queries. Also updated the documentation and removed mentioning of numeric range queries for span queries (they have to be terms). Closes #3392
This commit is contained in:
parent
d43f3d83d8
commit
dfcb3ca2d4
|
@ -2,7 +2,7 @@
|
||||||
=== Span Multi Term Query
|
=== Span Multi Term Query
|
||||||
|
|
||||||
The `span_multi` query allows you to wrap a `multi term query` (one of
|
The `span_multi` query allows you to wrap a `multi term query` (one of
|
||||||
fuzzy, prefix, term range or numeric range query) as a `span query`, so
|
fuzzy, prefix, term range or regexp query) as a `span query`, so
|
||||||
it can be nested. Example:
|
it can be nested. Example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
|
|
|
@ -28,7 +28,7 @@ import java.io.IOException;
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RegexpQueryBuilder extends BaseQueryBuilder implements BoostableQueryBuilder<RegexpQueryBuilder> {
|
public class RegexpQueryBuilder extends BaseQueryBuilder implements BoostableQueryBuilder<RegexpQueryBuilder>, MultiTermQueryBuilder {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String regexp;
|
private final String regexp;
|
||||||
|
|
|
@ -1505,6 +1505,74 @@ public class SimpleQueryTests extends AbstractIntegrationTest {
|
||||||
assertHitCount(response, 3l);
|
assertHitCount(response, 3l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSpanMultiTermQuery() throws ElasticSearchException, IOException {
|
||||||
|
|
||||||
|
client().admin().indices().prepareCreate("test").setSettings(
|
||||||
|
ImmutableSettings.settingsBuilder()
|
||||||
|
.put("index.number_of_shards", 1)
|
||||||
|
.put("index.number_of_replicas", 0)
|
||||||
|
)
|
||||||
|
.execute().actionGet();
|
||||||
|
ensureGreen();
|
||||||
|
|
||||||
|
client().prepareIndex("test", "test", "1").setSource(jsonBuilder().startObject()
|
||||||
|
.field("description", "foo other anything bar")
|
||||||
|
.field("count", 1)
|
||||||
|
.endObject())
|
||||||
|
.execute().actionGet();
|
||||||
|
|
||||||
|
client().prepareIndex("test", "test", "2").setSource(jsonBuilder().startObject()
|
||||||
|
.field("description", "foo other anything")
|
||||||
|
.field("count", 2)
|
||||||
|
.endObject())
|
||||||
|
.execute().actionGet();
|
||||||
|
|
||||||
|
client().prepareIndex("test", "test", "3").setSource(jsonBuilder().startObject()
|
||||||
|
.field("description", "foo other")
|
||||||
|
.field("count", 3)
|
||||||
|
.endObject())
|
||||||
|
.execute().actionGet();
|
||||||
|
|
||||||
|
client().prepareIndex("test", "test", "4").setSource(jsonBuilder().startObject()
|
||||||
|
.field("description", "fop")
|
||||||
|
.field("count", 4)
|
||||||
|
.endObject())
|
||||||
|
.execute().actionGet();
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
SearchResponse response = client().prepareSearch("test")
|
||||||
|
.setQuery(QueryBuilders.spanOrQuery().clause(QueryBuilders.spanMultiTermQueryBuilder(QueryBuilders.fuzzyQuery("description", "fop"))))
|
||||||
|
.execute().actionGet();
|
||||||
|
assertNoFailures(response);
|
||||||
|
assertHitCount(response, 4);
|
||||||
|
|
||||||
|
response = client().prepareSearch("test")
|
||||||
|
.setQuery(QueryBuilders.spanOrQuery().clause(QueryBuilders.spanMultiTermQueryBuilder(QueryBuilders.prefixQuery("description", "fo"))))
|
||||||
|
.execute().actionGet();
|
||||||
|
assertNoFailures(response);
|
||||||
|
assertHitCount(response, 4);
|
||||||
|
|
||||||
|
response = client().prepareSearch("test")
|
||||||
|
.setQuery(QueryBuilders.spanOrQuery().clause(QueryBuilders.spanMultiTermQueryBuilder(QueryBuilders.wildcardQuery("description", "oth*"))))
|
||||||
|
.execute().actionGet();
|
||||||
|
assertNoFailures(response);
|
||||||
|
assertHitCount(response, 3);
|
||||||
|
|
||||||
|
response = client().prepareSearch("test")
|
||||||
|
.setQuery(QueryBuilders.spanOrQuery().clause(QueryBuilders.spanMultiTermQueryBuilder(QueryBuilders.rangeQuery("description").from("ffa").to("foo"))))
|
||||||
|
.execute().actionGet();
|
||||||
|
assertNoFailures(response);
|
||||||
|
assertHitCount(response, 3);
|
||||||
|
|
||||||
|
response = client().prepareSearch("test")
|
||||||
|
.setQuery(QueryBuilders.spanOrQuery().clause(QueryBuilders.spanMultiTermQueryBuilder(QueryBuilders.regexpQuery("description", "fo{2}"))))
|
||||||
|
.execute().actionGet();
|
||||||
|
assertNoFailures(response);
|
||||||
|
assertHitCount(response, 3);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleDFSQuery() throws ElasticSearchException, IOException {
|
public void testSimpleDFSQuery() throws ElasticSearchException, IOException {
|
||||||
prepareCreate("test", -1,
|
prepareCreate("test", -1,
|
||||||
|
|
Loading…
Reference in New Issue