mirror of https://github.com/searxng/searxng.git
parent
e391b2d970
commit
9c2b7a82f0
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
ArXiV (Scientific preprints)
|
ArXiV (Scientific preprints)
|
||||||
@website https://axiv.org
|
@website https://arxiv.org
|
||||||
@provide-api yes (export.arxiv.org/api/query)
|
@provide-api yes (export.arxiv.org/api/query)
|
||||||
@using-api yes
|
@using-api yes
|
||||||
@results XML-RSS
|
@results XML-RSS
|
||||||
|
@ -41,7 +41,8 @@ def request(query, params):
|
||||||
def response(resp):
|
def response(resp):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
search_results = html.fromstring(resp.text).xpath('//entry')
|
dom = html.fromstring(resp.content)
|
||||||
|
search_results = dom.xpath('//entry')
|
||||||
|
|
||||||
for entry in search_results:
|
for entry in search_results:
|
||||||
title = entry.xpath('.//title')[0].text
|
title = entry.xpath('.//title')[0].text
|
||||||
|
@ -49,15 +50,15 @@ def response(resp):
|
||||||
url = entry.xpath('.//id')[0].text
|
url = entry.xpath('.//id')[0].text
|
||||||
|
|
||||||
content_string = '{doi_content}{abstract_content}'
|
content_string = '{doi_content}{abstract_content}'
|
||||||
|
|
||||||
abstract = entry.xpath('.//summary')[0].text
|
abstract = entry.xpath('.//summary')[0].text
|
||||||
|
|
||||||
# If a doi is available, add it to the snipppet
|
# If a doi is available, add it to the snipppet
|
||||||
try:
|
try:
|
||||||
doi_content = entry.xpath('.//link[@title="doi"]')[0].text
|
doi_content = entry.xpath('.//link[@title="doi"]')[0].text
|
||||||
content = content_string.format(doi_content=doi_content, abstract_content=abstract_content)
|
content = content_string.format(doi_content=doi_content, abstract_content=abstract)
|
||||||
except:
|
except:
|
||||||
content = content_string.format(abstract_content=abstract_content)
|
content = content_string.format(doi_content="", abstract_content=abstract)
|
||||||
|
|
||||||
if len(content) > 300:
|
if len(content) > 300:
|
||||||
content = content[0:300] + "..."
|
content = content[0:300] + "..."
|
||||||
|
|
|
@ -21,11 +21,11 @@ class TestBaseEngine(SearxTestCase):
|
||||||
self.assertRaises(AttributeError, arxiv.response, '')
|
self.assertRaises(AttributeError, arxiv.response, '')
|
||||||
self.assertRaises(AttributeError, arxiv.response, '[]')
|
self.assertRaises(AttributeError, arxiv.response, '[]')
|
||||||
|
|
||||||
response = mock.Mock(text='''<?xml version="1.0" encoding="UTF-8"?>
|
response = mock.Mock(content=b'''<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom"></feed>''')
|
<feed xmlns="http://www.w3.org/2005/Atom"></feed>''')
|
||||||
self.assertEqual(arxiv.response(response), [])
|
self.assertEqual(arxiv.response(response), [])
|
||||||
|
|
||||||
xml_mock = '''<?xml version="1.0" encoding="UTF-8"?>
|
xml_mock = b'''<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
<title type="html">ArXiv Query: search_query=all:test_query&id_list=&start=0&max_results=1</title>
|
<title type="html">ArXiv Query: search_query=all:test_query&id_list=&start=0&max_results=1</title>
|
||||||
<id>http://arxiv.org/api/1</id>
|
<id>http://arxiv.org/api/1</id>
|
||||||
|
@ -50,7 +50,7 @@ class TestBaseEngine(SearxTestCase):
|
||||||
</feed>
|
</feed>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
response = mock.Mock(text=xml_mock.encode('utf-8'))
|
response = mock.Mock(content=xml_mock)
|
||||||
results = arxiv.response(response)
|
results = arxiv.response(response)
|
||||||
self.assertEqual(type(results), list)
|
self.assertEqual(type(results), list)
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
|
|
Loading…
Reference in New Issue