have terms filter builder support iterables as well
This commit is contained in:
parent
5325bf4bec
commit
5beb656a16
|
@ -23,8 +23,6 @@ import org.elasticsearch.common.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A static factory for simple "import static" usage.
|
* A static factory for simple "import static" usage.
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class FilterBuilders {
|
public abstract class FilterBuilders {
|
||||||
|
|
||||||
|
@ -186,6 +184,16 @@ public abstract class FilterBuilders {
|
||||||
return new TermsFilterBuilder(name, values);
|
return new TermsFilterBuilder(name, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A filer for a field based on several terms matching on any of them.
|
||||||
|
*
|
||||||
|
* @param name The field name
|
||||||
|
* @param values The terms
|
||||||
|
*/
|
||||||
|
public static TermsFilterBuilder termsFilter(String name, Iterable values) {
|
||||||
|
return new TermsFilterBuilder(name, values);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A filer for a field based on several terms matching on any of them.
|
* A filer for a field based on several terms matching on any of them.
|
||||||
*
|
*
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private final Object[] values;
|
private final Object values;
|
||||||
|
|
||||||
private Boolean cache;
|
private Boolean cache;
|
||||||
private String cacheKey;
|
private String cacheKey;
|
||||||
|
@ -57,10 +57,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
|
||||||
*/
|
*/
|
||||||
public TermsFilterBuilder(String name, int... values) {
|
public TermsFilterBuilder(String name, int... values) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.values = new Integer[values.length];
|
this.values = values;
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
this.values[i] = values[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,10 +68,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
|
||||||
*/
|
*/
|
||||||
public TermsFilterBuilder(String name, long... values) {
|
public TermsFilterBuilder(String name, long... values) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.values = new Long[values.length];
|
this.values = values;
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
this.values[i] = values[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,10 +79,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
|
||||||
*/
|
*/
|
||||||
public TermsFilterBuilder(String name, float... values) {
|
public TermsFilterBuilder(String name, float... values) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.values = new Float[values.length];
|
this.values = values;
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
this.values[i] = values[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,10 +90,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
|
||||||
*/
|
*/
|
||||||
public TermsFilterBuilder(String name, double... values) {
|
public TermsFilterBuilder(String name, double... values) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.values = new Double[values.length];
|
this.values = values;
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
this.values[i] = values[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,6 +104,17 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
|
||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A filer for a field based on several terms matching on any of them.
|
||||||
|
*
|
||||||
|
* @param name The field name
|
||||||
|
* @param values The terms
|
||||||
|
*/
|
||||||
|
public TermsFilterBuilder(String name, Iterable values) {
|
||||||
|
this.name = name;
|
||||||
|
this.values = values;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the execution mode for the terms filter. Cane be either "plain", "bool"
|
* Sets the execution mode for the terms filter. Cane be either "plain", "bool"
|
||||||
* "and". Defaults to "plain".
|
* "and". Defaults to "plain".
|
||||||
|
@ -149,11 +148,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
|
||||||
@Override
|
@Override
|
||||||
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
public void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(TermsFilterParser.NAME);
|
builder.startObject(TermsFilterParser.NAME);
|
||||||
builder.startArray(name);
|
builder.field(name, values);
|
||||||
for (Object value : values) {
|
|
||||||
builder.value(value);
|
|
||||||
}
|
|
||||||
builder.endArray();
|
|
||||||
|
|
||||||
if (execution != null) {
|
if (execution != null) {
|
||||||
builder.field("execution", execution);
|
builder.field("execution", execution);
|
||||||
|
|
Loading…
Reference in New Issue