rename field facet to term facet
This commit is contained in:
parent
6e15e3dd24
commit
0901322337
|
@ -272,13 +272,13 @@ public class SearchRequestBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public SearchRequestBuilder addFieldFacet(String name, String fieldName, int size) {
|
||||
facetsBuilder().fieldFacet(name, fieldName, size);
|
||||
public SearchRequestBuilder addTermFacet(String name, String fieldName, int size) {
|
||||
facetsBuilder().termFacet(name, fieldName, size);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SearchRequestBuilder addFieldFacet(String name, String fieldName, int size, boolean global) {
|
||||
facetsBuilder().fieldFacet(name, fieldName, size, global);
|
||||
public SearchRequestBuilder addTermFacet(String name, String fieldName, int size, boolean global) {
|
||||
facetsBuilder().termFacet(name, fieldName, size, global);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
package org.elasticsearch.search.builder;
|
||||
|
||||
import org.elasticsearch.index.query.xcontent.XContentQueryBuilder;
|
||||
import org.elasticsearch.search.facets.collector.query.QueryFacetCollectorParser;
|
||||
import org.elasticsearch.search.facets.collector.term.TermFacetCollectorParser;
|
||||
import org.elasticsearch.util.xcontent.ToXContent;
|
||||
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
|
||||
|
||||
|
@ -37,7 +39,7 @@ import static org.elasticsearch.util.collect.Lists.*;
|
|||
public class SearchSourceFacetsBuilder implements ToXContent {
|
||||
|
||||
private List<QueryFacet> queryFacets;
|
||||
private List<FieldFacet> fieldFacets;
|
||||
private List<TermFacet> termFacets;
|
||||
|
||||
/**
|
||||
* Adds a query facet (which results in a count facet returned).
|
||||
|
@ -65,20 +67,20 @@ public class SearchSourceFacetsBuilder implements ToXContent {
|
|||
return this;
|
||||
}
|
||||
|
||||
public SearchSourceFacetsBuilder fieldFacet(String name, String fieldName, int size) {
|
||||
return fieldFacet(name, fieldName, size, null);
|
||||
public SearchSourceFacetsBuilder termFacet(String name, String fieldName, int size) {
|
||||
return termFacet(name, fieldName, size, null);
|
||||
}
|
||||
|
||||
public SearchSourceFacetsBuilder fieldFacet(String name, String fieldName, int size, Boolean global) {
|
||||
if (fieldFacets == null) {
|
||||
fieldFacets = newArrayListWithCapacity(2);
|
||||
public SearchSourceFacetsBuilder termFacet(String name, String fieldName, int size, Boolean global) {
|
||||
if (termFacets == null) {
|
||||
termFacets = newArrayListWithCapacity(2);
|
||||
}
|
||||
fieldFacets.add(new FieldFacet(name, fieldName, size, global));
|
||||
termFacets.add(new TermFacet(name, fieldName, size, global));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
if (queryFacets == null && fieldFacets == null) {
|
||||
if (queryFacets == null && termFacets == null) {
|
||||
return;
|
||||
}
|
||||
builder.field("facets");
|
||||
|
@ -88,7 +90,7 @@ public class SearchSourceFacetsBuilder implements ToXContent {
|
|||
if (queryFacets != null) {
|
||||
for (QueryFacet queryFacet : queryFacets) {
|
||||
builder.startObject(queryFacet.name());
|
||||
builder.field("query");
|
||||
builder.field(QueryFacetCollectorParser.NAME);
|
||||
queryFacet.queryBuilder().toXContent(builder, params);
|
||||
if (queryFacet.global() != null) {
|
||||
builder.field("global", queryFacet.global());
|
||||
|
@ -96,17 +98,17 @@ public class SearchSourceFacetsBuilder implements ToXContent {
|
|||
builder.endObject();
|
||||
}
|
||||
}
|
||||
if (fieldFacets != null) {
|
||||
for (FieldFacet fieldFacet : fieldFacets) {
|
||||
builder.startObject(fieldFacet.name());
|
||||
if (termFacets != null) {
|
||||
for (TermFacet termFacet : termFacets) {
|
||||
builder.startObject(termFacet.name());
|
||||
|
||||
builder.startObject("field");
|
||||
builder.field("name", fieldFacet.fieldName());
|
||||
builder.field("size", fieldFacet.size());
|
||||
builder.startObject(TermFacetCollectorParser.NAME);
|
||||
builder.field("field", termFacet.fieldName());
|
||||
builder.field("size", termFacet.size());
|
||||
builder.endObject();
|
||||
|
||||
if (fieldFacet.global() != null) {
|
||||
builder.field("global", fieldFacet.global());
|
||||
if (termFacet.global() != null) {
|
||||
builder.field("global", termFacet.global());
|
||||
}
|
||||
|
||||
builder.endObject();
|
||||
|
@ -116,13 +118,13 @@ public class SearchSourceFacetsBuilder implements ToXContent {
|
|||
builder.endObject();
|
||||
}
|
||||
|
||||
private static class FieldFacet {
|
||||
private static class TermFacet {
|
||||
private final String name;
|
||||
private final String fieldName;
|
||||
private final int size;
|
||||
private final Boolean global;
|
||||
|
||||
private FieldFacet(String name, String fieldName, int size, Boolean global) {
|
||||
private TermFacet(String name, String fieldName, int size, Boolean global) {
|
||||
this.name = name;
|
||||
this.fieldName = fieldName;
|
||||
this.size = size;
|
||||
|
|
|
@ -23,8 +23,8 @@ import org.elasticsearch.search.SearchParseElement;
|
|||
import org.elasticsearch.search.SearchParseException;
|
||||
import org.elasticsearch.search.facets.collector.FacetCollector;
|
||||
import org.elasticsearch.search.facets.collector.FacetCollectorParser;
|
||||
import org.elasticsearch.search.facets.collector.field.FieldFacetCollectorParser;
|
||||
import org.elasticsearch.search.facets.collector.query.QueryFacetCollectorParser;
|
||||
import org.elasticsearch.search.facets.collector.term.TermFacetCollectorParser;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.util.MapBuilder;
|
||||
import org.elasticsearch.util.collect.ImmutableMap;
|
||||
|
@ -60,8 +60,8 @@ public class FacetsParseElement implements SearchParseElement {
|
|||
|
||||
public FacetsParseElement() {
|
||||
MapBuilder<String, FacetCollectorParser> builder = newMapBuilder();
|
||||
builder.put("field", new FieldFacetCollectorParser());
|
||||
builder.put("query", new QueryFacetCollectorParser());
|
||||
builder.put(TermFacetCollectorParser.NAME, new TermFacetCollectorParser());
|
||||
builder.put(QueryFacetCollectorParser.NAME, new QueryFacetCollectorParser());
|
||||
this.facetCollectorParsers = builder.immutableMap();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@ import org.elasticsearch.util.xcontent.XContentParser;
|
|||
*/
|
||||
public class QueryFacetCollectorParser implements FacetCollectorParser {
|
||||
|
||||
public static final String NAME = "query";
|
||||
|
||||
@Override public String name() {
|
||||
return "query";
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.facets.collector.field;
|
||||
package org.elasticsearch.search.facets.collector.term;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
|
@ -42,7 +42,7 @@ import static org.elasticsearch.index.field.FieldDataOptions.*;
|
|||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class FieldFacetCollector extends FacetCollector {
|
||||
public class TermFacetCollector extends FacetCollector {
|
||||
|
||||
private static ThreadLocal<ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>>> cache = new ThreadLocal<ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>>>() {
|
||||
@Override protected ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>> initialValue() {
|
||||
|
@ -63,7 +63,7 @@ public class FieldFacetCollector extends FacetCollector {
|
|||
|
||||
private final TObjectIntHashMap<String> facets;
|
||||
|
||||
public FieldFacetCollector(String name, String fieldName, FieldDataCache fieldDataCache, int size) {
|
||||
public TermFacetCollector(String name, String fieldName, FieldDataCache fieldDataCache, int size) {
|
||||
this.name = name;
|
||||
this.fieldDataCache = fieldDataCache;
|
||||
this.fieldName = fieldName;
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.facets.collector.field;
|
||||
package org.elasticsearch.search.facets.collector.term;
|
||||
|
||||
import org.elasticsearch.search.facets.collector.FacetCollector;
|
||||
import org.elasticsearch.search.facets.collector.FacetCollectorParser;
|
||||
|
@ -29,10 +29,12 @@ import java.io.IOException;
|
|||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class FieldFacetCollectorParser implements FacetCollectorParser {
|
||||
public class TermFacetCollectorParser implements FacetCollectorParser {
|
||||
|
||||
public static final String NAME = "term";
|
||||
|
||||
@Override public String name() {
|
||||
return "field";
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override public FacetCollector parser(String facetName, XContentParser parser, SearchContext context) throws IOException {
|
||||
|
@ -45,13 +47,13 @@ public class FieldFacetCollectorParser implements FacetCollectorParser {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
termFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if ("name".equals(termFieldName)) {
|
||||
if ("field".equals(termFieldName)) {
|
||||
field = parser.text();
|
||||
} else if ("size".equals(termFieldName)) {
|
||||
size = parser.intValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return new FieldFacetCollector(facetName, field, context.fieldDataCache(), size);
|
||||
return new TermFacetCollector(facetName, field, context.fieldDataCache(), size);
|
||||
}
|
||||
}
|
|
@ -76,8 +76,8 @@ public class SimpleFacetsTests extends AbstractNodesTests {
|
|||
|
||||
SearchResponse searchResponse = client.prepareSearch()
|
||||
.setQuery(termQuery("stag", "111"))
|
||||
.addFieldFacet("facet1", "stag", 10)
|
||||
.addFieldFacet("facet2", "tag", 10)
|
||||
.addTermFacet("facet1", "stag", 10)
|
||||
.addTermFacet("facet2", "tag", 10)
|
||||
.execute().actionGet();
|
||||
|
||||
MultiCountFacet<String> facet = (MultiCountFacet<String>) searchResponse.facets().facet("facet1");
|
||||
|
|
Loading…
Reference in New Issue