diff options
| author | Adam Tauber <asciimoo@gmail.com> | 2015-02-12 10:52:55 +0100 |
|---|---|---|
| committer | Adam Tauber <asciimoo@gmail.com> | 2015-02-12 10:52:55 +0100 |
| commit | f6db77d81ea87d99462b4c3cc40a8a27e0264724 (patch) | |
| tree | b26fb71a62082aeec81c7bb1bb3d7447d006aed3 /searx/engines/yacy.py | |
| parent | 516105c570a920dadeb87b34ee5ee434ad5cb16f (diff) | |
| parent | f96154b7c454a3b02bf688f248b4471c2020c28f (diff) | |
Merge pull request #210 from Cqoicebordel/unit-tests
unit tests
Diffstat (limited to 'searx/engines/yacy.py')
| -rw-r--r-- | searx/engines/yacy.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/searx/engines/yacy.py b/searx/engines/yacy.py index 17e2a7aab..3d26c9cc4 100644 --- a/searx/engines/yacy.py +++ b/searx/engines/yacy.py @@ -25,10 +25,10 @@ number_of_results = 5 # search-url base_url = 'http://localhost:8090' search_url = '/yacysearch.json?{query}'\ - '&startRecord={offset}'\ - '&maximumRecords={limit}'\ - '&contentdom={search_type}'\ - '&resource=global' # noqa + '&startRecord={offset}'\ + '&maximumRecords={limit}'\ + '&contentdom={search_type}'\ + '&resource=global' # yacy specific type-definitions search_types = {'general': 'text', @@ -41,7 +41,7 @@ search_types = {'general': 'text', # do search-request def request(query, params): offset = (params['pageno'] - 1) * number_of_results - search_type = search_types.get(params['category'], '0') + search_type = search_types.get(params.get('category'), '0') params['url'] = base_url +\ search_url.format(query=urlencode({'query': query}), @@ -66,9 +66,12 @@ def response(resp): if not raw_search_results: return [] - search_results = raw_search_results.get('channels', {})[0].get('items', []) + search_results = raw_search_results.get('channels', []) - for result in search_results: + if len(search_results) == 0: + return [] + + for result in search_results[0].get('items', []): # parse image results if result.get('image'): # append result @@ -88,7 +91,7 @@ def response(resp): 'content': result['description'], 'publishedDate': publishedDate}) - #TODO parse video, audio and file results + # TODO parse video, audio and file results # return results return results |