Java Code Examples for org.apache.solr.common.SolrInputDocument#hasChildDocuments()

The following examples show how to use org.apache.solr.common.SolrInputDocument#hasChildDocuments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrExampleTests.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** 
 * Depth first search of a SolrInputDocument looking for a decendent by id, 
 * returns null if it's not a decendent 
 */
private SolrInputDocument findDecendent(SolrInputDocument parent, String childId) {
  if (childId.equals(parent.getFieldValue("id"))) {
    return parent;
  }
  if (! parent.hasChildDocuments() ) {
    return null;
  }
  for (SolrInputDocument kid : parent.getChildDocuments()) {
    SolrInputDocument result = findDecendent(kid, childId);
    if (null != result) {
      return result;
    }
  }
  return null;
}
 
Example 2
Source File: RowMutationHelper.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
public static RowMutation from(SolrInputDocument doc, String table) {
  validateAsRow(doc);

  RowMutation mutate = new RowMutation();
  String rowid = extractRowId(doc);
  mutate.setRowId(rowid);
  mutate.setTable(table);
  List<RecordMutation> recordMutations = Lists.newArrayList();

  if (doc.hasChildDocuments()) {
    for (SolrInputDocument child : doc.getChildDocuments()) {
      validateAsRecord(child);
      recordMutations.add(createRecordMutation(child, extractRecordId(child)));
    }

  }
  mutate.setRecordMutations(recordMutations);
  return mutate;
}
 
Example 3
Source File: DebugInfo.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public boolean add(SolrInputDocument e) {
  SolrInputDocument transformed = e.deepCopy();
  if (transformed.hasChildDocuments()) {
    ChildRollupDocs childList = new ChildRollupDocs();
    childList.addAll(transformed.getChildDocuments());
    transformed.addField("_childDocuments_", childList);
    transformed.getChildDocuments().clear();
  }
  return delegate.add(transformed);
}
 
Example 4
Source File: AddUpdateCommand.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void flattenLabelled(List<SolrInputDocument> unwrappedDocs, SolrInputDocument currentDoc) {
  if(currentDoc.hasChildDocuments()) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "Anonymous child docs can only hang from others or the root: " + currentDoc);
  }
  flattenLabelled(unwrappedDocs, currentDoc, false);
}
 
Example 5
Source File: IgnoreLargeDocumentProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
static long estimate(SolrInputDocument doc) {
  if (doc == null) return 0L;
  long size = 0;
  for (SolrInputField inputField : doc.values()) {
    size += primitiveEstimate(inputField.getName(), 0L);
    size += estimate(inputField.getValue());
  }

  if (doc.hasChildDocuments()) {
    for (SolrInputDocument childDoc : doc.getChildDocuments()) {
      size += estimate(childDoc);
    }
  }
  return size;
}
 
Example 6
Source File: ClientUtils.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"unchecked"})
public static void writeXML( SolrInputDocument doc, Writer writer ) throws IOException
{
  writer.write("<doc>");

  for( SolrInputField field : doc ) {
    String name = field.getName();

    for( Object v : field ) {
      String update = null;

      if(v instanceof SolrInputDocument) {
        writeVal(writer, name, v , null);
      } else if (v instanceof Map) {
        // currently only supports a single value
        for (Entry<Object,Object> entry : ((Map<Object,Object>)v).entrySet()) {
          update = entry.getKey().toString();
          v = entry.getValue();
          if (v instanceof Collection) {
            @SuppressWarnings({"rawtypes"})
            Collection values = (Collection) v;
            for (Object value : values) {
              writeVal(writer, name, value, update);
            }
          } else  {
            writeVal(writer, name, v, update);
          }
        }
      } else  {
        writeVal(writer, name, v, update);
      }
    }
  }

  if (doc.hasChildDocuments()) {
    for (SolrInputDocument childDocument : doc.getChildDocuments()) {
      writeXML(childDocument, writer);
    }
  }
  
  writer.write("</doc>");
}