Search in sources :

Example 21 with Collector

use of org.apache.lucene.search.Collector in project lucene-solr by apache.

the class TopGroupsFieldCommand method create.

@Override
public List<Collector> create() throws IOException {
    if (firstPhaseGroups.isEmpty()) {
        return Collections.emptyList();
    }
    final List<Collector> collectors = new ArrayList<>(1);
    final FieldType fieldType = field.getType();
    if (fieldType.getNumberType() != null) {
        ValueSource vs = fieldType.getValueSource(field, null);
        Collection<SearchGroup<MutableValue>> v = GroupConverter.toMutable(field, firstPhaseGroups);
        secondPassCollector = new TopGroupsCollector<>(new ValueSourceGroupSelector(vs, new HashMap<>()), v, groupSort, withinGroupSort, maxDocPerGroup, needScores, needMaxScore, true);
    } else {
        secondPassCollector = new TopGroupsCollector<>(new TermGroupSelector(field.getName()), firstPhaseGroups, groupSort, withinGroupSort, maxDocPerGroup, needScores, needMaxScore, true);
    }
    collectors.add(secondPassCollector);
    return collectors;
}
Also used : SearchGroup(org.apache.lucene.search.grouping.SearchGroup) ValueSource(org.apache.lucene.queries.function.ValueSource) ArrayList(java.util.ArrayList) Collector(org.apache.lucene.search.Collector) TopGroupsCollector(org.apache.lucene.search.grouping.TopGroupsCollector) ValueSourceGroupSelector(org.apache.lucene.search.grouping.ValueSourceGroupSelector) TermGroupSelector(org.apache.lucene.search.grouping.TermGroupSelector) FieldType(org.apache.solr.schema.FieldType)

Aggregations

Collector (org.apache.lucene.search.Collector)21 ArrayList (java.util.ArrayList)11 IndexSearcher (org.apache.lucene.search.IndexSearcher)10 Query (org.apache.lucene.search.Query)8 IOException (java.io.IOException)6 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)6 MultiCollector (org.apache.lucene.search.MultiCollector)6 Sort (org.apache.lucene.search.Sort)6 TopFieldCollector (org.apache.lucene.search.TopFieldCollector)6 Document (org.apache.lucene.document.Document)5 BytesRef (org.apache.lucene.util.BytesRef)5 HashMap (java.util.HashMap)4 StringField (org.apache.lucene.document.StringField)4 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 LeafCollector (org.apache.lucene.search.LeafCollector)4 ScoreDoc (org.apache.lucene.search.ScoreDoc)4 Directory (org.apache.lucene.store.Directory)4 HashSet (java.util.HashSet)3 List (java.util.List)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3