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

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


The following commit(s) were added to refs/heads/branch_9x by this push:
     new d458d94b065 SOLR-17715: Stop sending qt param from SolrJ (#4397)
d458d94b065 is described below

commit d458d94b065a7245da82c0995cb77fb12002fd7c
Author: r4mercur <[email protected]>
AuthorDate: Sat May 9 00:00:10 2026 -0400

    SOLR-17715: Stop sending qt param from SolrJ (#4397)
    
    Enhanced QueryRequest with explicit support for the path, avoiding the need 
for "qt".
    
    (cherry picked from commit 4d2720a0e906ff4a6e836e54802b7f283664366b)
---
 ...OLR-17715-remove-qt-param-from-queryrequest.yml | 12 ++++
 .../solr/client/solrj/request/QueryRequest.java    | 45 ++++++++-----
 .../client/solrj/request/QueryRequestTest.java     | 78 ++++++++++++++++++++++
 3 files changed, 119 insertions(+), 16 deletions(-)

diff --git 
a/changelog/unreleased/SOLR-17715-remove-qt-param-from-queryrequest.yml 
b/changelog/unreleased/SOLR-17715-remove-qt-param-from-queryrequest.yml
new file mode 100644
index 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/4397
diff --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.java
index 082b88cd101..68b344b17ec 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
@@ -16,9 +16,11 @@
  */
 package org.apache.solr.client.solrj.request;
 
+import java.util.Objects;
 import org.apache.solr.client.solrj.SolrClient;
 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;
 
 /**
@@ -28,31 +30,42 @@ public class QueryRequest extends 
CollectionRequiringSolrRequest<QueryResponse>
 
   private SolrParams query;
 
+  @Deprecated
   public QueryRequest() {
-    super(METHOD.GET, null);
+    super(METHOD.GET, "/select");
+    query = SolrParams.of();
   }
 
   public QueryRequest(SolrParams q) {
-    super(METHOD.GET, null);
-    query = q;
+    super(METHOD.GET, pathFromParams(Objects.requireNonNull(q)));
+    query = paramsWithoutQt(q);
   }
 
   public QueryRequest(SolrParams q, METHOD method) {
-    super(method, null);
-    query = q;
+    super(method, pathFromParams(Objects.requireNonNull(q)));
+    query = paramsWithoutQt(q);
   }
 
-  /** Use the params 'QT' parameter if it exists */
-  @Override
-  public String getPath() {
-    String qt = query == null ? null : 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) {
+    super(METHOD.GET, Objects.requireNonNull(path));
+    query = Objects.requireNonNull(q);
+  }
+
+  public QueryRequest(String path, SolrParams q, METHOD method) {
+    super(method, Objects.requireNonNull(path));
+    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.java
new file mode 100644
index 00000000000..8cbff949e85
--- /dev/null
+++ 
b/solr/solrj/src/test/org/apache/solr/client/solrj/request/QueryRequestTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.SolrQuery;
+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"));
+  }
+}

Reply via email to