You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by va...@apache.org on 2015/04/01 10:38:22 UTC

svn commit: r1670579 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/handler/component/ solr/core/src/test/org/apache/solr/handler/component/ solr/solrj/ solr/solrj/src/java/org/apache/solr/client/solrj/respo...

Author: varun
Date: Wed Apr  1 08:38:22 2015
New Revision: 1670579

URL: http://svn.apache.org/r1670579
Log:
SOLR-6709: Fix QueryResponse to deal with the expanded section when using the XMLResponseParser (merged from trunk r1670569)

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java
    lucene/dev/branches/branch_5x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java
    lucene/dev/branches/branch_5x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java

Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1670579&r1=1670578&r2=1670579&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Wed Apr  1 08:38:22 2015
@@ -28,6 +28,8 @@ New Features
 Bug Fixes
 ----------------------
 
+* SOLR-6709: Fix QueryResponse to deal with the "expanded" section when using the XMLResponseParser
+  (Varun Thacker, Joel Bernstein)
 Optimizations
 ----------------------
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java?rev=1670579&r1=1670578&r2=1670579&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java Wed Apr  1 08:38:22 2015
@@ -27,6 +27,15 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import com.carrotsearch.hppc.IntObjectOpenHashMap;
+import com.carrotsearch.hppc.IntOpenHashSet;
+import com.carrotsearch.hppc.LongObjectMap;
+import com.carrotsearch.hppc.LongObjectOpenHashMap;
+import com.carrotsearch.hppc.LongOpenHashSet;
+import com.carrotsearch.hppc.cursors.IntObjectCursor;
+import com.carrotsearch.hppc.cursors.LongCursor;
+import com.carrotsearch.hppc.cursors.LongObjectCursor;
+import com.carrotsearch.hppc.cursors.ObjectCursor;
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.DocValuesType;
 import org.apache.lucene.index.FieldInfo;
@@ -62,6 +71,7 @@ import org.apache.solr.common.SolrDocume
 import org.apache.solr.common.params.ExpandParams;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.core.PluginInfo;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.request.SolrQueryRequest;
@@ -82,16 +92,6 @@ import org.apache.solr.search.SolrIndexS
 import org.apache.solr.util.plugin.PluginInfoInitialized;
 import org.apache.solr.util.plugin.SolrCoreAware;
 
