From 090132233707ae88966bf5b8d067f776ef9f7727 Mon Sep 17 00:00:00 2001 From: kimchy Date: Fri, 4 Jun 2010 07:03:30 +0300 Subject: [PATCH] rename field facet to term facet --- .../action/search/SearchRequestBuilder.java | 8 ++-- .../builder/SearchSourceFacetsBuilder.java | 40 ++++++++++--------- .../search/facets/FacetsParseElement.java | 6 +-- .../query/QueryFacetCollectorParser.java | 2 + .../TermFacetCollector.java} | 6 +-- .../TermFacetCollectorParser.java} | 12 +++--- .../search/facets/SimpleFacetsTests.java | 4 +- 7 files changed, 42 insertions(+), 36 deletions(-) rename modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/{field/FieldFacetCollector.java => term/TermFacetCollector.java} (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/{field/FieldFacetCollectorParser.java => term/TermFacetCollectorParser.java} (84%) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/search/SearchRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/search/SearchRequestBuilder.java index 3a907655ae4..5017eb54f78 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/search/SearchRequestBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/search/SearchRequestBuilder.java @@ -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; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceFacetsBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceFacetsBuilder.java index e492ef7d8a9..05b4b4dbe55 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceFacetsBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceFacetsBuilder.java @@ -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 queryFacets; - private List fieldFacets; + private List 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; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsParseElement.java index 8c6839fc653..a016bb0675e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsParseElement.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsParseElement.java @@ -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 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(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/query/QueryFacetCollectorParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/query/QueryFacetCollectorParser.java index ccf4a901938..32df9cec8c7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/query/QueryFacetCollectorParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/query/QueryFacetCollectorParser.java @@ -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"; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/field/FieldFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/term/TermFacetCollector.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/field/FieldFacetCollector.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/term/TermFacetCollector.java index d85507061fe..3a6949132fa 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/field/FieldFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/term/TermFacetCollector.java @@ -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>>> cache = new ThreadLocal>>>() { @Override protected ThreadLocals.CleanableValue>> initialValue() { @@ -63,7 +63,7 @@ public class FieldFacetCollector extends FacetCollector { private final TObjectIntHashMap 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; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/field/FieldFacetCollectorParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/term/TermFacetCollectorParser.java similarity index 84% rename from modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/field/FieldFacetCollectorParser.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/term/TermFacetCollectorParser.java index c9f6bdb8122..38d88a36ea8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/field/FieldFacetCollectorParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/term/TermFacetCollectorParser.java @@ -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); } } diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/facets/SimpleFacetsTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/facets/SimpleFacetsTests.java index 2c9e4880335..275d09fcc28 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/facets/SimpleFacetsTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/facets/SimpleFacetsTests.java @@ -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 facet = (MultiCountFacet) searchResponse.facets().facet("facet1");