forked from zaclys/searxng
[enh] multilingual duckduckgo_definitions
This commit is contained in:
parent
8d335dbdae
commit
6dca14e95d
|
@ -1,5 +1,6 @@
|
||||||
import json
|
import json
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
|
from re import sub
|
||||||
from lxml import html
|
from lxml import html
|
||||||
from searx.utils import html_to_text
|
from searx.utils import html_to_text
|
||||||
from searx.engines.xpath import extract_text
|
from searx.engines.xpath import extract_text
|
||||||
|
@ -19,8 +20,8 @@ def result_to_text(url, text, htmlResult):
|
||||||
|
|
||||||
|
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
# TODO add kl={locale}
|
|
||||||
params['url'] = url.format(query=urlencode({'q': query}))
|
params['url'] = url.format(query=urlencode({'q': query}))
|
||||||
|
params['headers']['Accept-Language'] = params['language']
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,6 +104,10 @@ def response(resp):
|
||||||
urls.append({'title': search_res.get('DefinitionSource'),
|
urls.append({'title': search_res.get('DefinitionSource'),
|
||||||
'url': definitionURL})
|
'url': definitionURL})
|
||||||
|
|
||||||
|
# to merge with wikidata's infobox
|
||||||
|
if infobox_id:
|
||||||
|
infobox_id = sub(r'^http:', r'https:', infobox_id)
|
||||||
|
|
||||||
# entity
|
# entity
|
||||||
entity = search_res.get('Entity', None)
|
entity = search_res.get('Entity', None)
|
||||||
# TODO continent / country / department / location / waterfall /
|
# TODO continent / country / department / location / waterfall /
|
||||||
|
|
|
@ -123,7 +123,7 @@ class TestDDGDefinitionsEngine(SearxTestCase):
|
||||||
self.assertEqual(results[1]['url'], 'result first url')
|
self.assertEqual(results[1]['url'], 'result first url')
|
||||||
self.assertEqual(results[2]['suggestion'], 'text')
|
self.assertEqual(results[2]['suggestion'], 'text')
|
||||||
self.assertEqual(results[3]['infobox'], 'heading')
|
self.assertEqual(results[3]['infobox'], 'heading')
|
||||||
self.assertEqual(results[3]['id'], 'http://definition.url')
|
self.assertEqual(results[3]['id'], 'https://definition.url')
|
||||||
self.assertEqual(results[3]['entity'], 'Entity')
|
self.assertEqual(results[3]['entity'], 'Entity')
|
||||||
self.assertIn('abstract', results[3]['content'])
|
self.assertIn('abstract', results[3]['content'])
|
||||||
self.assertIn('this is the definition', results[3]['content'])
|
self.assertIn('this is the definition', results[3]['content'])
|
||||||
|
@ -240,7 +240,7 @@ class TestDDGDefinitionsEngine(SearxTestCase):
|
||||||
self.assertEqual(type(results), list)
|
self.assertEqual(type(results), list)
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
self.assertEqual(results[0]['infobox'], 'heading')
|
self.assertEqual(results[0]['infobox'], 'heading')
|
||||||
self.assertEqual(results[0]['id'], 'http://definition.url')
|
self.assertEqual(results[0]['id'], 'https://definition.url')
|
||||||
self.assertEqual(results[0]['entity'], 'Entity')
|
self.assertEqual(results[0]['entity'], 'Entity')
|
||||||
self.assertIn('abstract', results[0]['content'])
|
self.assertIn('abstract', results[0]['content'])
|
||||||
self.assertIn('this is the definition', results[0]['content'])
|
self.assertIn('this is the definition', results[0]['content'])
|
||||||
|
|
Loading…
Reference in New Issue