public void writeSolrDocument(SolrDocument doc) throws IOException { List<SolrDocument> children = doc.getChildDocuments(); int fieldsCount = 0; if (writableDocFields == null || writableDocFields.wantsAllFields() || ignoreWritable) { fieldsCount = doc.size(); } else { for (Entry<String, Object> e : doc) { if (toWrite(e.getKey())) fieldsCount++; } } int sz = fieldsCount + (children == null ? 0 : children.size()); writeTag(SOLRDOC); writeTag(ORDERED_MAP, sz); for (Map.Entry<String, Object> entry : doc) { String name = entry.getKey(); if (toWrite(name)) { writeExternString(name); Object val = entry.getValue(); writeVal(val); } } if (children != null) { try { ignoreWritable = true; for (SolrDocument child : children) { writeSolrDocument(child); } } finally { ignoreWritable = false; } } }
public boolean isSame(SolrIndexSearchMailDocument o) { if (this == o) { return true; // objects are the same } if (null == o) { return false; // dest is null } if (m_doc != null && o.m_doc != null) { if (m_doc.size() != o.m_doc.size()) { return false; // docs have different number of elements } for (String fieldName : m_doc.getFieldNames()) { if (!o.m_doc.containsKey(fieldName)) { return false; // a key was found in src but not in the dest } final Object srcValue = m_doc.get(fieldName); final Object destValue = o.m_doc.get(fieldName); if (srcValue == null ^ destValue == null) { return false; // one value is null } else if (srcValue != null && destValue != null) { if (srcValue instanceof Collection && destValue instanceof Collection) { Collection srcThings = (Collection) srcValue; Collection destThings = (Collection) destValue; if (srcThings.size() != destThings.size()) { return false; // src and dest contain different counts of elements } if (!srcThings.containsAll(destThings)) { return false; // contents of src and dest do not match } } else if (!srcValue.equals(destValue)) { return false; // values are different } } // else { both null and equal } } } else if ((m_doc != null) ^ (o.m_doc != null)) { return false; // one has a document and the other doesn't } // else { both are null and equal } return true; }