def get_results_from_search_response(response):
parsed = response.json()
formatted_results = []
for result in parsed['hits']['hits']:
formatted = format_company_details(result['_source'])
if 'highlight' in result:
highlighted = '...'.join(
result['highlight'].get('description', '') or
result['highlight'].get('summary', '')
)
# escape all html tags other than <em> and </em>
highlighted_escaped = (
escape(highlighted)
.replace('<em>', '<em>')
.replace('</em>', '</em>')
)
formatted['highlight'] = mark_safe(highlighted_escaped)
formatted_results.append(formatted)
parsed['results'] = formatted_results
return parsed
评论列表
文章目录