简体   繁体   中英

how to impliment Haystacksearch fetched autocomplete

I want implement fetching in autocomplete, here is my autocomplete function

def autocomplete(request):
fetch_field = request.GET.get('fetch_field')
sqs = SearchQuerySet().autocomplete(
    content_auto=request.GET.get(
        'query',
        ''))[
    :5]
s = []
for result in sqs:
    d = {"value": result.title, "data": result.object.slug}
    s.append(d)
output = {'suggestions': s}
print('hihi' ,output)
return JsonResponse(output)

Now I can get fetch fields but I don't know how to fetch with SearchQuerySet.

sqs = SearchQuerySet().filter(field_want_to_fetch = fetch_field ).autocomplete(
content_auto=request.GET.get(
    'query',
    ''))[
:5]

Use this !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM