You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2014/08/12 09:00:55 UTC

svn commit: r1617424 - in /lucene/dev/trunk/solr/solrj/src: java/org/apache/solr/common/util/JsonRecordReader.java test/org/apache/solr/common/util/TestJsonRecordReader.java

Author: noble
Date: Tue Aug 12 07:00:55 2014
New Revision: 1617424

URL: http://svn.apache.org/r1617424
Log:
SOLR-6304 wildcard fix

Modified:
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java
    lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java?rev=1617424&r1=1617423&r2=1617424&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java Tue Aug 12 07:00:55 2014
@@ -98,7 +98,7 @@ public class JsonRecordReader {
     if ("".equals(paths.get(0).trim()))
       paths.remove(0);
     rootNode.build(paths, fieldName, multiValued, isRecord, path);
-//    rootNode.buildOptimise(null);
+    rootNode.buildOptimize();
   }
 
   /**
@@ -154,8 +154,6 @@ public class JsonRecordReader {
     String fieldName; // the fieldname in the emitted record (key of the map)
     String splitPath; // the full path from the forEach entity attribute
     final LinkedHashMap<String ,Node> childNodes = new LinkedHashMap<>(); // List of immediate child Nodes of this node
-    List<Node> wildCardNodes; // List of '//' style decendants of this Node
-    Node wildAncestor; // ancestor Node containing '//' style decendants
     Node parent; // parent Node in the tree
     boolean isLeaf = false; // flag: store/emit streamed text for this node
     boolean isRecord = false; //flag: this Node starts a new record
@@ -179,14 +177,13 @@ public class JsonRecordReader {
 
     /**
      * Walk the Node tree propagating any wildDescentant information to
-     * child nodes. This allows us to optimise the performance of the
-     * main getInst method.
+     * child nodes.
      */
-    private void buildOptimise(Node wa) {
-      wildAncestor = wa;
-      if (wildCardNodes != null) wa = this;
-      if (childNodes != null)
-        for (Node n : childNodes.values()) n.buildOptimise(wa);
+    private void buildOptimize() {
+      if(parent != null && parent.recursiveWildCardChild !=null && this.recursiveWildCardChild ==null){
+        this.recursiveWildCardChild = parent.recursiveWildCardChild;
+      }
+      for (Node n : childNodes.values()) n.buildOptimize();
     }
     static final String WILDCARD_PATH = "*";
     static final String RECURSIVE_WILDCARD_PATH = "**";
@@ -259,7 +256,7 @@ public class JsonRecordReader {
      * deep-copied for thread safety
      */
     private static Map<String, Object> getDeepCopy(Map<String, Object> values) {
-      Map<String, Object> result = new HashMap<>();
+      Map<String, Object> result = new LinkedHashMap<>();
       for (Map.Entry<String, Object> entry : values.entrySet()) {
         if (entry.getValue() instanceof List) {
           result.put(entry.getKey(), new ArrayList((List) entry.getValue()));

Modified: lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java?rev=1617424&r1=1617423&r2=1617424&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java (original)
+++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java Tue Aug 12 07:00:55 2014
@@ -156,4 +156,37 @@ public class TestJsonRecordReader  exten
 
   }
 
+  public void testRecursiveWildcard2() throws Exception{
+    String json = "{\n" +
+        "  \"first\": \"John\",\n" +
+        "  \"last\": \"Doe\",\n" +
+        "  \"grade\": 8,\n" +
+        "  \"exams\": [\n" +
+        "      {\n" +
+        "        \"subject\": \"Maths\",\n" +
+        "        \"test\"   : \"term1\",\n" +
+        "        \"marks\":90},\n" +
+        "        {\n" +
+        "         \"subject\": \"Biology\",\n" +
+        "         \"test\"   : \"term1\",\n" +
+        "         \"marks\":86}\n" +
+        "      ]\n" +
+        "}";
+
+    JsonRecordReader streamer;
+    List<Map<String, Object>> records;
+
+    streamer = JsonRecordReader.getInst("/exams", Collections.singletonList("/**"));
+    records = streamer.getAllRecords(new StringReader(json));
+    assertEquals(2, records.size());
+    for (Map<String, Object> record : records) {
+      assertEquals(6,record.size());
+    }
+    streamer = JsonRecordReader.getInst("/", Collections.singletonList("txt:/**"));
+    records = streamer.getAllRecords(new StringReader(json));
+    assertEquals(1, records.size());
+    assertEquals(9, ((List)records.get(0).get("txt")).size() );
+
+  }
+
 }