add the option to control filter caching on each filter in the java filter builders

This commit is contained in:
kimchy 2010-10-16 16:12:38 +02:00
parent d9f966d83c
commit 4708d31040
14 changed files with 180 additions and 8 deletions

View File

@ -53,7 +53,7 @@ public class AndFilterBuilder extends BaseFilterBuilder {
}
/**
* Should the inner filters be cached or not. Defaults to <tt>true</tt>.
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public AndFilterBuilder cache(boolean cache) {
this.cache = cache;

View File

@ -34,6 +34,8 @@ public class BoolFilterBuilder extends BaseFilterBuilder {
private ArrayList<Clause> clauses = new ArrayList<Clause>();
private Boolean cache;
private String filterName;
/**
@ -70,6 +72,14 @@ public class BoolFilterBuilder extends BaseFilterBuilder {
return this;
}
/**
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public BoolFilterBuilder cache(boolean cache) {
this.cache = cache;
return this;
}
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("bool");
for (Clause clause : clauses) {
@ -87,6 +97,9 @@ public class BoolFilterBuilder extends BaseFilterBuilder {
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
builder.endObject();
}

View File

@ -40,6 +40,8 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
private String bottomRightGeohash;
private Boolean cache;
private String filterName;
public GeoBoundingBoxFilterBuilder(String name) {
@ -78,6 +80,14 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
return this;
}
/**
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public GeoBoundingBoxFilterBuilder cache(boolean cache) {
this.cache = cache;
return this;
}
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(GeoBoundingBoxFilterParser.NAME);
@ -102,6 +112,9 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
builder.endObject();
}

View File

@ -42,6 +42,8 @@ public class GeoDistanceFilterBuilder extends BaseFilterBuilder {
private GeoDistance geoDistance;
private Boolean cache;
private String filterName;
public GeoDistanceFilterBuilder(String name) {
@ -84,11 +86,22 @@ public class GeoDistanceFilterBuilder extends BaseFilterBuilder {
return this;
}
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public GeoDistanceFilterBuilder filterName(String filterName) {
this.filterName = filterName;
return this;
}
/**
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public GeoDistanceFilterBuilder cache(boolean cache) {
this.cache = cache;
return this;
}
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(GeoDistanceFilterParser.NAME);
if (geohash != null) {
@ -103,6 +116,9 @@ public class GeoDistanceFilterBuilder extends BaseFilterBuilder {
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
builder.endObject();
}
}

View File

@ -36,6 +36,8 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder {
private final List<GeoPolygonFilter.Point> points = Lists.newArrayList();
private Boolean cache;
private String filterName;
public GeoPolygonFilterBuilder(String name) {
@ -52,11 +54,22 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder {
return addPoint(values[0], values[1]);
}
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public GeoPolygonFilterBuilder filterName(String filterName) {
this.filterName = filterName;
return this;
}
/**
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public GeoPolygonFilterBuilder cache(boolean cache) {
this.cache = cache;
return this;
}
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(GeoPolygonFilterParser.NAME);
@ -71,6 +84,9 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder {
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
builder.endObject();
}

View File

@ -41,7 +41,7 @@ public class NotFilterBuilder extends BaseFilterBuilder {
}
/**
* Should the inner filter be cached or not. Defaults to <tt>true</tt>.
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public NotFilterBuilder cache(boolean cache) {
this.cache = cache;

View File

@ -42,6 +42,8 @@ public class NumericRangeFilterBuilder extends BaseFilterBuilder {
private boolean includeUpper = true;
private Boolean cache;
private String filterName;
/**
@ -329,11 +331,22 @@ public class NumericRangeFilterBuilder extends BaseFilterBuilder {
return this;
}
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public NumericRangeFilterBuilder filterName(String filterName) {
this.filterName = filterName;
return this;
}
/**
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public NumericRangeFilterBuilder cache(boolean cache) {
this.cache = cache;
return this;
}
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(NumericRangeFilterParser.NAME);
@ -347,6 +360,9 @@ public class NumericRangeFilterBuilder extends BaseFilterBuilder {
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
builder.endObject();
}

View File

@ -53,7 +53,7 @@ public class OrFilterBuilder extends BaseFilterBuilder {
}
/**
* Should the inner filters be cached or not. Defaults to <tt>true</tt>.
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public OrFilterBuilder cache(boolean cache) {
this.cache = cache;

View File

@ -35,6 +35,8 @@ public class PrefixFilterBuilder extends BaseFilterBuilder {
private final String prefix;
private Boolean cache;
private String filterName;
/**
@ -49,17 +51,31 @@ public class PrefixFilterBuilder extends BaseFilterBuilder {
this.prefix = prefix;
}
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public PrefixFilterBuilder filterName(String filterName) {
this.filterName = filterName;
return this;
}
/**
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public PrefixFilterBuilder cache(boolean cache) {
this.cache = cache;
return this;
}
@Override public void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(PrefixFilterParser.NAME);
builder.field(name, prefix);
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
builder.endObject();
}
}

View File

@ -32,6 +32,8 @@ public class QueryFilterBuilder extends BaseFilterBuilder {
private final XContentQueryBuilder queryBuilder;
private Boolean cache;
private String filterName;
/**
@ -43,20 +45,36 @@ public class QueryFilterBuilder extends BaseFilterBuilder {
this.queryBuilder = queryBuilder;
}
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public QueryFilterBuilder filterName(String filterName) {
this.filterName = filterName;
return this;
}
/**
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public QueryFilterBuilder cache(boolean cache) {
this.cache = cache;
return this;
}
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException {
if (filterName != null) {
if (filterName == null && cache == null) {
builder.field(QueryFilterParser.NAME);
queryBuilder.toXContent(builder, params);
} else {
builder.startObject(FQueryFilterParser.NAME);
builder.field("query");
queryBuilder.toXContent(builder, params);
builder.field("_name", filterName);
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
builder.endObject();
}
}

View File

@ -40,6 +40,8 @@ public class RangeFilterBuilder extends BaseFilterBuilder {
private boolean includeUpper = true;
private Boolean cache;
private String filterName;
/**
@ -327,11 +329,22 @@ public class RangeFilterBuilder extends BaseFilterBuilder {
return this;
}
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public RangeFilterBuilder filterName(String filterName) {
this.filterName = filterName;
return this;
}
/**
* Should the filter be cached or not. Defaults to <tt>true</tt>.
*/
public RangeFilterBuilder cache(boolean cache) {
this.cache = cache;
return this;
}
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(RangeFilterParser.NAME);
@ -345,6 +358,9 @@ public class RangeFilterBuilder extends BaseFilterBuilder {
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
builder.endObject();
}

