Skip to content

Issue with Highlight - KeyError: 0  #126

@code-wizard

Description

@code-wizard

I get the error below when I add HaystackHighlightFilter to a faceted viewset and use face url like

http://127.0.0.1:8002/api/v1/search/facets/?first_name=judith&params=u_type_exact%3AStudent
When I check the to_representation(self, instance) and print(instance.highlighted) here is the structure of the instance.highlighted

{'text': ['<em>Judith</em>\nAmaefula\nSaint Hopkins\nMechanical Engineering\nMedicine']}
Is there an update that addresses this issues?

File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner response = get_response(request) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, **kwargs) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/viewsets.py", line 95, in view return self.dispatch(request, *args, **kwargs) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/views.py", line 494, in dispatch response = self.handle_exception(exc) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/views.py", line 454, in handle_exception self.raise_uncaught_exception(exc) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/views.py", line 491, in dispatch response = handler(request, *args, **kwargs) File "/Users/ebuka/dev/university/core/api.py", line 46, in facets return Response(serializer.data) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/serializers.py", line 537, in data ret = super(Serializer, self).data File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/serializers.py", line 262, in data self._data = self.to_representation(self.instance) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/serializers.py", line 504, in to_representation ret[field.field_name] = field.to_representation(attribute) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/fields.py", line 1816, in to_representation return method(value) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/drf_haystack/serializers.py", line 411, in get_objects return serializer.data File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/serializers.py", line 742, in data ret = super(ListSerializer, self).data File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/serializers.py", line 262, in data self._data = self.to_representation(self.instance) File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/serializers.py", line 660, in to_representation self.child.to_representation(item) for item in iterable File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/rest_framework/serializers.py", line 660, in <listcomp> self.child.to_representation(item) for item in iterable File "/Users/ebuka/.virtualenvs/university/lib/python3.6/site-packages/drf_haystack/serializers.py", line 242, in to_representation ret["highlighted"] = instance.highlighted[0] KeyError: 0

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions