on master help sign in
[fix] add answers, suggestions, corrections to csv output

fixes #1888

commit018b6818419a1c3044b7d7244b55a62779063071 authorAdam Tauber <asciimoo@gmail.com> dateFri 13 Mar 2020, 00:50 (7 years ago) parent9bc2408
1 file changed+11−1
searx/webapp.py+11−1
searx/webapp.py+11−1
@@ -626,10 +626,20 @@ def index():
626626 mimetype='application/json')
627627 elif output_format == 'csv':
628628 csv = UnicodeWriter(StringIO())
629− keys = ('title', 'url', 'content', 'host', 'engine', 'score')
629+ keys = ('title', 'url', 'content', 'host', 'engine', 'score', 'type')
630630 csv.writerow(keys)
631631 for row in results:
632632 row['host'] = row['parsed_url'].netloc
633+ row['type'] = 'result'
634+ csv.writerow([row.get(key, '') for key in keys])
635+ for a in result_container.answers:
636+ row = {'title': a, 'type': 'answer'}
637+ csv.writerow([row.get(key, '') for key in keys])
638+ for a in result_container.suggestions:
639+ row = {'title': a, 'type': 'suggestion'}
640+ csv.writerow([row.get(key, '') for key in keys])
641+ for a in result_container.corrections:
642+ row = {'title': a, 'type': 'correction'}
633643 csv.writerow([row.get(key, '') for key in keys])
634644 csv.stream.seek(0)
635645 response = Response(csv.stream.read(), mimetype='application/csv')