Skip to content

Commit

Permalink
Add standalone FQueryFilterBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
cbuescher committed May 21, 2015
1 parent a9d4fc4 commit 5418664
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,48 @@

package org.elasticsearch.index.query;

import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;

/**
* A filter that simply wraps a query. This extension of the QueryFilterBuilder only differs in the NAME constant
* that links it to a separate parser.
* A filter that simply wraps a query. This only differs from {@link QueryFilterBuilder} in that it
* takes a mandatory queryName
* @deprecated Useless now that queries and filters are merged: pass the
* query as a filter directly.
*/
@Deprecated
public class FQueryFilterBuilder extends QueryFilterBuilder {
public class FQueryFilterBuilder extends QueryBuilder<FQueryFilterBuilder> {

public static final String NAME = "fquery";

public FQueryFilterBuilder(QueryBuilder queryBuilder) {
super(queryBuilder);
private final QueryBuilder<?> queryBuilder;

private final String queryName;

/**
* A filter that simply wraps a query.
*
* @param queryBuilder The query to wrap as a filter
*/
public FQueryFilterBuilder(QueryBuilder<?> queryBuilder, String queryName) {
this.queryBuilder = queryBuilder;
this.queryName = queryName;
}

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(FQueryFilterBuilder.NAME);
builder.field("query");
queryBuilder.toXContent(builder, params);
if (queryName != null) {
builder.field("_name", queryName);
}
builder.endObject();
}

@Override
public String queryId() {
return NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,25 @@
* query as a filter directly.
*/
@Deprecated
public class QueryFilterBuilder extends QueryBuilder {
public class QueryFilterBuilder extends QueryBuilder<QueryFilterBuilder> {

public static final String NAME = "query";

private final QueryBuilder queryBuilder;

private String queryName;
private final QueryBuilder<?> queryBuilder;

/**
* A filter that simply wraps a query.
*
* @param queryBuilder The query to wrap as a filter
*/
public QueryFilterBuilder(QueryBuilder queryBuilder) {
public QueryFilterBuilder(QueryBuilder<?> queryBuilder) {
this.queryBuilder = queryBuilder;
}

/**
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
*/
public QueryFilterBuilder queryName(String queryName) {
this.queryName = queryName;
return this;
}

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
if (queryName == null) {
builder.field(NAME);
queryBuilder.toXContent(builder, params);
} else {
builder.startObject(FQueryFilterBuilder.NAME);
builder.field("query");
queryBuilder.toXContent(builder, params);
if (queryName != null) {
builder.field("_name", queryName);
}
builder.endObject();
}
}

@Override
Expand Down

0 comments on commit 5418664

Please sign in to comment.