def build_results_list(pages, is_json):
 results = []
 for (rank, doc) in enumerate(pages, pages.start_index()):
  if (doc['model'] == 'wiki_document'):
   summary = _build_es_excerpt(doc)
   if (not summary):
    summary = doc['document_summary']
   result = {'title': doc['document_title'], 'type': 'document'}
  elif (doc['model'] == 'questions_question'):
   summary = _build_es_excerpt(doc)
   if (not summary):
    summary = bleach.clean(doc['question_content'], strip=True)[:500]
   result = {'title': doc['question_title'], 'type': 'question', 'last_updated': datetime.fromtimestamp(doc['updated']), 'is_solved': doc['question_is_solved'], 'num_answers': doc['question_num_answers'], 'num_votes': doc['question_num_votes'], 'num_votes_past_week': doc['question_num_votes_past_week']}
  elif (doc['model'] == 'forums_thread'):
   summary = _build_es_excerpt(doc, first_only=True)
   result = {'title': doc['post_title'], 'type': 'thread'}
  else:
   raise UnknownDocType(('%s is an unknown doctype' % doc['model']))
  result['url'] = doc['url']
  if (not is_json):
   result['object'] = doc
  result['search_summary'] = summary
  result['rank'] = rank
  result['score'] = doc.es_meta.score
  result['explanation'] = escape(format_explanation(doc.es_meta.explanation))
  result['id'] = doc['id']
  results.append(result)
 return results

def build_results_list ( pages , is_json ) : results = [ ] for ( rank , doc ) in enumerate ( pages , pages . start_index ( ) ) : if ( doc [ 'model' ] == 'wiki_document' ) : summary = _build_es_excerpt ( doc ) if ( not summary ) : summary = doc [ 'document_summary' ] result = { 'title' : doc [ 'document_title' ] , 'type' : 'document' } elif ( doc [ 'model' ] == 'questions_question' ) : summary = _build_es_excerpt ( doc ) if ( not summary ) : summary = bleach . clean ( doc [ 'question_content' ] , strip = True ) [ : 500 ] result = { 'title' : doc [ 'question_title' ] , 'type' : 'question' , 'last_updated' : datetime . fromtimestamp ( doc [ 'updated' ] ) , 'is_solved' : doc [ 'question_is_solved' ] , 'num_answers' : doc [ 'question_num_answers' ] , 'num_votes' : doc [ 'question_num_votes' ] , 'num_votes_past_week' : doc [ 'question_num_votes_past_week' ] } elif ( doc [ 'model' ] == 'forums_thread' ) : summary = _build_es_excerpt ( doc , first_only = True ) result = { 'title' : doc [ 'post_title' ] , 'type' : 'thread' } else : raise UnknownDocType ( ( '%s is an unknown doctype' % doc [ 'model' ] ) ) result [ 'url' ] = doc [ 'url' ] if ( not is_json ) : result [ 'object' ] = doc result [ 'search_summary' ] = summary result [ 'rank' ] = rank result [ 'score' ] = doc . es_meta . score result [ 'explanation' ] = escape ( format_explanation ( doc . es_meta . explanation ) ) result [ 'id' ] = doc [ 'id' ] results . append ( result ) return results
takes a paginated search and returns results list handles wiki documents .