def __add_new_doc(self, doc, new_result, index):
    new_doc = new_result.mutable_document()
    new_doc.set_id(doc['id'])
    new_doc.set_language(doc[Document.INDEX_LOCALE][0])
    for key in doc.keys():
      if not key.startswith(index.name):
        continue
      field_name = key.split("{0}_".format(index.name), 1)[1]
      new_field = new_doc.add_field() 
      new_field.set_name(field_name)
      new_value = new_field.mutable_value()
      field_type = ""
      for field in index.schema.fields:
        if field['name'] == "{0}_{1}".format(index.name, field_name):
          field_type = field['type']
      if field_type == "":
        logging.warning("Unable to find type for {0}").format(
          "{0}_{1}".format(index.name, field_name))
      self.__add_field_value(new_value, doc[key], field_type)
Add a new document to a query result.
dataset/ETHPy150Open AppScale/appscale/SearchService/solr_interface.py/Solr.__add_new_doc