have terms filter builder support iterables as well

This commit is contained in:
Shay Banon 2012-01-18 21:34:33 +02:00
parent 5325bf4bec
commit 5beb656a16
2 changed files with 27 additions and 24 deletions

View File

@ -23,8 +23,6 @@ import org.elasticsearch.common.Nullable;
/**
* A static factory for simple "import static" usage.
*
*
*/
public abstract class FilterBuilders {
@ -186,6 +184,16 @@ public abstract class FilterBuilders {
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.
*

View File

@ -30,7 +30,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
private final String name;
private final Object[] values;
private final Object values;
private Boolean cache;
private String cacheKey;
@ -57,10 +57,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
*/
public TermsFilterBuilder(String name, int... values) {
this.name = name;
this.values = new Integer[values.length];
for (int i = 0; i < values.length; i++) {
this.values[i] = values[i];
}
this.values = values;
}
/**
@ -71,10 +68,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
*/
public TermsFilterBuilder(String name, long... values) {
this.name = name;
this.values = new Long[values.length];
for (int i = 0; i < values.length; i++) {
this.values[i] = values[i];
}
this.values = values;
}
/**
@ -85,10 +79,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
*/
public TermsFilterBuilder(String name, float... values) {
this.name = name;
this.values = new Float[values.length];
for (int i = 0; i < values.length; i++) {
this.values[i] = values[i];
}
this.values = values;
}
/**
@ -99,10 +90,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
*/
public TermsFilterBuilder(String name, double... values) {
this.name = name;
this.values = new Double[values.length];
for (int i = 0; i < values.length; i++) {
this.values[i] = values[i];
}
this.values = values;
}
/**
@ -116,6 +104,17 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
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"
* "and". Defaults to "plain".
@ -149,11 +148,7 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
@Override
public void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(TermsFilterParser.NAME);
builder.startArray(name);
for (Object value : values) {
builder.value(value);
}
builder.endArray();
builder.field(name, values);
if (execution != null) {
builder.field("execution", execution);