lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1522680 - in /lucene/dev/trunk/solr: core/src/java/org/apache/solr/update/ core/src/test/org/apache/solr/update/ solrj/src/java/org/apache/solr/client/solrj/util/ solrj/src/java/org/apache/solr/common/ solrj/src/java/org/apache/solr/common...
Date Thu, 12 Sep 2013 17:44:10 GMT
Author: yonik
Date: Thu Sep 12 17:44:09 2013
New Revision: 1522680

URL: http://svn.apache.org/r1522680
Log:
SOLR-5148: optimization - lazy create child doc list

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java?rev=1522680&r1=1522679&r2=1522680&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java Thu Sep
12 17:44:09 2013
@@ -197,8 +197,11 @@ public class AddUpdateCommand extends Up
   }
 
   private void recUnwrapp(List<SolrInputDocument> unwrappedDocs, SolrInputDocument
currentDoc) {
-    for (SolrInputDocument child : currentDoc.getChildDocuments()) {
-      recUnwrapp(unwrappedDocs, child);
+    List<SolrInputDocument> children = currentDoc.getChildDocuments();
+    if (children != null) {
+      for (SolrInputDocument child : children) {
+        recUnwrapp(unwrappedDocs, child);
+      }
     }
     unwrappedDocs.add(currentDoc);
   }

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java?rev=1522680&r1=1522679&r2=1522680&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java Thu
Sep 12 17:44:09 2013
@@ -424,7 +424,8 @@ public class AddBlockUpdateTest extends 
     assertEquals("v2", result.getFieldValue("parent_f2"));
     
     List<SolrInputDocument> resultChilds = result.getChildDocuments();
-    assertEquals(childsNum, resultChilds.size());
+    int resultChildsSize = resultChilds == null ? 0 : resultChilds.size();
+    assertEquals(childsNum, resultChildsSize);
     
     for (int childIndex = 0; childIndex < childsNum; ++childIndex) {
       SolrInputDocument child = resultChilds.get(childIndex);
@@ -433,7 +434,9 @@ public class AddBlockUpdateTest extends 
       }
       
       List<SolrInputDocument> grandChilds = child.getChildDocuments();
-      assertEquals(childIndex * 2, grandChilds.size());
+      int grandChildsSize = grandChilds == null ? 0 : grandChilds.size();
+
+      assertEquals(childIndex * 2, grandChildsSize);
       for (int grandIndex = 0; grandIndex < childIndex * 2; ++grandIndex) {
         SolrInputDocument grandChild = grandChilds.get(grandIndex);
         assertFalse(grandChild.hasChildDocuments());

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java?rev=1522680&r1=1522679&r2=1522680&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
(original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
Thu Sep 12 17:44:09 2013
@@ -133,9 +133,11 @@ public class ClientUtils 
         }
       }
     }
-    
-    for (SolrInputDocument childDocument : doc.getChildDocuments()) {
-      writeXML(childDocument, writer);
+
+    if (doc.hasChildDocuments()) {
+      for (SolrInputDocument childDocument : doc.getChildDocuments()) {
+        writeXML(childDocument, writer);
+      }
     }
     
     writer.write("</doc>");

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java?rev=1522680&r1=1522679&r2=1522680&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java Thu
Sep 12 17:44:09 2013
@@ -43,12 +43,10 @@ public class SolrInputDocument implement
   
   public SolrInputDocument() {
     _fields = new LinkedHashMap<String,SolrInputField>();
-    _childDocuments = new ArrayList<SolrInputDocument>();
   }
   
   public SolrInputDocument(Map<String,SolrInputField> fields) {
     _fields = fields;
-    _childDocuments = new ArrayList<SolrInputDocument>();
   }
   
   /**
@@ -60,9 +58,7 @@ public class SolrInputDocument implement
     if( _fields != null ) {
       _fields.clear();      
     }
-    if (_childDocuments != null) {
-      _childDocuments.clear();
-    }
+    _childDocuments = null;
   }
 
   ///////////////////////////////////////////////////////////////////
@@ -198,7 +194,9 @@ public class SolrInputDocument implement
   @Override
   public String toString()
   {
-    return "SolrInputDocument(fields: " + _fields.values() + ", childs: " + _childDocuments
+ ")";
+    return "SolrInputDocument(fields: " + _fields.values()
+        + ( _childDocuments == null ? "" : (", children: " + _childDocuments) )
+        + ")";
   }
   
   public SolrInputDocument deepCopy() {
@@ -208,11 +206,13 @@ public class SolrInputDocument implement
       clone._fields.put(fieldEntry.getKey(), fieldEntry.getValue().deepCopy());
     }
     clone._documentBoost = _documentBoost;
-    
-    clone._childDocuments = new ArrayList<SolrInputDocument>(_childDocuments.size());
-    for (SolrInputDocument child : _childDocuments) {
-      clone._childDocuments.add(child.deepCopy());  
-    }    
+
+    if (_childDocuments != null) {
+      clone._childDocuments = new ArrayList<SolrInputDocument>(_childDocuments.size());
+      for (SolrInputDocument child : _childDocuments) {
+        clone._childDocuments.add(child.deepCopy());
+      }
+    }
     
     return clone;
   }
@@ -277,6 +277,9 @@ public class SolrInputDocument implement
   }
   
   public void addChildDocument(SolrInputDocument child) {
+   if (_childDocuments == null) {
+     _childDocuments = new ArrayList<SolrInputDocument>();
+   }
     _childDocuments.add(child);
   }
   
@@ -285,7 +288,8 @@ public class SolrInputDocument implement
       addChildDocument(child);
     }
   }
-  
+
+  /** Returns the list of child documents, or null if none. */
   public List<SolrInputDocument> getChildDocuments() {
     return _childDocuments;
   }

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java?rev=1522680&r1=1522679&r2=1522680&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java Thu
Sep 12 17:44:09 2013
@@ -387,7 +387,8 @@ public class JavaBinCodec {
 
   public void writeSolrInputDocument(SolrInputDocument sdoc) throws IOException {
     writeTag(SOLRINPUTDOC, sdoc.size());
-    writeTag(SOLRINPUTDOC_CHILDS, sdoc.getChildDocuments().size());    
+    List<SolrInputDocument> children = sdoc.getChildDocuments();
+    writeTag(SOLRINPUTDOC_CHILDS, children==null ? 0 : children.size());
     writeFloat(sdoc.getDocumentBoost());
     for (SolrInputField inputField : sdoc.values()) {
       if (inputField.getBoost() != 1.0f) {
@@ -396,8 +397,10 @@ public class JavaBinCodec {
       writeExternString(inputField.getName());
       writeVal(inputField.getValue());
     }
-    for (SolrInputDocument child : sdoc.getChildDocuments()) {
-      writeSolrInputDocument(child);
+    if (children != null) {
+      for (SolrInputDocument child : sdoc.getChildDocuments()) {
+        writeSolrInputDocument(child);
+      }
     }
   }
 



Mime
View raw message