You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/06/29 23:12:34 UTC

[GitHub] [lucene] gsmiller opened a new pull request #196: LUCENE-10000: Make MultiCollectorManager consistent with MultiCollector

gsmiller opened a new pull request #196:
URL: https://github.com/apache/lucene/pull/196


   # Description
   
   MultiCollectorManager is now consistent with MultiCollector with respect to early termination, min score setting and score caching.
   
   # Solution
   
   MultiCollectorManager delegates to MultiCollector instead of creating its own solution for wrapping/managing multiple Collectors.
   
   # Tests
   
   Created unit tests for MultiCollectorManager (none previously existed). Tests cover various scenarios that are similarly covered in MultiCollector.
   
   # Checklist
   
   Please review the following and check all that apply:
   
   - [x] I have reviewed the guidelines for [How to Contribute](https://wiki.apache.org/lucene/HowToContribute) and my code conforms to the standards described there to the best of my ability.
   - [x] I have created a Jira issue and added the issue ID to my pull request title.
   - [x] I have given Lucene maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended)
   - [x] I have developed this patch against the `main` branch.
   - [x] I have run `./gradlew check`.
   - [x] I have added tests for my changes.
   


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene] gsmiller commented on a change in pull request #196: LUCENE-10000: Make MultiCollectorManager consistent with MultiCollector

Posted by GitBox <gi...@apache.org>.
gsmiller commented on a change in pull request #196:
URL: https://github.com/apache/lucene/pull/196#discussion_r673536496



##########
File path: lucene/core/src/java/org/apache/lucene/search/MultiCollector.java
##########
@@ -83,7 +83,7 @@ public static Collector wrap(Iterable<? extends Collector> collectors) {
   }
 
   private final boolean cacheScores;
-  private final Collector[] collectors;
+  final Collector[] collectors;

Review comment:
       Sure!

##########
File path: lucene/core/src/test/org/apache/lucene/search/TestMultiCollectorManager.java
##########
@@ -0,0 +1,335 @@
+/*
+ * 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;
+
+import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestMultiCollectorManager extends LuceneTestCase {
+
+  @SuppressWarnings("unchecked")
+  public void testCollection() throws IOException {
+    Directory dir = newDirectory();
+    DirectoryReader reader = reader(dir);
+    LeafReaderContext ctx = reader.leaves().get(0);
+
+    // Setup two collector managers, one that will only collect even doc ids and one that
+    // only collects odd. Create some random doc ids and keep track of the ones that we
+    // expect each collector manager to collect:
+    Predicate<Integer> evenPredicate = val -> val % 2 == 0;
+    Predicate<Integer> oddPredicate = val -> val % 2 == 1;
+
+    SimpleCollectorManager cm1 = new SimpleCollectorManager(evenPredicate);
+    SimpleCollectorManager cm2 = new SimpleCollectorManager(oddPredicate);
+
+    for (int iter = 0; iter < 100; iter++) {
+      int docs = RandomNumbers.randomIntBetween(random(), 1000, 10000);
+      List<Integer> expected = new ArrayList<>(docs);
+      for (int i = 0; i < docs; i++) {
+        expected.add(random().nextInt());
+      }
+      List<Integer> expectedEven =
+          expected.stream().filter(evenPredicate).collect(Collectors.toList());
+      List<Integer> expectedOdd =
+          expected.stream().filter(oddPredicate).collect(Collectors.toList());
+
+      // Test only wrapping one of the collector managers:
+      MultiCollectorManager mcm = new MultiCollectorManager(cm1);
+      Object[] results = (Object[]) collectAll(ctx, expected, mcm);

Review comment:
       Good idea. Will do.




-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene] jpountz commented on a change in pull request #196: LUCENE-10000: Make MultiCollectorManager consistent with MultiCollector

Posted by GitBox <gi...@apache.org>.
jpountz commented on a change in pull request #196:
URL: https://github.com/apache/lucene/pull/196#discussion_r673114007



##########
File path: lucene/core/src/java/org/apache/lucene/search/MultiCollector.java
##########
@@ -83,7 +83,7 @@ public static Collector wrap(Iterable<? extends Collector> collectors) {
   }
 
   private final boolean cacheScores;
-  private final Collector[] collectors;
+  final Collector[] collectors;

Review comment:
       nit: can you keep it private and add a pkg-private getter instead?

##########
File path: lucene/CHANGES.txt
##########
@@ -236,6 +236,9 @@ Improvements
 * LUCENE-9535: Improve DocumentsWriterPerThreadPool to prefer larger instances.
   (Adrien Grand)
 
+* LUCENE-10000: MultiCollectorManager now has parity with MultiCollector with respect to how it
+  handles CollectionTerminationException and minCompetitiveScore calls. (Greg Miller)

Review comment:
       ```suggestion
     handles CollectionTerminationException and setMinCompetitiveScore calls. (Greg Miller)
   ```

##########
File path: lucene/core/src/test/org/apache/lucene/search/TestMultiCollectorManager.java
##########
@@ -0,0 +1,335 @@
+/*
+ * 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;
+
+import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestMultiCollectorManager extends LuceneTestCase {
+
+  @SuppressWarnings("unchecked")
+  public void testCollection() throws IOException {
+    Directory dir = newDirectory();
+    DirectoryReader reader = reader(dir);
+    LeafReaderContext ctx = reader.leaves().get(0);
+
+    // Setup two collector managers, one that will only collect even doc ids and one that
+    // only collects odd. Create some random doc ids and keep track of the ones that we
+    // expect each collector manager to collect:
+    Predicate<Integer> evenPredicate = val -> val % 2 == 0;
+    Predicate<Integer> oddPredicate = val -> val % 2 == 1;
+
+    SimpleCollectorManager cm1 = new SimpleCollectorManager(evenPredicate);
+    SimpleCollectorManager cm2 = new SimpleCollectorManager(oddPredicate);
+
+    for (int iter = 0; iter < 100; iter++) {
+      int docs = RandomNumbers.randomIntBetween(random(), 1000, 10000);
+      List<Integer> expected = new ArrayList<>(docs);
+      for (int i = 0; i < docs; i++) {
+        expected.add(random().nextInt());
+      }
+      List<Integer> expectedEven =
+          expected.stream().filter(evenPredicate).collect(Collectors.toList());
+      List<Integer> expectedOdd =
+          expected.stream().filter(oddPredicate).collect(Collectors.toList());
+
+      // Test only wrapping one of the collector managers:
+      MultiCollectorManager mcm = new MultiCollectorManager(cm1);
+      Object[] results = (Object[]) collectAll(ctx, expected, mcm);

Review comment:
       let's have `expected` sorted and only containing unique doc IDs to be more realistic?




-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene] gsmiller commented on pull request #196: LUCENE-10000: Make MultiCollectorManager consistent with MultiCollector

Posted by GitBox <gi...@apache.org>.
gsmiller commented on pull request #196:
URL: https://github.com/apache/lucene/pull/196#issuecomment-885353122


   > Thanks for fixing this!
   
   Sure. Thanks for the feedback!


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene] gsmiller merged pull request #196: LUCENE-10000: Make MultiCollectorManager consistent with MultiCollector

Posted by GitBox <gi...@apache.org>.
gsmiller merged pull request #196:
URL: https://github.com/apache/lucene/pull/196


   


-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org