search: allow passing request user to search engines (#26254)

This commit is contained in:
Frédéric Péters 2018-09-09 09:07:25 +02:00
parent 596dfe7678
commit 88382da422
1 changed files with 6 additions and 1 deletions

View File

@ -129,7 +129,8 @@ class SearchCell(CellBase):
if not query:
return render_response(service)
url = get_templated_url(service['url'], context={'q': query, 'search_service': service})
url = get_templated_url(service['url'],
context={'request': request, 'q': query, 'search_service': service})
url = url % {'q': quote(query.encode('utf-8'))} # if url contains %(q)s
if url.startswith('/'):
url = request.build_absolute_uri(url)
@ -140,6 +141,10 @@ class SearchCell(CellBase):
kwargs = {}
kwargs['cache_duration'] = service.get('cache_duration', 0)
kwargs['remote_service'] = 'auto' if service.get('signature') else None
# don't automatically add user info to query string, if required it can
# be set explicitely in the URL template in the engine definition (via
# {{user_nameid}} or {{user_email}}).
kwargs['without_user'] = True
results = requests.get(url, **kwargs).json()
hit_templates = {}
if service.get('hit_url_template'):