def refresh_search_keys(request): if (request.user.is_authenticated() and request.user.is_staff): client = Client('productIndex') total_old_docts = client.info()['num_docs'] delete_status = client.drop_index() new_index = False if delete_status == 'OK': new_index = create_product_search_index() auto_completer = AutoCompleter('productAutocompleter') auto_completer_old_count = auto_completer.len() create_product_autocompleter() auto_completer_new_count = auto_completer.len() return JsonResponse({'success': True}) else: return JsonResponse({'success': False})
def product_autocomplete(request): autocomplete_key = request.POST.get('autocomplete_key', "").strip() if len(autocomplete_key) == 0: return JsonResponse({'autocomplete_values': []}) auto_completer = AutoCompleter('productAutocompleter') autocomplete_values = [] if auto_completer.len() == 0: create_product_autocompleter() res = auto_completer.get_suggestions(autocomplete_key, fuzzy=True) for acv in res: autocomplete_values.append(str(acv)) context = {'autocomplete_values': autocomplete_values} return JsonResponse(context)