-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Introduce FirstPassGroupingCollectorManager #15574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d40d5d5
Introduce FirstPassGroupingCollectorManager
gaobinlong 79b499c
Return directly if only one collector exists
gaobinlong 0a09521
Merge remote-tracking branch 'upstream/main' into firstPassManager
gaobinlong 6084c22
Merge main
gaobinlong f34ec28
Merge remote-tracking branch 'upstream/main' into firstPassManager
gaobinlong eb3720a
Replace collector with collector manager in TestGrouping
gaobinlong fe4b5fa
Merge remote-tracking branch 'upstream/main' into firstPassManager
gaobinlong 21d6c6d
Move changelog to 10.5.0
gaobinlong e09fc00
Do not share context across collectors in concurrent scenario
gaobinlong 3dac819
Format code
gaobinlong 17dbaff
merge main
gaobinlong 725889f
Add more tests
gaobinlong 1f84145
Merge remote-tracking branch 'upstream/main' into firstPassManager
gaobinlong 9503fe7
Override more public search method in ShardSearcher
gaobinlong 9ea1170
Merge remote-tracking branch 'upstream/main' into firstPassManager
gaobinlong ad3daf4
Fix build failed
gaobinlong 496e3dc
Optimize code and fix issue
gaobinlong 7a289b2
Merge branch 'main' into firstPassManager
gaobinlong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...rouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollectorManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* | ||
| * 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.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.function.Supplier; | ||
| import org.apache.lucene.search.CollectorManager; | ||
| import org.apache.lucene.search.Sort; | ||
|
|
||
| /** | ||
| * A CollectorManager implementation for {@link FirstPassGroupingCollector} that supports parallel | ||
| * collection and merges results across segments. | ||
| * | ||
| * <p>Example usage: | ||
| * | ||
| * <pre class="prettyprint"> | ||
| * IndexSearcher searcher = new IndexSearcher(reader); | ||
| * Sort groupSort = Sort.RELEVANCE; | ||
| * int topNGroups = 10; | ||
| * | ||
| * FirstPassGroupingCollectorManager<BytesRef> manager = | ||
| * new FirstPassGroupingCollectorManager<>( | ||
| * () -> new TermGroupSelector("category"), | ||
| * groupSort, | ||
| * 0, | ||
| * topNGroups); | ||
| * | ||
| * Collection<SearchGroup<BytesRef>> searchGroups = searcher.search(query, manager); | ||
| * | ||
| * // searchGroups can then be passed to a second pass collector manager like TopGroupsCollectorManager for full group results | ||
| * </pre> | ||
| * | ||
| * @lucene.experimental | ||
| */ | ||
| public class FirstPassGroupingCollectorManager<T> | ||
|
javanna marked this conversation as resolved.
|
||
| implements CollectorManager<FirstPassGroupingCollector<T>, Collection<SearchGroup<T>>> { | ||
|
|
||
| private final Supplier<GroupSelector<T>> groupSelectorFactory; | ||
| private final Sort groupSort; | ||
| private final int groupOffset; | ||
| private final int topNGroups; | ||
| private final boolean ignoreDocsWithoutGroupField; | ||
|
|
||
| /** | ||
| * Creates a new FirstPassGroupingCollectorManager. | ||
| * | ||
| * @param groupSelectorFactory factory to create group selectors for each collector | ||
| * @param groupSort the sort to use for groups | ||
| * @param groupOffset The offset in the collected groups | ||
| * @param topNGroups the number of top groups to collect | ||
| */ | ||
| public FirstPassGroupingCollectorManager( | ||
| Supplier<GroupSelector<T>> groupSelectorFactory, | ||
| Sort groupSort, | ||
| int groupOffset, | ||
| int topNGroups) { | ||
| this(groupSelectorFactory, groupSort, groupOffset, topNGroups, false); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new FirstPassGroupingCollectorManager. | ||
| * | ||
| * @param groupSelectorFactory factory to create group selectors for each collector | ||
| * @param groupSort the sort to use for groups | ||
| * @param groupOffset The offset in the collected groups | ||
| * @param topNGroups the number of top groups to collect | ||
| * @param ignoreDocsWithoutGroupField whether to ignore documents without a group field | ||
| */ | ||
| public FirstPassGroupingCollectorManager( | ||
| Supplier<GroupSelector<T>> groupSelectorFactory, | ||
| Sort groupSort, | ||
| int groupOffset, | ||
| int topNGroups, | ||
| boolean ignoreDocsWithoutGroupField) { | ||
| if (groupOffset < 0) { | ||
| throw new IllegalArgumentException("groupOffset must be >= 0 (got " + groupOffset + ")"); | ||
| } | ||
| if (topNGroups < 1) { | ||
| throw new IllegalArgumentException("topNGroups must be >= 1 (got " + topNGroups + ")"); | ||
| } | ||
| this.groupSelectorFactory = groupSelectorFactory; | ||
| this.groupSort = groupSort; | ||
| this.groupOffset = groupOffset; | ||
| this.topNGroups = topNGroups; | ||
| this.ignoreDocsWithoutGroupField = ignoreDocsWithoutGroupField; | ||
|
javanna marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Override | ||
| public FirstPassGroupingCollector<T> newCollector() throws IOException { | ||
| return new FirstPassGroupingCollector<>( | ||
| groupSelectorFactory.get(), | ||
| groupSort, | ||
| groupOffset + topNGroups, | ||
| ignoreDocsWithoutGroupField); | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<SearchGroup<T>> reduce(Collection<FirstPassGroupingCollector<T>> collectors) | ||
| throws IOException { | ||
| final List<Collection<SearchGroup<T>>> allGroups = new ArrayList<>(); | ||
| for (FirstPassGroupingCollector<T> collector : collectors) { | ||
| Collection<SearchGroup<T>> groups = collector.getTopGroups(0); | ||
| if (groups != null) { | ||
| allGroups.add(groups); | ||
| } | ||
| } | ||
|
|
||
| return SearchGroup.merge(allGroups, groupOffset, topNGroups, groupSort); | ||
|
javanna marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.