SOLR-13806: SolrJ QueryResponse._explainMap is incorrectly typed.

This commit is contained in:
Andrzej Bialecki 2019-12-10 20:44:08 +01:00
parent 8c6a2640ed
commit 6d03baa485
4 changed files with 244 additions and 4 deletions

View File

@ -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<String, String> to Map<String, Object>
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
---------------------

View File

@ -95,7 +95,7 @@ public class QueryResponse extends SolrResponseBase
// Debug Info
private Map<String,Object> _debugMap = null;
private Map<String,String> _explainMap = null;
private Map<String,Object> _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<String> explain = (NamedList<String>)_debugMap.get( "explain" );
NamedList<Object> explain = (NamedList<Object>)_debugMap.get( "explain" );
if( explain != null ) {
for( Map.Entry<String, String> info : explain ) {
for( Map.Entry<String, Object> info : explain ) {
String key = info.getKey();
_explainMap.put( key, info.getValue() );
}
@ -522,7 +522,7 @@ public class QueryResponse extends SolrResponseBase
return _debugMap;
}
public Map<String, String> getExplainMap() {
public Map<String, Object> getExplainMap() {
return _explainMap;
}

View File

@ -0,0 +1,206 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">3</int>
<lst name="params">
<str name="q">name:"corsair"</str>
<str name="debug">true</str>
<str name="debug.explain.structured">true</str>
</lst>
</lst>
<result name="response" numFound="2" start="0">
<doc>
<str name="id">VS1GB400C3</str>
<str name="name">CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail</str>
<str name="manu">Corsair Microsystems Inc.</str>
<str name="manu_id_s">corsair</str>
<arr name="cat">
<str>electronics</str>
<str>memory</str>
</arr>
<float name="price">74.99</float>
<str name="price_c">74.99,USD</str>
<int name="popularity">7</int>
<bool name="inStock">true</bool>
<str name="store">37.7752,-100.0232</str>
<date name="manufacturedate_dt">2006-02-13T15:26:37Z</date>
<date name="manufacturedate_pdt">2006-02-13T15:26:37Z</date>
<str name="payloads">electronics|4.0 memory|2.0</str>
<long name="_version_">1651790000473243648</long>
</doc>
<doc>
<str name="id">TWINX2048-3200PRO</str>
<str name="name">CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail</str>
<str name="manu">Corsair Microsystems Inc.</str>
<str name="manu_id_s">corsair</str>
<arr name="cat">
<str>electronics</str>
<str>memory</str>
</arr>
<arr name="features">
<str>CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader</str>
</arr>
<float name="price">185.0</float>
<str name="price_c">185.00,USD</str>
<int name="popularity">5</int>
<bool name="inStock">true</bool>
<str name="store">37.7752,-122.4232</str>
<date name="manufacturedate_dt">2006-02-13T15:26:37Z</date>
<date name="manufacturedate_pdt">2006-02-13T15:26:37Z</date>
<str name="payloads">electronics|6.0 memory|3.0</str>
<long name="_version_">1651790000320151552</long>
</doc>
</result>
<lst name="debug">
<str name="rawquerystring">name:"corsair"</str>
<str name="querystring">name:"corsair"</str>
<str name="parsedquery">name:corsair</str>
<str name="parsedquery_toString">name:corsair</str>
<lst name="explain">
<lst name="VS1GB400C3">
<bool name="match">true</bool>
<float name="value">1.4886642</float>
<str name="description">weight(name:corsair in 1) [SchemaSimilarity], result of:</str>
<arr name="details">
<lst>
<bool name="match">true</bool>
<float name="value">1.4886642</float>
<str name="description">score(doc=1,freq=1.0 = termFreq=1.0), product of:</str>
<arr name="details">
<lst>
<bool name="match">true</bool>
<float name="value">2.1747518</float>
<str name="description">idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:</str>
<arr name="details">
<lst>
<bool name="match">true</bool>
<float name="value">2.0</float>
<str name="description">docFreq</str>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">21.0</float>
<str name="description">docCount</str>
</lst>
</arr>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">0.68452144</float>
<str name="description">tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:</str>
<arr name="details">
<lst>
<bool name="match">true</bool>
<float name="value">1.0</float>
<str name="description">termFreq=1.0</str>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">1.2</float>
<str name="description">parameter k1</str>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">0.75</float>
<str name="description">parameter b</str>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">7.5238094</float>
<str name="description">avgFieldLength</str>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">16.0</float>
<str name="description">fieldLength</str>
</lst>
</arr>
</lst>
</arr>
</lst>
</arr>
</lst>
<lst name="TWINX2048-3200PRO">
<bool name="match">true</bool>
<float name="value">1.0174209</float>
<str name="description">weight(name:corsair in 0) [SchemaSimilarity], result of:</str>
<arr name="details">
<lst>
<bool name="match">true</bool>
<float name="value">1.0174209</float>
<str name="description">score(doc=0,freq=1.0 = termFreq=1.0), product of:</str>
<arr name="details">
<lst>
<bool name="match">true</bool>
<float name="value">2.1747518</float>
<str name="description">idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:</str>
<arr name="details">
<lst>
<bool name="match">true</bool>
<float name="value">2.0</float>
<str name="description">docFreq</str>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">21.0</float>
<str name="description">docCount</str>
</lst>
</arr>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">0.4678331</float>
<str name="description">tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:</str>
<arr name="details">
<lst>
<bool name="match">true</bool>
<float name="value">1.0</float>
<str name="description">termFreq=1.0</str>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">1.2</float>
<str name="description">parameter k1</str>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">0.75</float>
<str name="description">parameter b</str>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">7.5238094</float>
<str name="description">avgFieldLength</str>
</lst>
<lst>
<bool name="match">true</bool>
<float name="value">28.444445</float>
<str name="description">fieldLength</str>
</lst>
</arr>
</lst>
</arr>
</lst>
</arr>
</lst>
</lst>
</lst>
</response>

View File

@ -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<Object> 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<String, Object> explainMap = qr.getExplainMap();
assertNotNull(explainMap);
assertEquals(2, explainMap.size());
Object[] values = explainMap.values().toArray();
assertTrue(values[0] instanceof SimpleOrderedMap);
assertTrue(values[1] instanceof SimpleOrderedMap);
}
}