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 2022/02/02 14:23:15 UTC

[GitHub] [lucene] javanna commented on a change in pull request #639: LUCENE-10002: Replace some IndexSearcher#search(Collector, Query) in tests

javanna commented on a change in pull request #639:
URL: https://github.com/apache/lucene/pull/639#discussion_r797656068



##########
File path: lucene/core/src/test/org/apache/lucene/index/TestOmitTf.java
##########
@@ -219,160 +221,101 @@ public void testBasic() throws Exception {
 
     searcher.search(
         q1,
-        new CountingHitCollector() {
-          private Scorable scorer;
-
-          @Override
-          public ScoreMode scoreMode() {
-            return ScoreMode.COMPLETE;
-          }
-
+        new CollectorManager<SimpleCollector, Void>() {
           @Override
-          public final void setScorer(Scorable scorer) {
-            this.scorer = scorer;
+          public SimpleCollector newCollector() {
+            return new ScoreAssertingCollector() {
+              @Override
+              public void collect(int doc) throws IOException {
+                // System.out.println("Q1: Doc=" + doc + " score=" + score);
+                float score = scorer.score();
+                assertTrue("got score=" + score, score == 1.0f);
+              }
+            };
           }
 
           @Override
-          public final void collect(int doc) throws IOException {
-            // System.out.println("Q1: Doc=" + doc + " score=" + score);
-            float score = scorer.score();
-            assertTrue("got score=" + score, score == 1.0f);
-            super.collect(doc);
+          public Void reduce(Collection<SimpleCollector> collectors) {
+            return null;
           }
         });
-    // System.out.println(CountingHitCollector.getCount());
 
     searcher.search(
         q2,
-        new CountingHitCollector() {
-          private Scorable scorer;
-
-          @Override
-          public ScoreMode scoreMode() {
-            return ScoreMode.COMPLETE;
-          }
-
+        new CollectorManager<SimpleCollector, Void>() {
           @Override
-          public final void setScorer(Scorable scorer) {
-            this.scorer = scorer;
+          public SimpleCollector newCollector() {
+            return new ScoreAssertingCollector() {
+              @Override
+              public void collect(int doc) throws IOException {
+                // System.out.println("Q2: Doc=" + doc + " score=" + score);
+                float score = scorer.score();
+                assertEquals(1.0f + doc, score, 0.00001f);
+              }
+            };
           }
 
           @Override
-          public final void collect(int doc) throws IOException {
-            // System.out.println("Q2: Doc=" + doc + " score=" + score);
-            float score = scorer.score();
-            assertEquals(1.0f + doc, score, 0.00001f);
-            super.collect(doc);
+          public Void reduce(Collection<SimpleCollector> collectors) {
+            return null;
           }
         });
-    // System.out.println(CountingHitCollector.getCount());
 
     searcher.search(
         q3,
-        new CountingHitCollector() {
-          private Scorable scorer;
-
-          @Override
-          public ScoreMode scoreMode() {
-            return ScoreMode.COMPLETE;
-          }
-
+        new CollectorManager<SimpleCollector, Void>() {
           @Override
-          public final void setScorer(Scorable scorer) {
-            this.scorer = scorer;
+          public SimpleCollector newCollector() {
+            return new ScoreAssertingCollector() {
+              @Override
+              public void collect(int doc) throws IOException {
+                // System.out.println("Q1: Doc=" + doc + " score=" + score);
+                float score = scorer.score();
+                assertTrue(score == 1.0f);
+                assertFalse(doc % 2 == 0);
+              }
+            };
           }
 
           @Override
-          public final void collect(int doc) throws IOException {
-            // System.out.println("Q1: Doc=" + doc + " score=" + score);
-            float score = scorer.score();
-            assertTrue(score == 1.0f);
-            assertFalse(doc % 2 == 0);
-            super.collect(doc);
+          public Void reduce(Collection<SimpleCollector> collectors) {
+            return null;
           }
         });
-    // System.out.println(CountingHitCollector.getCount());

Review comment:
       I wonder if I need to keep these System.out. In that case, it is not complicated to make the collector manager expose the count. I did not do it because these are all commented out and I wonder if we should just remove these lines 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: 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