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/07/20 22:45:34 UTC

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

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