Apache Solr open-source search software
SOLR-17715: Stop sending qt param from SolrJ (#4397)
r4mercur4d2720a0e906
diff --git a/changelog/unreleased/SOLR-17715-remove-qt-param-from-queryrequest.yml b/changelog/unreleased/SOLR-17715-remove-qt-param-from-queryrequest.ymlnew file mode 100644index 00000000000..71de6bf8645--- /dev/null+++ b/changelog/unreleased/SOLR-17715-remove-qt-param-from-queryrequest.yml@@ -0,0 +1,12 @@+# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc+title: >+ QueryRequest.java in SolrJ no longer sends the 'qt' parameter to the server.+type: changed # added, changed, fixed, deprecated, removed, dependency_update, security, other+authors:+ - name: r4mercur+ nick: r4mercur+links:+ - name: SOLR-17715+ url: https://issues.apache.org/jira/browse/SOLR-17715+ - name: PR#4397+ url: https://github.com/apache/solr/pull/4397diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/QueryRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/QueryRequest.javaindex 04b4d4e3a54..2ccf8d328b9 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/QueryRequest.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/QueryRequest.java@@ -19,6 +19,7 @@ package org.apache.solr.client.solrj.request;import java.util.Objects;import org.apache.solr.client.solrj.response.QueryResponse;import org.apache.solr.common.params.CommonParams;+import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.NamedList;@@ -33,31 +34,40 @@ public class QueryRequest extends CollectionRequiringSolrRequest<QueryResponse>private final SolrParams query;public QueryRequest() {- super(METHOD.GET, null, SolrRequestType.QUERY);+ super(METHOD.GET, "/select", SolrRequestType.QUERY);query = SolrParams.of();}public QueryRequest(SolrParams q) {- super(METHOD.GET, null, SolrRequestType.QUERY);- query = Objects.requireNonNull(q);+ super(METHOD.GET, pathFromParams(Objects.requireNonNull(q)), SolrRequestType.QUERY);+ query = paramsWithoutQt(q);}public QueryRequest(SolrParams q, METHOD method) {- super(method, null, SolrRequestType.QUERY);+ super(method, pathFromParams(Objects.requireNonNull(q)), SolrRequestType.QUERY);+ query = paramsWithoutQt(q);+ }++ public QueryRequest(String path, SolrParams q) {+ super(METHOD.GET, Objects.requireNonNull(path), SolrRequestType.QUERY);query = Objects.requireNonNull(q);}- /** Use the params 'QT' parameter if it exists */- @Override- public String getPath() {- String qt = query.get(CommonParams.QT);- if (qt == null) {- qt = super.getPath();- }- if (qt != null && qt.startsWith("/")) {- return qt;- }- return "/select";+ public QueryRequest(String path, SolrParams q, METHOD method) {+ super(method, Objects.requireNonNull(path), SolrRequestType.QUERY);+ query = Objects.requireNonNull(q);+ }++ private static String pathFromParams(SolrParams q) {+ String qt = q.get(CommonParams.QT);+ return (qt != null && qt.startsWith("/")) ? qt : "/select";+ }++ private static SolrParams paramsWithoutQt(SolrParams q) {+ if (q.get(CommonParams.QT) == null) return q;+ ModifiableSolrParams params = new ModifiableSolrParams(q);+ params.remove(CommonParams.QT);+ return params;}// ---------------------------------------------------------------------------------diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/QueryRequestTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/QueryRequestTest.javanew file mode 100644index 00000000000..dfc314c2e8c--- /dev/null+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/QueryRequestTest.java@@ -0,0 +1,77 @@+/*+ * 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.client.solrj.request;++import org.apache.solr.SolrTestCase;+import org.apache.solr.client.solrj.SolrRequest;+import org.junit.Test;++public class QueryRequestTest extends SolrTestCase {++ @Test+ public void testQtWithSlashBecomesPath() {+ SolrQuery query = new SolrQuery("*:*");+ query.setRequestHandler("/custom");++ QueryRequest request = new QueryRequest(query);++ assertEquals("/custom", request.getPath());+ assertNull("qt parameter should be removed from request params", request.getParams().get("qt"));+ assertEquals("*:*", request.getParams().get("q"));+ }++ @Test+ public void testQtWithoutSlashDefaultsToSelect() {+ SolrQuery query = new SolrQuery("*:*");+ query.setRequestHandler("custom");++ QueryRequest request = new QueryRequest(query);++ assertEquals("/select", request.getPath());+ assertNull("qt parameter shouldn't be sent to server", request.getParams().get("qt"));+ }++ @Test+ public void testDefaultPathToSelect() {+ SolrQuery query = new SolrQuery("*:*");++ QueryRequest request = new QueryRequest(query);++ assertEquals("/select", request.getPath());+ assertNull(request.getParams().get("qt"));+ }++ @Test+ public void testExplicitPath() {+ SolrQuery query = new SolrQuery("*:*");+ QueryRequest request = new QueryRequest("/custom", query);++ assertEquals("/custom", request.getPath());+ assertNull("qt parameter must not be present", request.getParams().get("qt"));+ assertEquals("*:*", request.getParams().get("q"));+ }++ @Test+ public void testExplicitPathWithMethod() {+ SolrQuery query = new SolrQuery("*:*");+ QueryRequest request = new QueryRequest("/spell", query, SolrRequest.METHOD.POST);++ assertEquals("/spell", request.getPath());+ assertEquals(SolrRequest.METHOD.POST, request.getMethod());+ assertNull(request.getParams().get("qt"));+ }+}