<commit_before>from django.views.generic import View
from django.views.generic.base import TemplateView

from braces.views import AjaxResponseMixin, JSONResponseMixin
from haystack.query import SearchQuerySet


class SiteView(TemplateView):
    template_name = 'landings/home_site.html'


class AutocompleteView(JSONResponseMixin, View):
    def get(self, request, *args, **kwargs):
        sqs = SearchQuerySet().autocomplete(text=request.GET.get('q', ''))[:5]
        suggestions = [result.pk for result in sqs]
        json = {'results': suggestions}
        return self.render_json_response(json)<commit_msg>Throw more data into the autocomplete view.<commit_after>from django.views.generic import View
from django.views.generic.base import TemplateView

from braces.views import AjaxResponseMixin, JSONResponseMixin
from haystack.query import SearchQuerySet
from haystack.inputs import AutoQuery, Exact, Clean


class SiteView(TemplateView):
    template_name = 'landings/home_site.html'


class AutocompleteView(JSONResponseMixin, AjaxResponseMixin, View):
    def get_ajax(self, request, *args, **kwargs):
        query = request.GET.get('q', '')
        sqs = SearchQuerySet().autocomplete(text=query).load_all()[:5]
        suggestions = []
        for result in sqs:
            suggestions.append({
                'text': result.text,
                'pk': result.pk,
                'model': result.model_name,
                'name': result.object.name if result.object.name != result.object.romanized_name else None,
                'romanized_name': result.object.romanized_name,
                'url': result.object.get_absolute_url(),
            })
        # suggestions = [result.pk for result in sqs]
        json = {'query': query, 'results': suggestions}
        return self.render_json_response(json)
{'fraction_non_alphanumeric': 0.10526315789473684, 'fraction_numerical': 0.0010964912280701754, 'mean_word_length': 3.3660287081339715, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6239916', 'n_tokens_mistral': 520, 'n_tokens_neox': 503, 'n_words': 124}