View File

@ -37,6 +37,8 @@ public class ScriptFilterBuilder extends BaseFilterBuilder {
private String lang;
private Boolean cache;
private String filterName;
public ScriptFilterBuilder(String script) {
@ -60,16 +62,27 @@ public class ScriptFilterBuilder extends BaseFilterBuilder {
return this;
}
/**
* Sets the script language.
*/
public ScriptFilterBuilder lang(String lang) {
this.lang = lang;
return this;
}
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public ScriptFilterBuilder filterName(String filterName) {
this.filterName = filterName;
return this;
}
/**
* Sets the script language.
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public ScriptFilterBuilder lang(String lang) {
this.lang = lang;
public ScriptFilterBuilder cache(boolean cache) {
this.cache = cache;
return this;
}
@ -85,6 +98,9 @@ public class ScriptFilterBuilder extends BaseFilterBuilder {
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
builder.endObject();
}
}

View File

@ -34,6 +34,8 @@ public class TermFilterBuilder extends BaseFilterBuilder {
private final Object value;
private Boolean cache;
private String filterName;
/**
@ -97,17 +99,31 @@ public class TermFilterBuilder extends BaseFilterBuilder {
this.value = value;
}
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public TermFilterBuilder filterName(String filterName) {
this.filterName = filterName;
return this;
}
/**
* Should the filter be cached or not. Defaults to <tt>true</tt>.
*/
public TermFilterBuilder cache(boolean cache) {
this.cache = cache;
return this;
}
@Override public void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(TermFilterParser.NAME);
builder.field(name, value);
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
builder.endObject();
}
}

View File

@ -34,6 +34,8 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
private final Object[] values;
private Boolean cache;
private String filterName;
/**
@ -113,11 +115,22 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
this.values = values;
}
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
public TermsFilterBuilder filterName(String filterName) {
this.filterName = filterName;
return this;
}
/**
* Should the filter be cached or not. Defaults to <tt>false</tt>.
*/
public TermsFilterBuilder cache(boolean cache) {
this.cache = cache;
return this;
}
@Override public void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(TermsFilterParser.NAME);
builder.startArray(name);
@ -129,6 +142,9 @@ public class TermsFilterBuilder extends BaseFilterBuilder {
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
builder.endObject();
}