/** * Returns a grouped facet count for the facet query * * @see FacetParams#FACET_QUERY */ public int getGroupedFacetQueryCount(Query facetQuery, DocSet docSet) throws IOException { // It is okay to retrieve group.field from global because it is never a local param String groupField = global.get(GroupParams.GROUP_FIELD); if (groupField == null) { throw new SolrException ( SolrException.ErrorCode.BAD_REQUEST, "Specify the group.field as parameter or local parameter" ); } TermAllGroupsCollector collector = new TermAllGroupsCollector(groupField); Filter mainQueryFilter = docSet.getTopFilter(); // This returns a filter that only matches documents matching with q param and fq params Query filteredFacetQuery = new BooleanQuery.Builder() .add(facetQuery, Occur.MUST) .add(mainQueryFilter, Occur.FILTER) .build(); searcher.search(filteredFacetQuery, collector); return collector.getGroupCount(); }
/** * Returns a grouped facet count for the facet query * * @see FacetParams#FACET_QUERY */ public int getGroupedFacetQueryCount(Query facetQuery) throws IOException { GroupingSpecification groupingSpecification = rb.getGroupingSpec(); String groupField = groupingSpecification != null ? groupingSpecification.getFields()[0] : null; if (groupField == null) { throw new SolrException ( SolrException.ErrorCode.BAD_REQUEST, "Specify the group.field as parameter or local parameter" ); } TermAllGroupsCollector collector = new TermAllGroupsCollector(groupField); Filter mainQueryFilter = docs.getTopFilter(); // This returns a filter that only matches documents matching with q param and fq params searcher.search(facetQuery, mainQueryFilter, collector); return collector.getGroupCount(); }
private AbstractAllGroupsCollector<?> createAllGroupsCollector(AbstractFirstPassGroupingCollector<?> firstPassGroupingCollector, String groupField) { if (firstPassGroupingCollector.getClass().isAssignableFrom(TermFirstPassGroupingCollector.class)) { return new TermAllGroupsCollector(groupField); } else { ValueSource vs = new BytesRefFieldSource(groupField); return new FunctionAllGroupsCollector(vs, new HashMap<>()); } }
/** * Returns a grouped facet count for the facet query * * @see FacetParams#FACET_QUERY */ public int getGroupedFacetQueryCount(Query facetQuery) throws IOException { String groupField = params.get(GroupParams.GROUP_FIELD); if (groupField == null) { throw new SolrException ( SolrException.ErrorCode.BAD_REQUEST, "Specify the group.field as parameter or local parameter" ); } TermAllGroupsCollector collector = new TermAllGroupsCollector(groupField); Filter mainQueryFilter = docs.getTopFilter(); // This returns a filter that only matches documents matching with q param and fq params searcher.search(facetQuery, mainQueryFilter, collector); return collector.getGroupCount(); }
@Override public List<Collector> create() throws IOException { List<Collector> collectors = new ArrayList<>(); if (topNGroups > 0) { firstPassGroupingCollector = new TermFirstPassGroupingCollector(field.getName(), groupSort, topNGroups); collectors.add(firstPassGroupingCollector); } if (includeGroupCount) { allGroupsCollector = new TermAllGroupsCollector(field.getName()); collectors.add(allGroupsCollector); } return collectors; }
private AbstractAllGroupsCollector<?> createAllGroupsCollector(AbstractFirstPassGroupingCollector<?> firstPassGroupingCollector, String groupField) { if (firstPassGroupingCollector.getClass().isAssignableFrom(TermFirstPassGroupingCollector.class)) { return new TermAllGroupsCollector(groupField); } else { ValueSource vs = new BytesRefFieldSource(groupField); return new FunctionAllGroupsCollector(vs, new HashMap<Object, Object>()); } }
@Override public List<Collector> create() throws IOException { List<Collector> collectors = new ArrayList<Collector>(); if (topNGroups > 0) { firstPassGroupingCollector = new TermFirstPassGroupingCollector(field.getName(), groupSort, topNGroups); collectors.add(firstPassGroupingCollector); } if (includeGroupCount) { allGroupsCollector = new TermAllGroupsCollector(field.getName()); collectors.add(allGroupsCollector); } return collectors; }