public TermsShortFacetCollector( String facetName, String fieldName, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, String scriptLang, String script, Map<String, Object> params) { super(facetName); this.fieldDataCache = context.fieldDataCache(); this.size = size; this.comparatorType = comparatorType; this.numberOfShards = context.numberOfShards(); MapperService.SmartNameFieldMappers smartMappers = context.mapperService().smartName(fieldName); if (smartMappers == null || !smartMappers.hasMapper()) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] doesn't have a type, can't run terms short facet collector on it"); } else { // add type filter if there is exact doc mapper associated with it if (smartMappers.hasDocMapper()) { setFilter(context.filterCache().cache(smartMappers.docMapper().typeFilter())); } if (smartMappers.mapper().fieldDataType() != FieldDataType.DefaultTypes.SHORT) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] is not of short type, can't run terms short facet collector on it"); } this.indexFieldName = smartMappers.mapper().names().indexName(); this.fieldDataType = smartMappers.mapper().fieldDataType(); } if (script != null) { this.script = new SearchScript(context.lookup(), scriptLang, script, params, context.scriptService()); } else { this.script = null; } if (this.script == null) { aggregator = new StaticAggregatorValueProc(popFacets()); } else { aggregator = new AggregatorValueProc(popFacets(), this.script); } if (allTerms) { try { for (IndexReader reader : context.searcher().subReaders()) { ShortFieldData fieldData = (ShortFieldData) fieldDataCache.cache(fieldDataType, reader, indexFieldName); fieldData.forEachValue(aggregator); } } catch (Exception e) { throw new FacetPhaseExecutionException(facetName, "failed to load all terms", e); } } }
public ReaderAggregator(ShortFieldData fieldData) { this.values = fieldData.values(); this.counts = CacheRecycler.popIntArray(fieldData.values().length); }
@Override protected void doCollect(int doc) throws IOException { fieldData.forEachValueInDoc(doc, aggregator); }
@Override protected void doCollect(int doc) throws IOException { fieldData.forEachOrdinalInDoc(doc, current); }