-import com.carrotsearch.hppc.IntObjectOpenHashMap;
-import com.carrotsearch.hppc.IntOpenHashSet;
-import com.carrotsearch.hppc.LongObjectMap;
-import com.carrotsearch.hppc.LongObjectOpenHashMap;
-import com.carrotsearch.hppc.LongOpenHashSet;
-import com.carrotsearch.hppc.cursors.IntObjectCursor;
-import com.carrotsearch.hppc.cursors.LongCursor;
-import com.carrotsearch.hppc.cursors.LongObjectCursor;
-import com.carrotsearch.hppc.cursors.ObjectCursor;
-
 /**
  * The ExpandComponent is designed to work with the CollapsingPostFilter.
  * The CollapsingPostFilter collapses a result set on a field.
@@ -384,7 +384,7 @@ public class ExpandComponent extends Sea
       searcher.search(new FilteredQuery(query, pfilter.filter), collector);
     }
     LongObjectMap groups = ((GroupCollector)groupExpandCollector).getGroups();
-    Map<String, DocSlice> outMap = new HashMap<>();
+    NamedList outMap = new SimpleOrderedMap();
     CharsRefBuilder charsRef = new CharsRefBuilder();
     for (LongObjectCursor cursor : (Iterable<LongObjectCursor>) groups) {
       long groupValue = cursor.key;
@@ -405,14 +405,14 @@ public class ExpandComponent extends Sea
           final BytesRef bytesRef = ordBytes.get((int)groupValue);
           fieldType.indexedToReadable(bytesRef, charsRef);
           String group = charsRef.toString();
-          outMap.put(group, slice);
+          outMap.add(group, slice);
         } else {
           if(fieldType instanceof TrieIntField || fieldType instanceof TrieLongField ) {
-            outMap.put(Long.toString(groupValue), slice);
+            outMap.add(Long.toString(groupValue), slice);
           } else if(fieldType instanceof TrieFloatField) {
-            outMap.put(Float.toString(Float.intBitsToFloat((int)groupValue)), slice);
+            outMap.add(Float.toString(Float.intBitsToFloat((int) groupValue)), slice);
           } else if(fieldType instanceof TrieDoubleField) {
-            outMap.put(Double.toString(Double.longBitsToDouble(groupValue)), slice);
+            outMap.add(Double.toString(Double.longBitsToDouble(groupValue)), slice);
           }
         }
       }
@@ -450,19 +450,19 @@ public class ExpandComponent extends Sea
 
     if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
       SolrQueryRequest req = rb.req;
-      Map expanded = (Map) req.getContext().get("expanded");
+      NamedList expanded = (NamedList) req.getContext().get("expanded");
       if (expanded == null) {
-        expanded = new HashMap();
+        expanded = new SimpleOrderedMap();
         req.getContext().put("expanded", expanded);
       }
 
       for (ShardResponse srsp : sreq.responses) {
         NamedList response = srsp.getSolrResponse().getResponse();
-        Map ex = (Map) response.get("expanded");
-        for (Map.Entry<String, SolrDocumentList> entry : (Iterable<Map.Entry<String, SolrDocumentList>>) ex.entrySet()) {
-          String name = entry.getKey();
-          SolrDocumentList val = entry.getValue();
-          expanded.put(name, val);
+        NamedList ex = (NamedList) response.get("expanded");
+        for (int i=0; i<ex.size(); i++) {
+          String name = ex.getName(i);
+          SolrDocumentList val = (SolrDocumentList) ex.getVal(i);
+          expanded.add(name, val);
         }
       }
     }
@@ -479,9 +479,9 @@ public class ExpandComponent extends Sea
       return;
     }
 
-    Map expanded = (Map) rb.req.getContext().get("expanded");
+    NamedList expanded = (NamedList) rb.req.getContext().get("expanded");
     if (expanded == null) {
-      expanded = new HashMap();
+      expanded = new SimpleOrderedMap();
     }
 
     rb.rsp.add("expanded", expanded);

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java?rev=1670579&r1=1670578&r2=1670579&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java Wed Apr  1 08:38:22 2015
@@ -78,6 +78,7 @@ public class DistributedExpandComponentT
     handle.put("q", SKIP);
     handle.put("maxScore", SKIPVAL);
     handle.put("_version_", SKIP);
+    handle.put("expanded", UNORDERED);
 
     query("q", "*:*", "fq", "{!collapse field="+group+"}", "defType", "edismax", "bf", "field(test_ti)", "expand", "true", "fl","*,score");
     query("q", "*:*", "fq", "{!collapse field="+group+"}", "defType", "edismax", "bf", "field(test_ti)", "expand", "true", "expand.sort", "test_tl desc", "fl","*,score");

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java?rev=1670579&r1=1670578&r2=1670579&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java (original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java Wed Apr  1 08:38:22 2015
@@ -17,13 +17,6 @@
 
 package org.apache.solr.client.solrj.response;
 
-import org.apache.solr.client.solrj.SolrClient;
-import org.apache.solr.client.solrj.beans.DocumentObjectBinder;
-import org.apache.solr.common.SolrDocumentList;
-import org.apache.solr.common.params.CursorMarkParams;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.SimpleOrderedMap;
-
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -32,6 +25,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.beans.DocumentObjectBinder;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.params.CursorMarkParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SimpleOrderedMap;
+
 /**
  * 
  *
@@ -86,7 +86,7 @@ public class QueryResponse extends SolrR
 
   // utility variable used for automatic binding -- it should not be serialized
   private transient final SolrClient solrClient;
-  
+
   public QueryResponse(){
     solrClient = null;
   }
@@ -134,7 +134,8 @@ public class QueryResponse extends SolrR
         extractGroupedInfo( _groupedInfo );
       }
       else if("expanded".equals(n)) {
-        _expandedResults = (Map<String, SolrDocumentList>) res.getVal( i );
+        NamedList map = (NamedList) res.getVal(i);
+        _expandedResults = map.asMap(1);
       }
       else if( "highlighting".equals( n ) ) {
         _highlightingInfo = (NamedList<Object>) res.getVal( i );
@@ -480,7 +481,13 @@ public class QueryResponse extends SolrR
     return _facetQuery;
   }
 
-  public Map<String, SolrDocumentList> getExpandedResults(){
+  /**
+   *
+   * @return map with each group value as key and the expanded documents that belong to the group as value.
+   * There is no guarantee on the order of the keys obtained via an iterator.
+   *
+   */
+  public Map<String, SolrDocumentList> getExpandedResults() {
     return this._expandedResults;
   }
 

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java?rev=1670579&r1=1670578&r2=1670579&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java (original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java Wed Apr  1 08:38:22 2015
@@ -46,6 +46,7 @@ import org.apache.solr.common.SolrInputD
 import org.apache.solr.common.params.AnalysisParams;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.FacetParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.util.NamedList;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -1587,6 +1588,41 @@ abstract public class SolrExampleTests e
   }
 
   @Test
