queryJson) {
return this;
}
+ /**
+ * Specify the queries parameter sent as a part of JSON request.
+ *
+ * This method would be helpful in setting the queries parameter specially for Combined Query
+ * Component {@code CombinedQueryComponent} use case.
+ *
+ *
Example: You wish to send the JSON request:
+ *
+ *
{@code {'limit': 5, 'queries': {'query1': {'lucene':
+ * {'df':'genre_s', 'query': 'scifi'}}}, 'query2': {'knn': {'f': 'vector', 'query': [0.1, 0.43]}}}}
+ *
+ *
+ * @param queriesJson a Map of values representing the query subtree of the JSON request you wish
+ * to send.
+ */
+ public JsonQueryRequest setQueries(Map queriesJson) {
+ jsonRequestMap.put("queries", queriesJson);
+ return this;
+ }
+
/**
* Specify the query sent as a part of this JSON request.
*
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java
index dc516e00f3ab..b43310e8fe17 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
@@ -45,6 +46,7 @@ public class JsonQueryRequestIntegrationTest extends SolrCloudTestCase {
private static final int NUM_SCIFI_BOOKS = 2;
private static final int NUM_IN_STOCK = 8;
private static final int NUM_IN_STOCK_AND_FIRST_IN_SERIES = 5;
+ private static final int NUM_MARTIN_BOOKS = 3;
@BeforeClass
public static void setupCluster() throws Exception {
@@ -88,6 +90,29 @@ public void testQueriesCanUseLocalParamsSyntax() throws Exception {
assertEquals(NUM_SCIFI_BOOKS, queryResponse.getResults().getNumFound());
}
+ /**
+ * Test multiple queries can use local params syntax with Combined Query Component.
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public void testMultipleQueriesCanUseLocalParamsSyntax() throws Exception {
+ final Map queriesMap = new HashMap<>();
+ queriesMap.put("query1", "{!lucene df=genre_s v='scifi'}");
+ queriesMap.put("query2", "{!edismax df=author_t v='martin'}");
+ final JsonQueryRequest query =
+ new JsonQueryRequest()
+ .setQueries(queriesMap)
+ .withFilter("inStock:true")
+ .withParam("fl", "name")
+ .withParam("combiner", "true")
+ .withParam("combiner.query", List.of("query1", "query2"));
+ query.setPath("/rrf");
+ QueryResponse queryResponse = query.process(cluster.getSolrClient(), COLLECTION_NAME);
+ assertEquals(0, queryResponse.getStatus());
+ assertEquals(NUM_SCIFI_BOOKS + NUM_MARTIN_BOOKS, queryResponse.getResults().size());
+ }
+
@Test
public void testQueriesCanUseExpandedSyntax() throws Exception {
// Construct a tree representing the JSON: {lucene: {df:'genre_s', 'query': 'scifi'}}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestUnitTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestUnitTest.java
index 6297c56cd6c0..51a407ce5265 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestUnitTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestUnitTest.java
@@ -88,6 +88,29 @@ public void testWritesProvidedQueryMapToJsonCorrectly() {
requestBody, containsString("\"query\":{\"lucene\":{\"q\":\"*:*\",\"df\":\"text\"}}"));
}
+ @Test
+ public void testWritesProvidedQueriesMapToJsonCorrectly() {
+ final Map queriesMap = new HashMap<>();
+ queriesMap.put(
+ "query1",
+ Map.of(
+ "lucene",
+ Map.of(
+ "query", "*:*",
+ "df", "text")));
+ queriesMap.put(
+ "query2",
+ Map.of(
+ "edismax",
+ Map.of(
+ "query", "solr",
+ "df", "text")));
+ final JsonQueryRequest request = new JsonQueryRequest().setQueries(queriesMap);
+ final String requestBody = writeRequestToJson(request);
+ assertThat(requestBody, containsString("\"query1\":{\"lucene\":"));
+ assertThat(requestBody, containsString("\"query2\":{\"edismax\":"));
+ }
+
@Test
public void testWritesProvidedQueryMapWriterToJsonCorrectly() {
final MapWriter queryWriter =