From 58554ad41d789d21c7477c01fd8c27ff1f590445 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 10 Nov 2020 15:17:42 +0100 Subject: [PATCH] Restore opensearch hints. --- src/catalogue/urls.py | 2 ++ src/search/views.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/catalogue/urls.py b/src/catalogue/urls.py index 230e1c925..7f1eddbae 100644 --- a/src/catalogue/urls.py +++ b/src/catalogue/urls.py @@ -8,6 +8,7 @@ from catalogue.feeds import AudiobookFeed from catalogue.models import Book from catalogue import views import picture.views +import search.views urlpatterns = [ @@ -36,6 +37,7 @@ urlpatterns = [ path('lektury//', views.collection, name='collection'), path('audiobooki/', views.audiobooks, name='audiobook_list'), path('daisy/', views.daisy_list, name='daisy_list'), + path('jtags/', search.views.hint, {'param': 'q', 'mozhint': True}, name='jhint'), path('nowe/', ListView.as_view( queryset=Book.objects.filter(parent=None, findable=True).order_by('-created_at'), template_name='catalogue/recent_list.html'), name='recent_list'), diff --git a/src/search/views.py b/src/search/views.py index 970734ad7..da3a767f8 100644 --- a/src/search/views.py +++ b/src/search/views.py @@ -59,8 +59,8 @@ def did_you_mean(query, tokens): @cache.never_cache -def hint(request): - prefix = request.GET.get('term', '') +def hint(request, mozhint=False, param='term'): + prefix = request.GET.get(param, '') if len(prefix) < 2: return JsonResponse([], safe=False) @@ -94,6 +94,16 @@ def hint(request): } for b in Book.objects.filter(findable=True, title__iregex='\m' + prefix)[:limit-len(data)] ] + + if mozhint: + data = [ + prefix, + [ + item['label'] + for item in data + ] + ] + callback = request.GET.get('callback', None) if callback: return HttpResponse("%s(%s);" % (callback, json.dumps(data)), -- 2.20.1