public TermsLongOrdinalsFacetCollector( String facetName, String fieldName, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, ImmutableSet<String> excluded) { 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 long 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.LONG) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] is not of long type, can't run terms long facet collector on it"); } this.indexFieldName = smartMappers.mapper().names().indexName(); this.fieldDataType = smartMappers.mapper().fieldDataType(); } if (excluded == null || excluded.isEmpty()) { this.excluded = null; } else { this.excluded = new TLongHashSet(excluded.size()); for (String s : excluded) { this.excluded.add(Long.parseLong(s)); } } // minCount is offset by -1 if (allTerms) { minCount = -1; } else { minCount = 0; } this.aggregators = new ArrayList<ReaderAggregator>(context.searcher().subReaders().length); }
public static Query wrapSmartNameQuery( Query query, @Nullable MapperService.SmartNameFieldMappers smartFieldMappers, QueryParseContext parseContext) { if (smartFieldMappers == null) { return query; } if (!smartFieldMappers.hasDocMapper()) { return query; } DocumentMapper docMapper = smartFieldMappers.docMapper(); return new FilteredQuery(query, parseContext.cacheFilter(docMapper.typeFilter(), null)); }
public static Filter wrapSmartNameFilter( Filter filter, @Nullable MapperService.SmartNameFieldMappers smartFieldMappers, QueryParseContext parseContext) { if (smartFieldMappers == null) { return filter; } if (!smartFieldMappers.hasDocMapper()) { return filter; } DocumentMapper docMapper = smartFieldMappers.docMapper(); return new AndFilter( ImmutableList.of(parseContext.cacheFilter(docMapper.typeFilter(), null), filter)); }
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); } } }