You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2019/12/10 19:44:27 UTC

[lucene-solr] branch master updated: SOLR-13806: SolrJ QueryResponse._explainMap is incorrectly typed.

This is an automated email from the ASF dual-hosted git repository.

ab pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 6d03baa  SOLR-13806: SolrJ QueryResponse._explainMap is incorrectly typed.
6d03baa is described below

commit 6d03baa485711283d61306fcac022e47aa263f4c
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Tue Dec 10 20:44:08 2019 +0100

    SOLR-13806: SolrJ QueryResponse._explainMap is incorrectly typed.
---
 solr/CHANGES.txt                                   |   7 +
 .../solr/client/solrj/response/QueryResponse.java  |   8 +-
 .../src/test-files/solrj/sampleDebugResponse.xml   | 206 +++++++++++++++++++++
 .../client/solrj/response/QueryResponseTest.java   |  27 +++
 4 files changed, 244 insertions(+), 4 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a65dc8e..0b9af78 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<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
 ---------------------
 
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 cdb64e3..92db560 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<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;
   }
 
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 0000000..6a74929
--- /dev/null
+++ b/solr/solrj/src/test-files/solrj/sampleDebugResponse.xml
@@ -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>
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 cbdc73f..af9da26 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<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);
+  }
+
 }