def add_documents_to_index(documents, index, retries=DEFAULT_NUM_RETRIES):
 if (not isinstance(index, basestring)):
  raise ValueError(('Index must be the unicode/str name of an index, got %s' % type(index)))
 index = gae_search.Index(index)
 gae_docs = [_dict_to_search_document(d) for d in documents]
 try:
  logging.debug('adding the following docs to index %s: %s', index.name, documents)
  results = index.put(gae_docs, deadline=5)
 except gae_search.PutError as e:
  logging.exception('PutError raised.')
  if (retries > 1):
   for res in e.results:
    if (res.code == gae_search.OperationResult.TRANSIENT_ERROR):
     new_retries = (retries - 1)
     logging.debug(('%d tries left, retrying.' % new_retries))
     return add_documents_to_index(documents=documents, index=index.name, retries=new_retries)
  raise SearchFailureError(e)
 return [r.id for r in results]

def add_documents_to_index ( documents , index , retries = DEFAULT_NUM_RETRIES ) : if ( not isinstance ( index , basestring ) ) : raise ValueError ( ( 'Index must be the unicode/str name of an index, got %s' % type ( index ) ) ) index = gae_search . Index ( index ) gae_docs = [ _dict_to_search_document ( d ) for d in documents ] try : logging . debug ( 'adding the following docs to index %s: %s' , index . name , documents ) results = index . put ( gae_docs , deadline = 5 ) except gae_search . PutError as e : logging . exception ( 'PutError raised.' ) if ( retries > 1 ) : for res in e . results : if ( res . code == gae_search . OperationResult . TRANSIENT_ERROR ) : new_retries = ( retries - 1 ) logging . debug ( ( '%d tries left, retrying.' % new_retries ) ) return add_documents_to_index ( documents = documents , index = index . name , retries = new_retries ) raise SearchFailureError ( e ) return [ r . id for r in results ]
adds a document to an index .