+  public void testExpandComponent() throws IOException, SolrServerException {
+    SolrClient server = getSolrClient();
+    server.deleteByQuery("*:*");
+
+    ArrayList<SolrInputDocument> docs = new ArrayList<>();
+    docs.add( makeTestDoc("id","1", "term_s", "YYYY", "group_s", "group1", "test_ti", "5", "test_tl", "10", "test_tf", "2000", "type_s", "parent"));
+    docs.add( makeTestDoc("id","2", "term_s","YYYY", "group_s", "group1", "test_ti", "50", "test_tl", "100", "test_tf", "200", "type_s", "child"));
+    docs.add( makeTestDoc("id","3", "term_s", "YYYY", "test_ti", "5000", "test_tl", "100", "test_tf", "200"));
+    docs.add( makeTestDoc("id","4", "term_s", "YYYY", "test_ti", "500", "test_tl", "1000", "test_tf", "2000"));
+    docs.add( makeTestDoc("id","5", "term_s", "YYYY", "group_s", "group2", "test_ti", "4", "test_tl", "10", "test_tf", "2000", "type_s", "parent"));
+    docs.add( makeTestDoc("id","6", "term_s","YYYY", "group_s", "group2", "test_ti", "10", "test_tl", "100", "test_tf", "200", "type_s", "child"));
+    docs.add( makeTestDoc("id","7", "term_s", "YYYY", "group_s", "group1", "test_ti", "1", "test_tl", "100000", "test_tf", "2000", "type_s", "child"));
+    docs.add( makeTestDoc("id","8", "term_s","YYYY", "group_s", "group2", "test_ti", "2", "test_tl", "100000", "test_tf", "200", "type_s", "child"));
+
+    server.add(docs);
+    server.commit();
+
+    ModifiableSolrParams msParams = new ModifiableSolrParams();
+    msParams.add("q", "*:*");
+    msParams.add("fq", "{!collapse field=group_s}");
+    msParams.add("defType", "edismax");
+    msParams.add("bf", "field(test_ti)");
+    msParams.add("expand", "true");
+    QueryResponse resp = server.query(msParams);
+
+    Map<String, SolrDocumentList> expanded = resp.getExpandedResults();
+    assertEquals(2, expanded.size());
+    assertEquals("1", expanded.get("group1").get(0).get("id"));
+    assertEquals("7", expanded.get("group1").get(1).get("id"));
+    assertEquals("5", expanded.get("group2").get(0).get("id"));
+    assertEquals("8", expanded.get("group2").get(1).get("id"));
+
+  }
+
+  @Test
   public void testFieldGlobbing() throws Exception  {
     SolrClient client = getSolrClient();