def build_results_list(pages, is_json):
    """Takes a paginated search and returns results List

    Handles wiki documents, questions and contributor forum posts.

    :arg pages: paginated S
    :arg is_json: whether or not this is generated results for json output

    :returns: list of dicts

    """
    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:
                # We're excerpting only question_content, so if the query matched
                # question_title or question_answer_content, then there won't be any
                # question_content excerpts. In that case, just show the question--but
                # only the first 500 characters.
                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
dataset/ETHPy150Open mozilla/kitsune/kitsune/search/views.py/build_results_list/original