use of org.apache.lucene.search.grouping.AllGroupsCollector in project lucene-solr by apache.
the class SimpleFacets method getGroupedFacetQueryCount.
/**
* 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");
}
AllGroupsCollector collector = new AllGroupsCollector<>(new TermGroupSelector(groupField));
// This returns a filter that only matches documents matching with q param and fq params
Filter mainQueryFilter = docSet.getTopFilter();
Query filteredFacetQuery = new BooleanQuery.Builder().add(facetQuery, Occur.MUST).add(mainQueryFilter, Occur.FILTER).build();
searcher.search(filteredFacetQuery, collector);
return collector.getGroupCount();
}
use of org.apache.lucene.search.grouping.AllGroupsCollector in project lucene-solr by apache.
the class SearchGroupsFieldCommand method create.
@Override
public List<Collector> create() throws IOException {
final List<Collector> collectors = new ArrayList<>(2);
final FieldType fieldType = field.getType();
if (topNGroups > 0) {
if (fieldType.getNumberType() != null) {
ValueSource vs = fieldType.getValueSource(field, null);
firstPassGroupingCollector = new FirstPassGroupingCollector<>(new ValueSourceGroupSelector(vs, new HashMap<>()), groupSort, topNGroups);
} else {
firstPassGroupingCollector = new FirstPassGroupingCollector<>(new TermGroupSelector(field.getName()), groupSort, topNGroups);
}
collectors.add(firstPassGroupingCollector);
}
if (includeGroupCount) {
if (fieldType.getNumberType() != null) {
ValueSource vs = fieldType.getValueSource(field, null);
allGroupsCollector = new AllGroupsCollector<>(new ValueSourceGroupSelector(vs, new HashMap<>()));
} else {
allGroupsCollector = new AllGroupsCollector<>(new TermGroupSelector(field.getName()));
}
collectors.add(allGroupsCollector);
}
return collectors;
}
Aggregations