Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added base class for collector

  • Loading branch information...
commit 1e2b4ed1faea883da5d33fe6eb03c7dbf54e9ef4 1 parent adf2fe1
@quodt quodt authored
View
20 src/main/java/com/lovelysystems/facet/latest/IntLatestFacetCollector.java
@@ -21,15 +21,7 @@
import org.elasticsearch.search.facet.Facet;
import org.elasticsearch.search.internal.SearchContext;
-public class IntLatestFacetCollector extends AbstractFacetCollector {
-
- static ThreadLocal<ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>>> cache = new ThreadLocal<ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>>>() {
- @Override
- protected ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>> initialValue() {
- return new ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<java.lang.String>>>(
- new ArrayDeque<TObjectIntHashMap<String>>());
- }
- };
+public class IntLatestFacetCollector extends LatestFacetCollector {
private final FieldDataCache fieldDataCache;
@@ -37,20 +29,10 @@
private final String valueFieldName;
private final String tsFieldName;
- public static final FieldDataType keyDataType = FieldDataType.DefaultTypes.LONG;
public static final FieldDataType valueDataType = FieldDataType.DefaultTypes.INT;
- public static final FieldDataType tsDataType = FieldDataType.DefaultTypes.LONG;
-
- private LongFieldData keyFieldData;
private final Aggregator aggregator;
- private final int limit = 10;
- private int size = 10;
- private int start = 0;
-
- private final Set<String> names = new HashSet<String>();
-
public IntLatestFacetCollector(String facetName, String keyField,
String valueField, String tsField, int size, int start,
SearchContext context) {
View
48 src/main/java/com/lovelysystems/facet/latest/LatestFacetCollector.java
@@ -0,0 +1,48 @@
+package com.lovelysystems.facet.latest;
+
+import org.apache.lucene.index.IndexReader;
+import org.elasticsearch.common.CacheRecycler;
+import org.elasticsearch.common.thread.ThreadLocals;
+import org.elasticsearch.common.trove.ExtTLongObjectHashMap;
+import org.elasticsearch.common.trove.map.hash.TObjectIntHashMap;
+import org.elasticsearch.index.cache.field.data.FieldDataCache;
+import org.elasticsearch.index.field.data.FieldDataType;
+import org.elasticsearch.index.field.data.NumericFieldData.LongValueInDocProc;
+import org.elasticsearch.index.field.data.longs.LongFieldData;
+import org.elasticsearch.index.mapper.MapperService;
+import org.elasticsearch.search.facet.AbstractFacetCollector;
+import org.elasticsearch.search.facet.Facet;
+import org.elasticsearch.search.internal.SearchContext;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.Set;
+
+public abstract class LatestFacetCollector extends AbstractFacetCollector {
+
+ static ThreadLocal<ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>>> cache = new ThreadLocal<ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>>>() {
+ @Override
+ protected ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>> initialValue() {
+ return new ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>>(
+ new ArrayDeque<TObjectIntHashMap<String>>());
+ }
+ };
+
+ public static final FieldDataType keyDataType = FieldDataType.DefaultTypes.LONG;
+ public static final FieldDataType tsDataType = FieldDataType.DefaultTypes.LONG;
+
+ protected LongFieldData keyFieldData;
+
+ protected final int limit = 10;
+ protected int size = 10;
+ protected int start = 0;
+
+ protected final Set<String> names = new HashSet<String>();
+
+
+ public LatestFacetCollector(String facetName) {
+ super(facetName);
+ }
+}
View
4 src/main/java/com/lovelysystems/facet/latest/LatestFacetProcessor.java
@@ -62,7 +62,7 @@ public FacetCollector parse(String facetName, XContentParser parser,
FieldMapper fieldMapper = context.mapperService().smartNameFieldMapper(
keyField);
if ((fieldMapper != null)
- && (fieldMapper.fieldDataType() != IntLatestFacetCollector.keyDataType)) {
+ && (fieldMapper.fieldDataType() != LatestFacetCollector.keyDataType)) {
throw new FacetPhaseExecutionException(facetName,
"key field must be of type long but is "
+ fieldMapper.fieldDataType());
@@ -70,7 +70,7 @@ public FacetCollector parse(String facetName, XContentParser parser,
fieldMapper = context.mapperService().smartNameFieldMapper(tsField);
if ((fieldMapper != null)
- && (fieldMapper.fieldDataType() != IntLatestFacetCollector.tsDataType)) {
+ && (fieldMapper.fieldDataType() != LatestFacetCollector.tsDataType)) {
throw new FacetPhaseExecutionException(facetName,
"ts field must be of type long but is "
+ fieldMapper.fieldDataType());
View
18 src/main/java/com/lovelysystems/facet/latest/LongLatestFacetCollector.java
@@ -20,15 +20,7 @@
import org.elasticsearch.search.facet.Facet;
import org.elasticsearch.search.internal.SearchContext;
-public class LongLatestFacetCollector extends AbstractFacetCollector {
-
- static ThreadLocal<ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>>> cache = new ThreadLocal<ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>>>() {
- @Override
- protected ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<String>>> initialValue() {
- return new ThreadLocals.CleanableValue<Deque<TObjectIntHashMap<java.lang.String>>>(
- new ArrayDeque<TObjectIntHashMap<String>>());
- }
- };
+public class LongLatestFacetCollector extends LatestFacetCollector {
private final FieldDataCache fieldDataCache;
@@ -36,20 +28,12 @@
private final String valueFieldName;
private final String tsFieldName;
- public static final FieldDataType keyDataType = FieldDataType.DefaultTypes.LONG;
public static final FieldDataType valueDataType = FieldDataType.DefaultTypes.LONG;
- public static final FieldDataType tsDataType = FieldDataType.DefaultTypes.LONG;
private LongFieldData keyFieldData;
private final Aggregator aggregator;
- private final int limit = 10;
- private int size = 10;
- private int start = 0;
-
- private final Set<String> names = new HashSet<String>();
-
public LongLatestFacetCollector(String facetName, String keyField,
String valueField, String tsField, int size, int start,
SearchContext context) {
Please sign in to comment.
Something went wrong with that request. Please try again.