mirror of
https://github.com/searxng/searxng.git
synced 2024-11-22 12:10:11 +01:00
[mod] decouple qwant's categories from SearXNG's categories
By using new property `qwant_categ:` the category of qwant is no longer bound to the category of SearXNG. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
e81c458165
commit
75bb8c45d0
@ -9,16 +9,16 @@ https://www.qwant.com/ queries.
|
|||||||
This implementation is used by different qwant engines in the settings.yml::
|
This implementation is used by different qwant engines in the settings.yml::
|
||||||
|
|
||||||
- name: qwant
|
- name: qwant
|
||||||
categories: general
|
qwant_categ: web
|
||||||
...
|
...
|
||||||
- name: qwant news
|
- name: qwant news
|
||||||
categories: news
|
qwant_categ: news
|
||||||
...
|
...
|
||||||
- name: qwant images
|
- name: qwant images
|
||||||
categories: images
|
qwant_categ: images
|
||||||
...
|
...
|
||||||
- name: qwant videos
|
- name: qwant videos
|
||||||
categories: videos
|
qwant_categ: videos
|
||||||
...
|
...
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -50,13 +50,7 @@ about = {
|
|||||||
categories = []
|
categories = []
|
||||||
paging = True
|
paging = True
|
||||||
supported_languages_url = about['website']
|
supported_languages_url = about['website']
|
||||||
|
qwant_categ = None # web|news|inages|videos
|
||||||
category_to_keyword = {
|
|
||||||
'general': 'web',
|
|
||||||
'news': 'news',
|
|
||||||
'images': 'images',
|
|
||||||
'videos': 'videos',
|
|
||||||
}
|
|
||||||
|
|
||||||
# search-url
|
# search-url
|
||||||
url = 'https://api.qwant.com/v3/search/{keyword}?{query}&count={count}&offset={offset}'
|
url = 'https://api.qwant.com/v3/search/{keyword}?{query}&count={count}&offset={offset}'
|
||||||
@ -64,10 +58,9 @@ url = 'https://api.qwant.com/v3/search/{keyword}?{query}&count={count}&offset={o
|
|||||||
|
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
"""Qwant search request"""
|
"""Qwant search request"""
|
||||||
keyword = category_to_keyword[categories[0]]
|
|
||||||
count = 10 # web: count must be equal to 10
|
count = 10 # web: count must be equal to 10
|
||||||
|
|
||||||
if keyword == 'images':
|
if qwant_categ == 'images':
|
||||||
count = 50
|
count = 50
|
||||||
offset = (params['pageno'] - 1) * count
|
offset = (params['pageno'] - 1) * count
|
||||||
# count + offset must be lower than 250
|
# count + offset must be lower than 250
|
||||||
@ -78,7 +71,7 @@ def request(query, params):
|
|||||||
offset = min(offset, 40)
|
offset = min(offset, 40)
|
||||||
|
|
||||||
params['url'] = url.format(
|
params['url'] = url.format(
|
||||||
keyword=keyword,
|
keyword=qwant_categ,
|
||||||
query=urlencode({'q': query}),
|
query=urlencode({'q': query}),
|
||||||
offset=offset,
|
offset=offset,
|
||||||
count=count,
|
count=count,
|
||||||
@ -103,7 +96,6 @@ def response(resp):
|
|||||||
"""Get response from Qwant's search request"""
|
"""Get response from Qwant's search request"""
|
||||||
# pylint: disable=too-many-locals, too-many-branches, too-many-statements
|
# pylint: disable=too-many-locals, too-many-branches, too-many-statements
|
||||||
|
|
||||||
keyword = category_to_keyword[categories[0]]
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
# load JSON result
|
# load JSON result
|
||||||
@ -125,7 +117,7 @@ def response(resp):
|
|||||||
# raise for other errors
|
# raise for other errors
|
||||||
raise_for_httperror(resp)
|
raise_for_httperror(resp)
|
||||||
|
|
||||||
if keyword == 'web':
|
if qwant_categ == 'web':
|
||||||
# The WEB query contains a list named 'mainline'. This list can contain
|
# The WEB query contains a list named 'mainline'. This list can contain
|
||||||
# different result types (e.g. mainline[0]['type'] returns type of the
|
# different result types (e.g. mainline[0]['type'] returns type of the
|
||||||
# result items in mainline[0]['items']
|
# result items in mainline[0]['items']
|
||||||
@ -136,7 +128,7 @@ def response(resp):
|
|||||||
# result['items'].
|
# result['items'].
|
||||||
mainline = data.get('result', {}).get('items', [])
|
mainline = data.get('result', {}).get('items', [])
|
||||||
mainline = [
|
mainline = [
|
||||||
{'type': keyword, 'items': mainline},
|
{'type': qwant_categ, 'items': mainline},
|
||||||
]
|
]
|
||||||
|
|
||||||
# return empty array if there are no results
|
# return empty array if there are no results
|
||||||
@ -146,7 +138,7 @@ def response(resp):
|
|||||||
for row in mainline:
|
for row in mainline:
|
||||||
|
|
||||||
mainline_type = row.get('type', 'web')
|
mainline_type = row.get('type', 'web')
|
||||||
if mainline_type != keyword:
|
if mainline_type != qwant_categ:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if mainline_type == 'ads':
|
if mainline_type == 'ads':
|
||||||
|
@ -1198,6 +1198,7 @@ engines:
|
|||||||
results: HTML
|
results: HTML
|
||||||
|
|
||||||
- name: qwant
|
- name: qwant
|
||||||
|
qwant_categ: web
|
||||||
engine: qwant
|
engine: qwant
|
||||||
shortcut: qw
|
shortcut: qw
|
||||||
categories: [general, web]
|
categories: [general, web]
|
||||||
@ -1206,6 +1207,7 @@ engines:
|
|||||||
rosebud: *test_rosebud
|
rosebud: *test_rosebud
|
||||||
|
|
||||||
- name: qwant news
|
- name: qwant news
|
||||||
|
qwant_categ: news
|
||||||
engine: qwant
|
engine: qwant
|
||||||
shortcut: qwn
|
shortcut: qwn
|
||||||
categories: news
|
categories: news
|
||||||
@ -1213,6 +1215,7 @@ engines:
|
|||||||
network: qwant
|
network: qwant
|
||||||
|
|
||||||
- name: qwant images
|
- name: qwant images
|
||||||
|
qwant_categ: images
|
||||||
engine: qwant
|
engine: qwant
|
||||||
shortcut: qwi
|
shortcut: qwi
|
||||||
categories: [images, web]
|
categories: [images, web]
|
||||||
@ -1220,6 +1223,7 @@ engines:
|
|||||||
network: qwant
|
network: qwant
|
||||||
|
|
||||||
- name: qwant videos
|
- name: qwant videos
|
||||||
|
qwant_categ: videos
|
||||||
engine: qwant
|
engine: qwant
|
||||||
shortcut: qwv
|
shortcut: qwv
|
||||||
categories: [videos, web]
|
categories: [videos, web]
|
||||||
|
Loading…
Reference in New Issue
Block a user