Search in sources :

Example 1 with FirstPassGroupingCollector

use of org.apache.lucene.search.grouping.FirstPassGroupingCollector 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;
}
Also used : ValueSource(org.apache.lucene.queries.function.ValueSource) ArrayList(java.util.ArrayList) AllGroupsCollector(org.apache.lucene.search.grouping.AllGroupsCollector) Collector(org.apache.lucene.search.Collector) FirstPassGroupingCollector(org.apache.lucene.search.grouping.FirstPassGroupingCollector) ValueSourceGroupSelector(org.apache.lucene.search.grouping.ValueSourceGroupSelector) TermGroupSelector(org.apache.lucene.search.grouping.TermGroupSelector) FieldType(org.apache.solr.schema.FieldType)

Aggregations

ArrayList (java.util.ArrayList)1 ValueSource (org.apache.lucene.queries.function.ValueSource)1 Collector (org.apache.lucene.search.Collector)1 AllGroupsCollector (org.apache.lucene.search.grouping.AllGroupsCollector)1 FirstPassGroupingCollector (org.apache.lucene.search.grouping.FirstPassGroupingCollector)1 TermGroupSelector (org.apache.lucene.search.grouping.TermGroupSelector)1 ValueSourceGroupSelector (org.apache.lucene.search.grouping.ValueSourceGroupSelector)1 FieldType (org.apache.solr.schema.FieldType)1