sigram commented on code in PR #4906:
URL: https://github.com/apache/solr/pull/4906#discussion_r4005066493


##########
solr/core/src/test/org/apache/solr/core/ExitableDirectoryReaderTest.java:
##########
@@ -79,4 +84,55 @@ public void testExitableDirectoryReader() throws Exception {
         "there should be at least " + maxCount + " calls from 
ExitableTermsEnum: " + callCounts,
         callCounts.get(callerExpr) >= maxCount);
   }
+
+  /**
+   * Checks that a custom {@link Similarity} configured on the core is honored 
when scoring with
+   * query limits enabled (Regression test for SOLR-18305).
+   */
+  @Test
+  public void testCustomSimilarity() throws Exception {
+    System.setProperty("solr.similarity", 
DummySimilarityFactory.class.getName());
+    initCore("solrconfig-minimal.xml", "schema-tiny.xml");
+
+    assertU(adoc("id", "1", "aaa_t", "a1"));
+    assertU(commit());
+
+    // Check the dummy similarity is used as expected with no query limits.
+    // The returned doc has score 42.0, in both the result and the debug 
explanation plan.
+    String q = "aaa_t:a1";
+    assertQ(
+        req("q", q, "fl", "id,score", "debug", "results"),
+        "//result[@numFound = '1']",
+        "//result/doc[1]/float[@name='score'][.='42.0']",
+        
"//lst[@name='debug']/lst[@name='explain']/str[@name='1'][contains(text(),'DummySimilarity')]",
+        
"//lst[@name='debug']/lst[@name='explain']/str[@name='1'][contains(text(),'42.0 
= score')]");
+
+    // Similar assertion as before, the only difference is we add a query 
limit with parameter
+    // 'timeAllowed=xxx'
+    assertQ(
+        req("q", q, "fl", "id,score", "debug", "results", "timeAllowed", 
"60000"),
+        "//result[@numFound = '1']",
+        "//result/doc[1]/float[@name='score'][.='42.0']",
+        
"//lst[@name='debug']/lst[@name='explain']/str[@name='1'][contains(text(),'DummySimilarity')]",
+        
"//lst[@name='debug']/lst[@name='explain']/str[@name='1'][contains(text(),'42.0 
= score')]");
+  }
+
+  public static class DummySimilarityFactory extends SimilarityFactory {
+    public static class DummySimilarity extends Similarity {
+      @Override
+      public SimScorer scorer(
+          float boost, CollectionStatistics collectionStats, TermStatistics... 
termStats) {
+        return new Similarity.SimScorer() {
+          public float score(float freq, long norm) {
+            return 42f;

Review Comment:
   The all meaningful value :)



-- 
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]

Reply via email to