You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cm...@apache.org on 2013/08/13 07:20:49 UTC

svn commit: r1513349 [2/2] - in /lucene/dev/branches/lucene4956: ./ dev-tools/ dev-tools/idea/solr/core/src/java/ dev-tools/idea/solr/core/src/test/ dev-tools/maven/solr/core/src/java/ dev-tools/maven/solr/core/src/test/ lucene/ lucene/analysis/ lucene...

Modified: lucene/dev/branches/lucene4956/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4956/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java?rev=1513349&r1=1513348&r2=1513349&view=diff
==============================================================================
--- lucene/dev/branches/lucene4956/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java (original)
+++ lucene/dev/branches/lucene4956/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java Tue Aug 13 05:20:47 2013
@@ -18,9 +18,12 @@
 package org.apache.solr.common;
 
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -36,13 +39,16 @@ public class SolrInputDocument implement
 {
   private final Map<String,SolrInputField> _fields;
   private float _documentBoost = 1.0f;
-
+  private List<SolrInputDocument> _childDocuments;
+  
   public SolrInputDocument() {
     _fields = new LinkedHashMap<String,SolrInputField>();
+    _childDocuments = new ArrayList<SolrInputDocument>();
   }
   
   public SolrInputDocument(Map<String,SolrInputField> fields) {
     _fields = fields;
+    _childDocuments = new ArrayList<SolrInputDocument>();
   }
   
   /**
@@ -52,7 +58,10 @@ public class SolrInputDocument implement
   public void clear()
   {
     if( _fields != null ) {
-      _fields.clear();
+      _fields.clear();      
+    }
+    if (_childDocuments != null) {
+      _childDocuments.clear();
     }
   }
 
@@ -189,7 +198,7 @@ public class SolrInputDocument implement
   @Override
   public String toString()
   {
-    return "SolrInputDocument" + _fields.values();
+    return "SolrInputDocument(fields: " + _fields.values() + ", childs: " + _childDocuments + ")";
   }
   
   public SolrInputDocument deepCopy() {
@@ -199,6 +208,12 @@ 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());  
+    }    
+    
     return clone;
   }
 
@@ -260,4 +275,23 @@ public class SolrInputDocument implement
   public Collection<SolrInputField> values() {
     return _fields.values();
   }
+  
+  public void addChildDocument(SolrInputDocument child) {
+    _childDocuments.add(child);
+  }
+  
+  public void addChildDocuments(Collection<SolrInputDocument> childs) {
+    for (SolrInputDocument child : childs) {
+      addChildDocument(child);
+    }
+  }
+  
+  public List<SolrInputDocument> getChildDocuments() {
+    return _childDocuments;
+  }
+  
+  public boolean hasChildDocuments() {
+    boolean isEmpty = (_childDocuments == null || _childDocuments.isEmpty());
+    return !isEmpty;
+  }
 }

Modified: lucene/dev/branches/lucene4956/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4956/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java?rev=1513349&r1=1513348&r2=1513349&view=diff
==============================================================================
--- lucene/dev/branches/lucene4956/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java (original)
+++ lucene/dev/branches/lucene4956/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java Tue Aug 13 05:20:47 2013
@@ -62,6 +62,7 @@ public class JavaBinCodec {
           END = 15,
 
           SOLRINPUTDOC = 16,
+          SOLRINPUTDOC_CHILDS = 17,
 
           // types that combine tag + length (or other info) in a single byte
           TAG_AND_LEN = (byte) (1 << 5),
@@ -358,6 +359,8 @@ public class JavaBinCodec {
 
   public SolrInputDocument readSolrInputDocument(DataInputInputStream dis) throws IOException {
     int sz = readVInt(dis);
+    dis.readByte(); // skip childDocuments tag
+    int childsSize = readVInt(dis);
     float docBoost = (Float)readVal(dis);
     SolrInputDocument sdoc = new SolrInputDocument();
     sdoc.setDocumentBoost(docBoost);
@@ -374,11 +377,17 @@ public class JavaBinCodec {
       Object fieldVal = readVal(dis);
       sdoc.setField(fieldName, fieldVal, boost);
     }
+    for (int i = 0; i < childsSize; i++) {
+      dis.readByte(); // skip solrinputdoc tag
+      SolrInputDocument child = readSolrInputDocument(dis);
+      sdoc.addChildDocument(child);
+    }
     return sdoc;
   }
 
   public void writeSolrInputDocument(SolrInputDocument sdoc) throws IOException {
     writeTag(SOLRINPUTDOC, sdoc.size());
+    writeTag(SOLRINPUTDOC_CHILDS, sdoc.getChildDocuments().size());    
     writeFloat(sdoc.getDocumentBoost());
     for (SolrInputField inputField : sdoc.values()) {
       if (inputField.getBoost() != 1.0f) {
@@ -387,6 +396,9 @@ public class JavaBinCodec {
       writeExternString(inputField.getName());
       writeVal(inputField.getValue());
     }
+    for (SolrInputDocument child : sdoc.getChildDocuments()) {
+      writeSolrInputDocument(child);
+    }
   }
 
 

Modified: lucene/dev/branches/lucene4956/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4956/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java?rev=1513349&r1=1513348&r2=1513349&view=diff
==============================================================================
--- lucene/dev/branches/lucene4956/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/branches/lucene4956/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java Tue Aug 13 05:20:47 2013
@@ -72,6 +72,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -969,6 +970,10 @@ public abstract class SolrTestCaseJ4 ext
     return sd;
   }
 
+  public static List<SolrInputDocument> sdocs(SolrInputDocument... docs) {
+    return Arrays.asList(docs);
+  }
+
   /** Converts "test JSON" and returns standard JSON.
    *  Currently this only consists of changing unescaped single quotes to double quotes,
    *  and escaped single quotes to single quotes.
@@ -1527,7 +1532,7 @@ public abstract class SolrTestCaseJ4 ext
   }
 
   /** Return a Map from field value to a list of document ids */
-  Map<Comparable, List<Comparable>> invertField(Map<Comparable, Doc> model, String field) {
+  public Map<Comparable, List<Comparable>> invertField(Map<Comparable, Doc> model, String field) {
     Map<Comparable, List<Comparable>> value_to_id = new HashMap<Comparable, List<Comparable>>();
 
     // invert field