1616 */
1717package org .apache .solr .handler .component ;
1818
19+ import static org .apache .solr .cloud .AbstractZkTestCase .SOLRHOME ;
20+
1921import java .io .IOException ;
2022import java .util .ArrayList ;
2123import java .util .Arrays ;
2224import java .util .List ;
2325import org .apache .solr .client .solrj .response .QueryResponse ;
2426import org .apache .solr .cloud .AbstractFullDistribZkTestBase ;
27+ import org .apache .solr .cloud .ZkTestServer ;
2528import org .apache .solr .common .SolrInputDocument ;
2629import org .apache .solr .common .params .CommonParams ;
2730import org .apache .solr .common .params .ShardParams ;
@@ -49,6 +52,12 @@ public CombinedQuerySolrCloudTest() {
4952 configString = "solrconfig-combined-query.xml" ;
5053 }
5154
55+ @ Override
56+ public void distribSetUp () throws Exception {
57+ super .distribSetUp ();
58+ ZkTestServer .putConfig ("conf1" , zkServer .getZkClient (), SOLRHOME , "elevate.xml" );
59+ }
60+
5261 @ Override
5362 protected String getCloudSchemaFile () {
5463 return "schema-vector-catchall.xml" ;
@@ -121,7 +130,7 @@ public void testSingleLexicalQuery() throws Exception {
121130 query (
122131 CommonParams .JSON ,
123132 "{\" queries\" :"
124- + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:2^10\" }}},"
133+ + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:2^= 10\" }}},"
125134 + "\" limit\" :5,"
126135 + "\" fields\" :[\" id\" ,\" score\" ,\" title\" ],"
127136 + "\" params\" :{\" combiner\" :true,\" combiner.query\" :[\" lexical1\" ]}}" ,
@@ -141,8 +150,8 @@ public void testMultipleLexicalQuery() throws Exception {
141150 prepareIndexDocs ();
142151 String jsonQuery =
143152 "{\" queries\" :"
144- + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^2 OR 3^1 OR 6^2 OR 5^1)\" }},"
145- + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^1 OR 5^2 OR 7^3 OR 10^2)\" }}},"
153+ + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^=4 OR 3^=2 OR 6^=3 OR 5^= 1)\" }},"
154+ + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^= 1 OR 5^=3 OR 7^=4 OR 10^= 2)\" }}},"
146155 + "\" limit\" :5,"
147156 + "\" fields\" :[\" id\" ,\" score\" ,\" title\" ],"
148157 + "\" params\" :{\" combiner\" :true,\" combiner.query\" :[\" lexical1\" ,\" lexical2\" ]}}" ;
@@ -161,8 +170,8 @@ public void testMultipleQueryWithSort() throws Exception {
161170 prepareIndexDocs ();
162171 String jsonQuery =
163172 "{\" queries\" :"
164- + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^2 OR 3^1 OR 6^2 OR 5^1)\" }},"
165- + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^1 OR 5^2 OR 7^3 OR 10^1 )\" }}},"
173+ + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^=4 OR 3^=2 OR 6^=3 OR 5^= 1)\" }},"
174+ + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^= 1 OR 5^=3 OR 7^=4 OR 10^=2 )\" }}},"
166175 + "\" limit\" :5,\" sort\" :\" mod3_idv desc, score desc\" "
167176 + "\" fields\" :[\" id\" ,\" score\" ,\" title\" ],"
168177 + "\" params\" :{\" combiner\" :true,\" combiner.query\" :[\" lexical1\" ,\" lexical2\" ]}}" ;
@@ -183,8 +192,8 @@ public void testHybridQueryWithPagination() throws Exception {
183192 query (
184193 CommonParams .JSON ,
185194 "{\" queries\" :"
186- + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^2 OR 3^1 OR 6^2 OR 5^1)\" }},"
187- + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^1 OR 5^2 OR 7^3 OR 10^2)\" }}},"
195+ + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^=4 OR 3^=2 OR 6^=3 OR 5^= 1)\" }},"
196+ + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^= 1 OR 5^=3 OR 7^=4 OR 10^= 2)\" }}},"
188197 + "\" fields\" :[\" id\" ,\" score\" ,\" title\" ],"
189198 + "\" params\" :{\" combiner\" :true,\" combiner.query\" :[\" lexical1\" ,\" lexical2\" ]}}" ,
190199 CommonParams .QT ,
@@ -194,8 +203,8 @@ public void testHybridQueryWithPagination() throws Exception {
194203 query (
195204 CommonParams .JSON ,
196205 "{\" queries\" :"
197- + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^2 OR 3^1 OR 6^2 OR 5^1)\" }},"
198- + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^1 OR 5^2 OR 7^3 OR 10^2)\" }}},"
206+ + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^=4 OR 3^=2 OR 6^=3 OR 5^= 1)\" }},"
207+ + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^= 1 OR 5^=3 OR 7^=4 OR 10^= 2)\" }}},"
199208 + "\" limit\" :4,"
200209 + "\" fields\" :[\" id\" ,\" score\" ,\" title\" ],"
201210 + "\" params\" :{\" combiner\" :true,\" combiner.query\" :[\" lexical1\" ,\" lexical2\" ]}}" ,
@@ -206,8 +215,8 @@ public void testHybridQueryWithPagination() throws Exception {
206215 query (
207216 CommonParams .JSON ,
208217 "{\" queries\" :"
209- + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^2 OR 3^1 OR 6^2 OR 5^1)\" }},"
210- + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^1 OR 5^2 OR 7^3 OR 10^2)\" }}},"
218+ + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^=4 OR 3^=2 OR 6^=3 OR 5^= 1)\" }},"
219+ + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^= 1 OR 5^=3 OR 7^=4 OR 10^= 2)\" }}},"
211220 + "\" limit\" :4,\" offset\" :3,"
212221 + "\" fields\" :[\" id\" ,\" score\" ,\" title\" ],"
213222 + "\" params\" :{\" combiner\" :true,\" combiner.query\" :[\" lexical1\" ,\" lexical2\" ]}}" ,
@@ -227,7 +236,7 @@ public void testQueryWithFaceting() throws Exception {
227236 prepareIndexDocs ();
228237 String jsonQuery =
229238 "{\" queries\" :"
230- + "{\" lexical\" :{\" lucene\" :{\" query\" :\" id:(2^2 OR 3^1 OR 6^2 OR 5^1)\" }}},"
239+ + "{\" lexical\" :{\" lucene\" :{\" query\" :\" id:(2^= 2 OR 3^= 1 OR 6^= 2 OR 5^= 1)\" }}},"
231240 + "\" limit\" :3,\" offset\" :1"
232241 + "\" fields\" :[\" id\" ,\" score\" ,\" title\" ],"
233242 + "\" params\" :{\" combiner\" :true,\" facet\" :true,\" facet.field\" :\" mod3_idv\" ,\" facet.mincount\" :1,"
@@ -248,8 +257,8 @@ public void testQueriesWithFacetAndHighlights() throws Exception {
248257 prepareIndexDocs ();
249258 String jsonQuery =
250259 "{\" queries\" :"
251- + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^2 OR 3^1 OR 6^2 OR 5^1)\" }},"
252- + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^1 OR 5^2 OR 7^3 OR 10^2)\" }}},"
260+ + "{\" lexical1\" :{\" lucene\" :{\" query\" :\" id:(2^=4 OR 3^=2 OR 6^=3 OR 5^= 1)\" }},"
261+ + "\" lexical2\" :{\" lucene\" :{\" query\" :\" id:(8^= 1 OR 5^=3 OR 7^=4 OR 10^= 2)\" }}},"
253262 + "\" limit\" :4,"
254263 + "\" fields\" :[\" id\" ,\" score\" ,\" title\" ],"
255264 + "\" params\" :{\" combiner\" :true,\" facet\" :true,\" facet.field\" :\" mod3_idv\" ,"
@@ -269,6 +278,48 @@ public void testQueriesWithFacetAndHighlights() throws Exception {
269278 rsp .getHighlighting ().get ("5" ).get ("title" ).getFirst ());
270279 }
271280
281+ /**
282+ * Tests the combined query feature with faceting, highlighting and elevation.
283+ *
284+ * @throws Exception if any unexpected error occurs during the test execution.
285+ */
286+ @ Test
287+ public void testElevatedQueriesWithFacetAndHighlights () throws Exception {
288+ prepareIndexDocs ();
289+ String jsonQuery =
290+ """
291+ {
292+ "queries": {
293+ "lexical1": {"lucene": {"query": "id:(2^=3 OR 3^=1 OR 6^=2 OR 5^=2)"}},
294+ "lexical2": {"lucene": {"query": "id:(4^=1 OR 5^=2 OR 7^=3 OR 10^=2)"}}
295+ },
296+ "limit": 4,
297+ "fields": ["id", "score", "title"],
298+ "params": {
299+ "combiner": true,
300+ "elevateIds": "6,10",
301+ "combiner.query": ["lexical1", "lexical2"],
302+ "facet": true,
303+ "facet.field": "mod3_idv",
304+ "hl": true,
305+ "hl.fl": "title",
306+ "hl.q": "test doc"
307+ }
308+ }""" ;
309+ QueryResponse rsp = query (CommonParams .JSON , jsonQuery , CommonParams .QT , "/search-elevate" );
310+ assertEquals (4 , rsp .getResults ().size ());
311+ assertFieldValues (rsp .getResults (), id , "6" , "10" , "5" , "7" );
312+ assertEquals ("mod3_idv" , rsp .getFacetFields ().getFirst ().getName ());
313+ assertEquals ("[1 (3), 0 (2), 2 (2)]" , rsp .getFacetFields ().getFirst ().getValues ().toString ());
314+ assertEquals (4 , rsp .getHighlighting ().size ());
315+ assertEquals (
316+ "title <em>test</em> for <em>doc</em> 10" ,
317+ rsp .getHighlighting ().get ("10" ).get ("title" ).getFirst ());
318+ assertEquals (
319+ "title <em>test</em> for <em>doc</em> 5" ,
320+ rsp .getHighlighting ().get ("5" ).get ("title" ).getFirst ());
321+ }
322+
272323 /**
273324 * Tests the combined query feature with faceting, highlighting and collapse.
274325 *
@@ -284,12 +335,12 @@ public void testQueriesWithFacetAndHighlightsCollapse() throws Exception {
284335 "queries": {
285336 "lexical1": {
286337 "lucene": {
287- "query": "id:(CO!2^3 OR CO!3^1 OR CO!6^2 OR CO!5^1)"
338+ "query": "id:(CO!2^= 3 OR CO!3^= 1 OR CO!6^= 2 OR CO!5^= 1)"
288339 }
289340 },
290341 "lexical2": {
291342 "lucene": {
292- "query": "id:(CO!8^1 OR CO!5^2 OR CO!7^3 OR CO!10^2)"
343+ "query": "id:(CO!8^= 1 OR CO!5^= 2 OR CO!7^= 3 OR CO!10^= 2)"
293344 }
294345 }
295346 },
0 commit comments