summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2020-03-15 09:19:26 +0100
committerMarkus Heiser <markus.heiser@darmarit.de>2020-03-15 09:19:26 +0100
commit26b85659c0b7c9bf545dfe4edeedc3ccf247bc97 (patch)
tree4123d4d529e59186f43293b9945c3d3e3fa64a18
parent80f7b658047a3541697ef5ae1aae897817b3f43c (diff)
parent8e727ac77f5db59c1b772d9fd7603b519badb35a (diff)
downloadsearxng-26b85659c0b7c9bf545dfe4edeedc3ccf247bc97.tar.gz
searxng-26b85659c0b7c9bf545dfe4edeedc3ccf247bc97.zip
Merge branch 'master' of https://github.com/asciimoo/searx into filtron
-rw-r--r--searx/templates/__common__/opensearch_response_rss.xml24
-rw-r--r--searx/webapp.py18
-rw-r--r--tests/unit/test_webapp.py6
3 files changed, 43 insertions, 5 deletions
diff --git a/searx/templates/__common__/opensearch_response_rss.xml b/searx/templates/__common__/opensearch_response_rss.xml
index 32c42e7c7..3781dd87c 100644
--- a/searx/templates/__common__/opensearch_response_rss.xml
+++ b/searx/templates/__common__/opensearch_response_rss.xml
@@ -25,5 +25,29 @@
{% if r.pubdate %}<pubDate>{{ r.pubdate }}</pubDate>{% endif %}
</item>
{% endfor %}
+ {% if answers %}
+ {% for a in answers %}
+ <item>
+ <title>{{ a }}</title>
+ <type>answer</type>
+ </item>
+ {% endfor %}
+ {% endif %}
+ {% if corrections %}
+ {% for a in corrections %}
+ <item>
+ <title>{{ a }}</title>
+ <type>correction</type>
+ </item>
+ {% endfor %}
+ {% endif %}
+ {% if suggestions %}
+ {% for a in suggestions %}
+ <item>
+ <title>{{ a }}</title>
+ <type>suggestion</type>
+ </item>
+ {% endfor %}
+ {% endif %}
</channel>
</rss>
diff --git a/searx/webapp.py b/searx/webapp.py
index b661e39d1..0c5ed4570 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -626,20 +626,34 @@ def index():
mimetype='application/json')
elif output_format == 'csv':
csv = UnicodeWriter(StringIO())
- keys = ('title', 'url', 'content', 'host', 'engine', 'score')
+ keys = ('title', 'url', 'content', 'host', 'engine', 'score', 'type')
csv.writerow(keys)
for row in results:
row['host'] = row['parsed_url'].netloc
+ row['type'] = 'result'
+ csv.writerow([row.get(key, '') for key in keys])
+ for a in result_container.answers:
+ row = {'title': a, 'type': 'answer'}
+ csv.writerow([row.get(key, '') for key in keys])
+ for a in result_container.suggestions:
+ row = {'title': a, 'type': 'suggestion'}
+ csv.writerow([row.get(key, '') for key in keys])
+ for a in result_container.corrections:
+ row = {'title': a, 'type': 'correction'}
csv.writerow([row.get(key, '') for key in keys])
csv.stream.seek(0)
response = Response(csv.stream.read(), mimetype='application/csv')
- cont_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search_query.query)
+ cont_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search_query.query.decode('utf-8'))
response.headers.add('Content-Disposition', cont_disp)
return response
elif output_format == 'rss':
+ print(results)
response_rss = render(
'opensearch_response_rss.xml',
results=results,
+ answers=result_container.answers,
+ corrections=result_container.corrections,
+ suggestions=result_container.suggestions,
q=request.form['q'],
number_of_results=number_of_results,
base_url=get_base_url(),
diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py
index 72ace4850..f31332fa0 100644
--- a/tests/unit/test_webapp.py
+++ b/tests/unit/test_webapp.py
@@ -99,9 +99,9 @@ class ViewsTestCase(SearxTestCase):
result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
self.assertEqual(
- b'title,url,content,host,engine,score\r\n'
- b'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,\r\n' # noqa
- b'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,\r\n', # noqa
+ b'title,url,content,host,engine,score,type\r\n'
+ b'First Test,http://first.test.xyz,first test content,first.test.xyz,startpage,,result\r\n' # noqa
+ b'Second Test,http://second.test.xyz,second test content,second.test.xyz,youtube,,result\r\n', # noqa
result.data
)