Apache Solr open-source search software
SOLR-16916: JSON boolean queries when solrconfig defType is set to edismax (#1827)
Jane Sandberg04bfd236ad47
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 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.javaindex 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.javanew file mode 100644index 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());+ }+}