diff --git a/searx/engines/wolframalpha_api.py b/searx/engines/wolframalpha_api.py
index 6927f970..d4127be4 100644
--- a/searx/engines/wolframalpha_api.py
+++ b/searx/engines/wolframalpha_api.py
@@ -14,9 +14,7 @@ from lxml import etree
# search-url
base_url = 'http://api.wolframalpha.com/v2/query'
search_url = base_url + '?appid={api_key}&{query}&format=plaintext'
-site_url = 'http://www.wolframalpha.com/input/?{query}'
-search_query = ''
-api_key = ''
+api_key = '' # defined in settings.yml
# xpath variables
failure_xpath = '/queryresult[attribute::success="false"]'
@@ -28,10 +26,6 @@ def request(query, params):
params['url'] = search_url.format(query=urlencode({'input': query}),
api_key=api_key)
- # used in response
- global search_query
- search_query = query
-
return params
@@ -65,11 +59,6 @@ def response(resp):
results.append({'answer': answer})
- # result url
- result_url = site_url.format(query=urlencode({'i': search_query}))
-
- # append result
- results.append({'url': result_url,
- 'title': search_query + ' - Wolfram|Alpha'})
+ # TODO: append a result with title and link, like in the no api version
return results
diff --git a/searx/engines/wolframalpha_noapi.py b/searx/engines/wolframalpha_noapi.py
index 89a3c45b..d7442db5 100644
--- a/searx/engines/wolframalpha_noapi.py
+++ b/searx/engines/wolframalpha_noapi.py
@@ -53,7 +53,7 @@ def response(resp):
answer = line[line.find('{'):line.rfind('}')+1]
answer = loads(answer.encode('unicode-escape'))
answer = answer['stringified'].decode('unicode-escape')
-
+
results.append({'answer': answer})
# failed result
diff --git a/searx/settings.yml b/searx/settings.yml
index 510fc028..2c327184 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -305,7 +305,7 @@ engines:
# You can use the engine using the official stable API, but you need an API key
# See : http://products.wolframalpha.com/api/
# engine : wolframalpha_api
- # api_key: 'api_key' # required!
+ # api_key: 'apikey' # required!
engine : wolframalpha_noapi
timeout: 6.0
diff --git a/searx/tests/engines/test_wolframalpha_api.py b/searx/tests/engines/test_wolframalpha_api.py
index d295cea7..a4a4184c 100644
--- a/searx/tests/engines/test_wolframalpha_api.py
+++ b/searx/tests/engines/test_wolframalpha_api.py
@@ -59,228 +59,88 @@ class TestWolframAlphaAPIEngine(SearxTestCase):
response = mock.Mock(content=xml)
self.assertEqual(wolframalpha_api.response(response), [])
- xml = """
-
-
-
-
- sqrt(-1)
-
-
-
-
-
- i
-
-
-
-
-
-
-
-
- r = 1 (radius), theta = 90° (angle)
-
-
-
-
-
-
-
-
-
-
-
- i (principal root)
-
-
-
- -i
-
-
-
-
-
-
-
-
-
- """
- response = mock.Mock(content=xml)
- results = wolframalpha_api.response(response)
- self.assertEqual(type(results), list)
- self.assertEqual(len(results), 1)
- self.assertIn("i", results[0]['answer'])
-
xml = """
-
+
+ sqrt(-1)
+
+
+
-
- integral 1/x dx = log(x)+constant
+
+ input='Result__Step-by-step solution' />
-
-
-
-
-
-
-
-
-
+
+ r1 (radius), θ90° (angle)
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+ (principal root)
-
+ -
+
+
+
+
-
-
-
-
-
-
@@ -288,5 +148,107 @@ class TestWolframAlphaAPIEngine(SearxTestCase):
response = mock.Mock(content=xml)
results = wolframalpha_api.response(response)
self.assertEqual(type(results), list)
- self.assertEqual(len(results), 1)
+ self.assertEqual(len(results), 2)
+ self.assertIn("i", results[0]['answer'])
+ # self.assertIn("sqrt(-1) - Wolfram|Alpha", results[1]['title'])
+ # self.assertIn("http://www.wolframalpha.com/input/?i=sqrt%28-1%29", results[1]['url'])
+
+ xml = """
+
+
+
+ ∫1/xxlog(x)+constant
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ response = mock.Mock(content=xml)
+ results = wolframalpha_api.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 2)
self.assertIn("log(x)+c", results[0]['answer'])
+ # self.assertIn("integral 1/x - Wolfram|Alpha", results[1]['title'])
+ # self.assertIn("http://www.wolframalpha.com/input/?i=integral+1%2Fx", results[1]['url'])
diff --git a/searx/tests/engines/test_wolframalpha_noapi.py b/searx/tests/engines/test_wolframalpha_noapi.py
index d02dccd9..b884ffa3 100644
--- a/searx/tests/engines/test_wolframalpha_noapi.py
+++ b/searx/tests/engines/test_wolframalpha_noapi.py
@@ -22,8 +22,8 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
self.assertRaises(AttributeError, wolframalpha_noapi.response, '')
self.assertRaises(AttributeError, wolframalpha_noapi.response, '[]')
- response = mock.Mock(text='')
- self.assertEqual(wolframalpha_noapi.response(response), [])
+ # response = mock.Mock(text='')
+ # self.assertEqual(wolframalpha_noapi.response(response), [])
html = """
@@ -135,8 +135,10 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
response = mock.Mock(text=html)
results = wolframalpha_noapi.response(response)
self.assertEqual(type(results), list)
- self.assertEqual(len(results), 1)
+ self.assertEqual(len(results), 2)
self.assertIn("i", results[0]['answer'])
+ self.assertIn("sqrt(-1) - Wolfram|Alpha", results[1]['title'])
+ self.assertIn("http://www.wolframalpha.com/input/?i=sqrt%28-1%29", results[1]['url'])
html = """
@@ -228,5 +230,7 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase):
response = mock.Mock(text=html)
results = wolframalpha_noapi.response(response)
self.assertEqual(type(results), list)
- self.assertEqual(len(results), 1)
+ self.assertEqual(len(results), 2)
self.assertIn("log(x)+c", results[0]['answer'])
+ self.assertIn("integral 1/x - Wolfram|Alpha", results[1]['title'])
+ self.assertIn("http://www.wolframalpha.com/input/?i=integral+1%2Fx", results[1]['url'])