From 6d03baa485711283d61306fcac022e47aa263f4c Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki Date: Tue, 10 Dec 2019 20:44:08 +0100 Subject: [PATCH] SOLR-13806: SolrJ QueryResponse._explainMap is incorrectly typed. --- solr/CHANGES.txt | 7 + .../client/solrj/response/QueryResponse.java | 8 +- .../test-files/solrj/sampleDebugResponse.xml | 206 ++++++++++++++++++ .../solrj/response/QueryResponseTest.java | 27 +++ 4 files changed, 244 insertions(+), 4 deletions(-) create mode 100644 solr/solrj/src/test-files/solrj/sampleDebugResponse.xml diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index a65dc8ea6f5..0b9af781ffc 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -114,6 +114,11 @@ Upgrade Notes up by Solr's http server that contains inline javascript, it will no longer execute in modern browsers. You can fix your JS code to not run inline anymore, or edit etc/jetty.xml and weaken the CSP, or remove/alter the headers with a reverse proxy. (rmuir) +* SOLR-13806: QueryResponse.getExplainMap() type has changed from Map to Map + in order to accommodate structured explanations. This is a partially back-compatible change - compiled + third-party components will work the same as before due to type erasure but source code changes may be + required. + New Features --------------------- * SOLR-13821: A Package store to store and load package artifacts (noble, Ishan Chattopadhyaya) @@ -223,6 +228,8 @@ Bug Fixes * SOLR-13563: SPLITSHARD using LINK method fails on disk usage checks. (Andrew Kettmann, ab) +* SOLR-13806: SolrJ QueryResponse._explainMap is incorrectly typed. (Guna Sekhar Dorai, ab) + Other Changes --------------------- diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java index cdb64e3a015..92db560055e 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java @@ -95,7 +95,7 @@ public class QueryResponse extends SolrResponseBase // Debug Info private Map _debugMap = null; - private Map _explainMap = null; + private Map _explainMap = null; // utility variable used for automatic binding -- it should not be serialized private transient final SolrClient solrClient; @@ -239,9 +239,9 @@ public class QueryResponse extends SolrResponseBase // Parse out interesting bits from the debug info _explainMap = new HashMap<>(); - NamedList explain = (NamedList)_debugMap.get( "explain" ); + NamedList explain = (NamedList)_debugMap.get( "explain" ); if( explain != null ) { - for( Map.Entry info : explain ) { + for( Map.Entry info : explain ) { String key = info.getKey(); _explainMap.put( key, info.getValue() ); } @@ -522,7 +522,7 @@ public class QueryResponse extends SolrResponseBase return _debugMap; } - public Map getExplainMap() { + public Map getExplainMap() { return _explainMap; } diff --git a/solr/solrj/src/test-files/solrj/sampleDebugResponse.xml b/solr/solrj/src/test-files/solrj/sampleDebugResponse.xml new file mode 100644 index 00000000000..6a749292d3e --- /dev/null +++ b/solr/solrj/src/test-files/solrj/sampleDebugResponse.xml @@ -0,0 +1,206 @@ + + + + + + 0 + 3 + + name:"corsair" + true + true + + + + + VS1GB400C3 + CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail + Corsair Microsystems Inc. + corsair + + electronics + memory + + 74.99 + 74.99,USD + 7 + true + 37.7752,-100.0232 + 2006-02-13T15:26:37Z + 2006-02-13T15:26:37Z + electronics|4.0 memory|2.0 + 1651790000473243648 + + + TWINX2048-3200PRO + CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail + Corsair Microsystems Inc. + corsair + + electronics + memory + + + CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader + + 185.0 + 185.00,USD + 5 + true + 37.7752,-122.4232 + 2006-02-13T15:26:37Z + 2006-02-13T15:26:37Z + electronics|6.0 memory|3.0 + 1651790000320151552 + + + + name:"corsair" + name:"corsair" + name:corsair + name:corsair + + + true + 1.4886642 + weight(name:corsair in 1) [SchemaSimilarity], result of: + + + true + 1.4886642 + score(doc=1,freq=1.0 = termFreq=1.0), product of: + + + true + 2.1747518 + idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from: + + + true + 2.0 + docFreq + + + true + 21.0 + docCount + + + + + true + 0.68452144 + tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from: + + + true + 1.0 + termFreq=1.0 + + + true + 1.2 + parameter k1 + + + true + 0.75 + parameter b + + + true + 7.5238094 + avgFieldLength + + + true + 16.0 + fieldLength + + + + + + + + + true + 1.0174209 + weight(name:corsair in 0) [SchemaSimilarity], result of: + + + true + 1.0174209 + score(doc=0,freq=1.0 = termFreq=1.0), product of: + + + true + 2.1747518 + idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from: + + + true + 2.0 + docFreq + + + true + 21.0 + docCount + + + + + true + 0.4678331 + tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from: + + + true + 1.0 + termFreq=1.0 + + + true + 1.2 + parameter k1 + + + true + 0.75 + parameter b + + + true + 7.5238094 + avgFieldLength + + + true + 28.444445 + fieldLength + + + + + + + + + + diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java index cbdc73f5e96..af9da260582 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/response/QueryResponseTest.java @@ -16,6 +16,7 @@ */ package org.apache.solr.client.solrj.response; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; @@ -23,6 +24,7 @@ import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.Date; import java.util.List; +import java.util.Map; import junit.framework.Assert; import org.apache.lucene.util.TestRuleLimitSysouts.Limit; @@ -30,6 +32,7 @@ import org.apache.solr.SolrTestCase; import org.apache.solr.client.solrj.impl.XMLResponseParser; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.util.NamedList; +import org.apache.solr.common.util.SimpleOrderedMap; import org.apache.solr.core.SolrResourceLoader; import org.junit.Test; @@ -299,4 +302,28 @@ public class QueryResponseTest extends SolrTestCase { } + @Test + public void testExplainMapResponse() throws IOException { + XMLResponseParser parser = new XMLResponseParser(); + NamedList response; + + try (SolrResourceLoader loader = new SolrResourceLoader(); + InputStream is = loader.openResource("solrj/sampleDebugResponse.xml")) { + assertNotNull(is); + try (Reader in = new InputStreamReader(is, StandardCharsets.UTF_8)) { + response = parser.processResponse(in); + } + } + + QueryResponse qr = new QueryResponse(response, null); + assertNotNull(qr); + + Map explainMap = qr.getExplainMap(); + assertNotNull(explainMap); + assertEquals(2, explainMap.size()); + Object[] values = explainMap.values().toArray(); + assertTrue(values[0] instanceof SimpleOrderedMap); + assertTrue(values[1] instanceof SimpleOrderedMap); + } + }