def items(self, query): params = search_string_to_params(query) main_search = MainappSearch(params) main_search = main_search[:settings.SEARCH_PAGINATION_LENGTH] executed = main_search.execute() results = [parse_hit(hit, highlighting=False) for hit in executed.hits] return results
def search_index(request, query): params = search_string_to_params(query) options, search, errors = params_to_query(params) for error in errors: messages.error(request, error) try: handle_subscribe_requests( request, params, _('You will now receive notifications about new search results.'), _('You will no longer receive notifications.'), _('You have already subscribed to this search.')) except NeedsLoginError as err: return redirect(err.redirect_url) context = _search_to_context(query, params, options, search) context['subscribable'] = params_are_subscribable(params) context['is_subscribed'] = is_subscribed_to_search(request.user, params) return render(request, "mainapp/search.html", context)
def search_results_only(request, query): """ Returns only the result list items. Used for the endless scrolling """ params = search_string_to_params(query) options, search, _ = params_to_query(params) after = int(request.GET.get('after', 0)) search = search[after:after + 20] context = _search_to_context(query, params, options, search) context['subscribable'] = params_are_subscribable(params) context['is_subscribed'] = is_subscribed_to_search(request.user, params) result = { 'results': loader.render_to_string('partials/mixed_results.html', context, request), 'total_results': context['total_hits'], 'subscribe_widget': loader.render_to_string('partials/subscribe_widget.html', context, request), } return JsonResponse(result, safe=False)
def search_results_only(request, query): """ Returns only the result list items. Used for the endless scrolling """ params = search_string_to_params(query) main_search = MainappSearch(params) after = int(request.GET.get('after', 0)) main_search = main_search[after:settings.SEARCH_PAGINATION_LENGTH + after] executed = main_search.execute() results = [parse_hit(hit) for hit in executed.hits] context = _search_to_context(query, main_search, executed, results, request) result = { 'results': loader.render_to_string('partials/mixed_results.html', context, request), 'total_results': executed.hits.total, 'subscribe_widget': loader.render_to_string('partials/subscribe_widget.html', context, request), 'more_link': reverse(search_results_only, args=[query]), # TOOD: Currently we need both because the js for the dropdown facet # and document type facet hasn't been unified 'facets': executed.facets.to_dict(), 'new_facets': aggs_to_context(executed) } return JsonResponse(result, safe=False)
def search(request, query): params = search_string_to_params(query) main_search = MainappSearch(params) for error in main_search.errors: messages.error(request, error) try: handle_subscribe_requests(request, params, _('You will now receive notifications about new search results.'), _('You will no longer receive notifications.'), _('You have already subscribed to this search.')) except NeedsLoginError as err: return redirect(err.redirect_url) main_search = main_search[:settings.SEARCH_PAGINATION_LENGTH] executed = main_search.execute() results = [parse_hit(hit) for hit in executed.hits] context = _search_to_context(query, main_search, executed, results, request) context["new_facets"] = aggs_to_context(executed) context["query"] = query return render(request, "mainapp/search/search.html", context)
def get_search_params(self): return search_string_to_params(self.search_string)
def test_search_string_to_params(self): instring = search_string_to_params( "document-type:file,committee word radius radius:50 anotherword") self.assertEqual(instring, self.params)
def title(self, query): params = search_string_to_params(query) return params_to_human_string(params)