Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;

Expand All @@ -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;
}

// ---------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}