javanna commented on code in PR #15565:
URL: https://github.com/apache/lucene/pull/15565#discussion_r3154248268
##########
lucene/grouping/src/java/org/apache/lucene/search/grouping/AllGroupHeadsCollector.java:
##########
@@ -232,40 +258,60 @@ protected void setNextReader(LeafReaderContext ctx)
throws IOException {
* @throws IOException If I/O related errors occur
*/
protected abstract void updateDocHead(int doc) throws IOException;
+
+ /**
+ * Returns the sort values for this group head.
+ *
+ * @return the sort values, or null if not stored
+ */
+ protected Object[] getSortValues() {
+ return null;
Review Comment:
Also, is there any type correlation between sort values and the group value?
##########
lucene/CHANGES.txt:
##########
@@ -304,6 +304,8 @@ Improvements
* GITHUB#15574: Introduce TopGroupsCollectorManager to parallelize search when
using TopGroupsCollector. (Binlong Gao)
+* GITHUB#15565: Introduce AllGroupHeadsCollectorManager to parallelize search
when using AllGroupHeadsCollector. (Binlong Gao)
Review Comment:
please move this to the 10.5 section?
##########
lucene/grouping/src/java/org/apache/lucene/search/grouping/AllGroupHeadsCollector.java:
##########
@@ -45,6 +45,7 @@ public abstract class AllGroupHeadsCollector<T> extends
SimpleCollector {
private final GroupSelector<T> groupSelector;
protected final Sort sort;
+ protected final boolean fillSortValues;
Review Comment:
I wonder if this belongs in the new collector manager or in the collector
instances. Could we have mixed values for the different collectors created by
the same collector manager?
##########
lucene/grouping/src/java/org/apache/lucene/search/grouping/AllGroupHeadsCollectorManager.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.search.grouping;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Supplier;
+import org.apache.lucene.search.CollectorManager;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.FixedBitSet;
+
+/**
+ * A CollectorManager implementation for AllGroupHeadsCollector.
+ *
+ * @lucene.experimental
+ */
+public class AllGroupHeadsCollectorManager<T>
+ implements CollectorManager<
+ AllGroupHeadsCollector<T>,
AllGroupHeadsCollectorManager.GroupHeadsResult> {
+
+ /** Result wrapper that allows retrieving group heads as int[] or Bits. */
+ public static class GroupHeadsResult {
+ private final int[] groupHeads;
+
+ GroupHeadsResult(int[] groupHeads) {
+ this.groupHeads = groupHeads;
+ }
+
+ public int[] retrieveGroupHeads() {
+ return groupHeads;
+ }
+
+ public Bits retrieveGroupHeads(int maxDoc) {
+ FixedBitSet result = new FixedBitSet(maxDoc);
+ for (int docId : groupHeads) {
+ result.set(docId);
+ }
+ return result;
+ }
+ }
+
+ private static class GroupHeadWithValues {
Review Comment:
make this final?
##########
lucene/grouping/src/java/org/apache/lucene/search/grouping/AllGroupHeadsCollectorManager.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.search.grouping;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Supplier;
+import org.apache.lucene.search.CollectorManager;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.FixedBitSet;
+
+/**
+ * A CollectorManager implementation for AllGroupHeadsCollector.
+ *
+ * @lucene.experimental
+ */
+public class AllGroupHeadsCollectorManager<T>
+ implements CollectorManager<
+ AllGroupHeadsCollector<T>,
AllGroupHeadsCollectorManager.GroupHeadsResult> {
+
+ /** Result wrapper that allows retrieving group heads as int[] or Bits. */
+ public static class GroupHeadsResult {
+ private final int[] groupHeads;
+
+ GroupHeadsResult(int[] groupHeads) {
+ this.groupHeads = groupHeads;
+ }
+
+ public int[] retrieveGroupHeads() {
+ return groupHeads;
+ }
+
+ public Bits retrieveGroupHeads(int maxDoc) {
+ FixedBitSet result = new FixedBitSet(maxDoc);
+ for (int docId : groupHeads) {
+ result.set(docId);
+ }
+ return result;
+ }
+ }
+
+ private static class GroupHeadWithValues {
+ int doc;
+ final Object[] sortValues;
+
+ GroupHeadWithValues(int doc, Object[] sortValues) {
+ this.doc = doc;
+ this.sortValues = sortValues;
+ }
+ }
+
+ private final Supplier<GroupSelector<T>> groupSelectorFactory;
+ private final Sort sortWithinGroup;
+
+ /**
+ * Creates a new AllGroupHeadsCollectorManager.
+ *
+ * @param groupSelectorFactory factory to create group selectors for each
collector
+ * @param sortWithinGroup the sort to use within each group to determine the
group head
+ */
+ public AllGroupHeadsCollectorManager(
+ Supplier<GroupSelector<T>> groupSelectorFactory, Sort sortWithinGroup) {
+ this.groupSelectorFactory = groupSelectorFactory;
+ this.sortWithinGroup = sortWithinGroup;
+ }
+
+ @Override
+ public AllGroupHeadsCollector<T> newCollector() throws IOException {
+ return AllGroupHeadsCollector.newCollector(groupSelectorFactory.get(),
sortWithinGroup, true);
+ }
+
+ @Override
+ public GroupHeadsResult reduce(Collection<AllGroupHeadsCollector<T>>
collectors) {
+ Map<Object, GroupHeadWithValues> mergedHeads = new HashMap<>();
+ SortField[] sortFields = sortWithinGroup.getSort();
+
+ for (AllGroupHeadsCollector<T> collector : collectors) {
+ mergeCollectorHeads(collector, mergedHeads, sortFields);
+ }
+
+ return new GroupHeadsResult(mergedHeads.values().stream().mapToInt(h ->
h.doc).toArray());
+ }
+
+ private void mergeCollectorHeads(
+ AllGroupHeadsCollector<T> collector,
+ Map<Object, GroupHeadWithValues> mergedHeads,
+ SortField[] sortFields) {
+ Collection<? extends AllGroupHeadsCollector.GroupHead<T>> heads =
+ collector.getCollectedGroupHeads();
+ for (AllGroupHeadsCollector.GroupHead<T> head : heads) {
+ Object[] sortValues = collector.getSortValues(head.groupValue);
Review Comment:
do we need to go through the collector to get the sort values? Couldn't we
get it directly from the current head?
##########
lucene/grouping/src/java/org/apache/lucene/search/grouping/AllGroupHeadsCollectorManager.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.search.grouping;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Supplier;
+import org.apache.lucene.search.CollectorManager;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.FixedBitSet;
+
+/**
+ * A CollectorManager implementation for AllGroupHeadsCollector.
+ *
+ * @lucene.experimental
+ */
+public class AllGroupHeadsCollectorManager<T>
+ implements CollectorManager<
+ AllGroupHeadsCollector<T>,
AllGroupHeadsCollectorManager.GroupHeadsResult> {
+
+ /** Result wrapper that allows retrieving group heads as int[] or Bits. */
+ public static class GroupHeadsResult {
+ private final int[] groupHeads;
+
+ GroupHeadsResult(int[] groupHeads) {
Review Comment:
Does this constructor need to be public, or instead should we make it
private if instances can only be created by the reduce method?
##########
lucene/grouping/src/java/org/apache/lucene/search/grouping/AllGroupHeadsCollector.java:
##########
@@ -232,40 +258,60 @@ protected void setNextReader(LeafReaderContext ctx)
throws IOException {
* @throws IOException If I/O related errors occur
*/
protected abstract void updateDocHead(int doc) throws IOException;
+
+ /**
+ * Returns the sort values for this group head.
+ *
+ * @return the sort values, or null if not stored
+ */
+ protected Object[] getSortValues() {
+ return null;
Review Comment:
is this correct? Should the method be abstract instead?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]