lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From munendr...@apache.org
Subject [lucene-solr] branch master updated: SOLR-12364: add test cases for edismax boost
Date Sat, 29 Jun 2019 17:03:07 GMT
This is an automated email from the ASF dual-hosted git repository.

munendrasn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new cfd6e1a  SOLR-12364: add test cases for edismax boost
cfd6e1a is described below

commit cfd6e1adfaed17f260cd874c02dab7b04acf280c
Author: Munendra S N <munendrasn@apache.org>
AuthorDate: Sat Jun 29 22:16:51 2019 +0530

    SOLR-12364: add test cases for edismax boost
    
    * This adds tests for bf and boosts
    * Use expectThrows in edismax tests to verify exception
---
 solr/CHANGES.txt                                   |  2 +
 .../solr/search/TestExtendedDismaxParser.java      | 76 ++++++++++++++++++----
 2 files changed, 65 insertions(+), 13 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5a5091c..02ee9e4 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -224,6 +224,8 @@ Other Changes
 
 * SOLR-13576: Factor out a TopGroupsShardResponseProcessor.fillResultIds method. (Christine
Poerschke, Diego Ceccarelli)
 
+* SOLR-12364: Add test cases for edismax boost (David Smiley, Munendra S N)
+
 ==================  8.1.2 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java b/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
index 19ac53b..72546cc 100644
--- a/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
+++ b/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
@@ -39,7 +39,6 @@ import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.Utils;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.util.SolrPluginUtils;
-import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -522,6 +521,56 @@ public class TestExtendedDismaxParser extends SolrTestCaseJ4 {
      );
   }
 
+  @Test
+  public void testBf() {
+    assertQ(
+        req("q", "tekna", "qf", "text_sw", "defType", "edismax", "bf", "ord(id)", "fq", "id:[52
TO 54]", "fl", "id,score"),
+        "//doc[1]/str[@name='id'][.='54']",
+        "//doc[2]/str[@name='id'][.='53']",
+        "//doc[3]/str[@name='id'][.='52']"
+    );
+
+    assertQ(req("q", "tekna", "qf", "text_sw", "defType", "edismax",
+        "bf", "if(and(query({!v='id:53'})),120,if(query({!v='id:52'}),10,0))", "fq", "id:[52
TO 54]", "fl", "id,score"),
+        "//doc[1]/str[@name='id'][.='53']",
+        "//doc[2]/str[@name='id'][.='52']",
+        "//doc[3]/str[@name='id'][.='54']");
+
+    // adding value from a field
+    // 0 would be returned for negative values
+    assertQ(req("q", "*:*", "qf", "text_sw", "defType", "edismax",
+        "bf", "foo_i", "fq", "id:[47 TO 49]", "fl", "id,score"),
+        "//doc[1]/str[@name='id'][.='48']",
+        "//doc[2]/str[@name='id'][.='47']",
+        "//doc[3]/str[@name='id'][.='49']");
+  }
+
+  @Test
+  public void testBoost() {
+    assertQ(
+        req("q", "*:*", "qf", "text_sw", "defType", "edismax", "boost", "exists(foo_i)",
"fq", "id:[47 TO 49]",
+            "fl", "id,score", "boost", "if(not(query({!v=id:49})),10,1)"),
+        "//doc[1]/str[@name='id'][.='48']",
+        "//doc[2]/str[@name='id'][.='49']",
+        "//doc[3]/str[@name='id'][.='47']"
+    );
+
+    assertQ(req("q", "tekna", "qf", "text_sw", "defType", "edismax",
+        "boost", "if(and(query({!v='id:53'})),120,if(query({!v='id:52'}),0.0002,1))", "fq",
"id:[52 TO 54]", "fl", "id,score"),
+        "//doc[1]/str[@name='id'][.='53']",
+        "//doc[2]/str[@name='id'][.='54']",
+        "//doc[3]/str[@name='id'][.='52']");
+
+    // adding value from a field
+    // using sum to verify the order
+    // 0 would be returned for negative values or if the field value is not present
+    assertQ(req("q", "*:*", "qf", "text_sw", "defType", "edismax",
+        "boost", "sum(foo_i,1)", "fq", "id:[48 TO 50]", "fl", "id,score"),
+        "//doc[1]/str[@name='id'][.='48']",
+        "//doc[2]/str[@name='id'][.='50']",
+        "//doc[3]/str[@name='id'][.='49']");
+  }
+
   public void testUserFields() {
     String allr = "*[count(//doc)=10]";
     String oner = "*[count(//doc)=1]";
@@ -2078,9 +2127,13 @@ public class TestExtendedDismaxParser extends SolrTestCaseJ4 {
   }
 
   /** SOLR-11512 */
-  @Test(expected=SolrException.class)
+  @Test
   public void killInfiniteRecursionParse() throws Exception {
-    assertJQ(req("defType", "edismax", "q", "*", "qq", "{!edismax v=something}", "bq", "{!edismax
v=$qq}"));
+    SolrException exception = expectThrows(SolrException.class, () -> {
+      h.query(req("defType", "edismax", "q", "*", "qq", "{!edismax v=something}", "bq", "{!edismax
v=$qq}"));
+    });
+    assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, exception.code());
+    assertTrue(exception.getMessage().contains("Infinite Recursion detected parsing query"));
   }
 
   /** SOLR-5163 */
@@ -2095,19 +2148,16 @@ public class TestExtendedDismaxParser extends SolrTestCaseJ4 {
     params.add("debugQuery", "true");
 
     // test valid field names
-    try (SolrQueryRequest req = req(params)) {
-      String response = h.query(req);
-      response.contains("+DisjunctionMaxQuery((title:olive | (subject:oliv)^3.0)) +DisjunctionMaxQuery((title:other
| (subject:other)^3.0))");
-    }
+    String response = h.query(req(params));
+    assertTrue(response.contains("+DisjunctionMaxQuery((title:olive | " +
+        "(subject:oliv)^3.0)) +DisjunctionMaxQuery((title:other | (subject:other)^3.0))"));
 
     // test invalid field name
     params.set("qf", "subject^3 nosuchfield");
-    try (SolrQueryRequest req = req(params)) {
-      h.query(req);
-    } catch (Exception e) {
-      Assert.assertEquals("org.apache.solr.search.SyntaxError: Query Field 'nosuchfield'
is not a valid field name", e.getMessage());
-    }
-
+    SolrException exception = expectThrows(SolrException.class, () -> h.query(req(params)));
+    assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, exception.code());
+    assertEquals("org.apache.solr.search.SyntaxError: Query Field 'nosuchfield' is not a
valid field name",
+        exception.getMessage());
   }
 
 }


Mime
View raw message