1
package org.apache.lucene.search.grouping;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
20
import java.io.IOException;
21
import java.util.Collection;
23
import org.apache.lucene.index.IndexReader;
24
import org.apache.lucene.search.FieldCache;
25
import org.apache.lucene.search.Sort;
28
* Concrete implementation of {@link AbstractSecondPassGroupingCollector} that groups based on
29
* field values and more specifically uses {@link org.apache.lucene.search.FieldCache.StringIndex}
30
* to collect grouped docs.
32
* @lucene.experimental
34
public class TermSecondPassGroupingCollector extends AbstractSecondPassGroupingCollector<String> {
36
private final SentinelIntSet ordSet;
37
private FieldCache.StringIndex index;
38
private final String groupField;
40
@SuppressWarnings("unchecked")
41
public TermSecondPassGroupingCollector(String groupField, Collection<SearchGroup<String>> groups, Sort groupSort, Sort withinGroupSort,
42
int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields)
44
super(groups, groupSort, withinGroupSort, maxDocsPerGroup, getScores, getMaxScores, fillSortFields);
45
ordSet = new SentinelIntSet(groupMap.size(), -1);
46
this.groupField = groupField;
47
groupDocs = (SearchGroupDocs<String>[]) new SearchGroupDocs[ordSet.keys.length];
51
public void setNextReader(IndexReader reader, int docBase) throws IOException {
52
super.setNextReader(reader, docBase);
53
index = FieldCache.DEFAULT.getStringIndex(reader, groupField);
57
for (SearchGroupDocs<String> group : groupMap.values()) {
58
// System.out.println(" group=" + (group.groupValue == null ? "null" : group.groupValue.utf8ToString()));
59
int ord = group.groupValue == null ? 0 : index.binarySearchLookup(group.groupValue);
61
groupDocs[ordSet.put(ord)] = group;
67
protected SearchGroupDocs<String> retrieveGroup(int doc) throws IOException {
68
int slot = ordSet.find(index.order[doc]);
70
return groupDocs[slot];
b'\\ No newline at end of file'