You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ds...@apache.org on 2023/08/24 13:16:57 UTC

[solr] branch main updated: SOLR-16916: JSON boolean queries when solrconfig defType is set to edismax (#1827)

This is an automated email from the ASF dual-hosted git repository.

dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 04bfd236ad4 SOLR-16916: JSON boolean queries when solrconfig defType is set to edismax (#1827)
04bfd236ad4 is described below

commit 04bfd236ad4703e34f5b263ba1b04257173fccb5
Author: Jane Sandberg <sa...@users.noreply.github.com>
AuthorDate: Thu Aug 24 09:16:52 2023 -0400

    SOLR-16916: JSON boolean queries when solrconfig defType is set to edismax (#1827)
    
    SOLR-16916: Use of the JSON Query DSL should ignore the defType parameter
      (Christina Chortaria, Max Kadel, Ryan Laddusaw, Jane Sandberg, David Smiley)
    
    
    Co-authored-by: David Smiley <ds...@apache.org>
    Co-authored-by: Jane Sandberg <sa...@users.noreply.github.com>
    Co-authored-by: Ryan Laddusaw <rl...@users.noreply.github.com>
    Co-authored-by: Christina Chortaria <ch...@users.noreply.github.com>
    Co-authored-by: Max Kadel <ma...@users.noreply.github.com>
---
 solr/CHANGES.txt                                   |  5 +-
 .../org/apache/solr/request/json/RequestUtil.java  |  3 +
 .../json/TestJsonRequestWithEdismaxDefType.java    | 74 ++++++++++++++++++++++
 3 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 009f9bc2d44..ce100a932d6 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -138,7 +138,10 @@ Bug Fixes
 
 * SOLR-16946: Updated Cluster Singleton plugins are stopped correctly when the Overseer is closed. (Paul McArthur)
 
-* SOLR-16933: Include the full query response when using the API tool, and fix serialization issues for SolrDocumentList. (Houston Putman) 
+* SOLR-16933: Include the full query response when using the API tool, and fix serialization issues for SolrDocumentList. (Houston Putman)
+
+* SOLR-16916: Use of the JSON Query DSL should ignore the defType parameter
+  (Christina Chortaria, Max Kadel, Ryan Laddusaw, Jane Sandberg, David Smiley)
 
 Dependency Upgrades
 ---------------------
diff --git a/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java b/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java
index ace858667bc..d5c46bbb9a1 100644
--- a/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java
+++ b/solr/core/src/java/org/apache/solr/request/json/RequestUtil.java
@@ -33,6 +33,7 @@ import org.apache.solr.handler.component.SearchHandler;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.request.SolrRequestHandler;
 import org.apache.solr.request.macro.MacroExpander;
+import org.apache.solr.search.QueryParsing;
 import org.noggit.JSONParser;
 import org.noggit.ObjectBuilder;
 
@@ -217,6 +218,8 @@ public class RequestUtil {
         if ("query".equals(key)) {
           out = "q";
           isQuery = true;
+          String[] queryParsers = {"lucene"};
+          newMap.put(QueryParsing.DEFTYPE, queryParsers);
         } else if ("filter".equals(key)) {
           out = "fq";
           arr = true;
diff --git a/solr/core/src/test/org/apache/solr/search/json/TestJsonRequestWithEdismaxDefType.java b/solr/core/src/test/org/apache/solr/search/json/TestJsonRequestWithEdismaxDefType.java
new file mode 100644
index 00000000000..3d3ec25a878
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/search/json/TestJsonRequestWithEdismaxDefType.java
@@ -0,0 +1,74 @@
+/*
+ * 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.solr.search.json;
+
+import java.nio.file.Path;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrRequest.METHOD;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.cloud.ConfigRequest;
+import org.apache.solr.util.EmbeddedSolrServerTestRule;
+import org.apache.solr.util.SolrClientTestRule;
+import org.junit.ClassRule;
+
+public class TestJsonRequestWithEdismaxDefType extends SolrTestCaseJ4 {
+
+  @ClassRule
+  public static final SolrClientTestRule solrClientTestRule = new EmbeddedSolrServerTestRule();
+
+  public void test() throws Exception {
+    solrClientTestRule.startSolr(LuceneTestCase.createTempDir());
+
+    Path configSet = LuceneTestCase.createTempDir();
+    SolrTestCaseJ4.copyMinConf(configSet.toFile());
+
+    solrClientTestRule.newCollection().withConfigSet(configSet.toString()).create();
+
+    SolrClient client = solrClientTestRule.getSolrClient();
+
+    client.request(
+        new ConfigRequest(
+            "{"
+                + "  'create-requesthandler':{"
+                + "    'name':'/query',"
+                + "    'class':'solr.SearchHandler',"
+                + "    'defaults' : {'defType':'edismax'}" // the critical part
+                + "  }"
+                + "}"));
+
+    addDocs(client);
+
+    doQuery(client);
+  }
+
+  private static void addDocs(SolrClient client) throws Exception {
+    client.add(sdoc("id", "1", "cat_s", "A", "where_s", "NY"));
+    client.add(sdoc("id", "2", "cat_s", "B", "where_s", "NJ"));
+    client.add(sdoc("id", "3"));
+    client.commit();
+  }
+
+  private static void doQuery(SolrClient client) throws Exception {
+    final var jsonQuery =
+        "{\"query\":{\"bool\":{\"should\":[{\"lucene\":{\"query\":\"id:1\"}}, \"id:2\"]}}}";
+    final var req = new QueryRequest(params("json", jsonQuery, "qt", "/query"), METHOD.POST);
+    final var rsp = req.process(client);
+    assertEquals(2, rsp.getResults().getNumFound());
+  }
+}