SOLR-5148: optimization - lazy create child doc list

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1522680 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2013-09-12 17:44:09 +00:00
parent 534a9f3080
commit f2b3d010b3
5 changed files with 37 additions and 22 deletions

View File

@ -197,9 +197,12 @@ public class AddUpdateCommand extends UpdateCommand implements Iterable<IndexDoc
}
private void recUnwrapp(List<SolrInputDocument> unwrappedDocs, SolrInputDocument currentDoc) {
for (SolrInputDocument child : currentDoc.getChildDocuments()) {
List<SolrInputDocument> children = currentDoc.getChildDocuments();
if (children != null) {
for (SolrInputDocument child : children) {
recUnwrapp(unwrappedDocs, child);
}
}
unwrappedDocs.add(currentDoc);
}

View File

@ -424,7 +424,8 @@ public class AddBlockUpdateTest extends SolrTestCaseJ4 {
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 SolrTestCaseJ4 {
}
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());

View File

@ -134,9 +134,11 @@ public class ClientUtils
}
}
if (doc.hasChildDocuments()) {
for (SolrInputDocument childDocument : doc.getChildDocuments()) {
writeXML(childDocument, writer);
}
}
writer.write("</doc>");
}

View File

@ -43,12 +43,10 @@ public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<S
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 implements Map<String,SolrInputField>, Iterable<S
if( _fields != null ) {
_fields.clear();
}
if (_childDocuments != null) {
_childDocuments.clear();
}
_childDocuments = null;
}
///////////////////////////////////////////////////////////////////
@ -198,7 +194,9 @@ public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<S
@Override
public String toString()
{
return "SolrInputDocument(fields: " + _fields.values() + ", childs: " + _childDocuments + ")";
return "SolrInputDocument(fields: " + _fields.values()
+ ( _childDocuments == null ? "" : (", children: " + _childDocuments) )
+ ")";
}
public SolrInputDocument deepCopy() {
@ -209,10 +207,12 @@ public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<S
}
clone._documentBoost = _documentBoost;
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 implements Map<String,SolrInputField>, Iterable<S
}
public void addChildDocument(SolrInputDocument child) {
if (_childDocuments == null) {
_childDocuments = new ArrayList<SolrInputDocument>();
}
_childDocuments.add(child);
}
@ -286,6 +289,7 @@ public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<S
}
}
/** Returns the list of child documents, or null if none. */
public List<SolrInputDocument> getChildDocuments() {
return _childDocuments;
}

View File

@ -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,10 +397,12 @@ public class JavaBinCodec {
writeExternString(inputField.getName());
writeVal(inputField.getValue());
}
if (children != null) {
for (SolrInputDocument child : sdoc.getChildDocuments()) {
writeSolrInputDocument(child);
}
}
}
public Map<Object,Object> readMap(DataInputInputStream dis)