How to retrieve spelling suggestions in the serializer?
I would like to return spelling suggestions in my serializer. How would I do that? Thanks
Haystack method: http://django-haystack.readthedocs.io/en/latest/searchqueryset_api.html?#SearchQuerySet.spelling_suggestion
Hi. Support for spelling suggestion is not currently implemented. It's probably quite easy to add support for, so I'll see what I can do.
Any chance there is an update on this?
Hi, I have started looking into it, but I got busy with other work so it is currently a bit on hold. I'll see if I have som time soon-ish..
Any news on this?
@rhblind any pointer? I am also looking for same, if you are busy I can add it. please share if you have already done an analysis of it.
@jpatel3 have you made any progress on this implementation?
@pymarco I was using ListAPIView, so I did override on list method to add a suggestion in it if any.
def list(self, request, *args, **kwargs):
response = super(SearchList, self).list(request, args, kwargs)
q = request.query_params.get('q', None)
suggestion_query = SearchQuerySet().auto_query(q.strip())
if suggestion_query.count() == 0:
suggestion = suggestion_query.spelling_suggestion()
if suggestion:
suggestion = re.sub(r"[\(.*?\)]", "", suggestion)
response.data['suggestion'] = suggestion
response.data['searchQuery'] = q.strip()
return response
Where suggestion is spelling suggestion, and searchQuery is actual query. The reason why I extracted the value using regular expression is that the spelling suggestion string was coming in bracket e.g. "(government)".
Hope it helps!
Hello guys. Sorry for not replying, been insanely busy lately.
I did start working on this, but didn't get very far. I started by adding this as a filter feature, but I think that's going down the wrong path. I quickly ran into issues where spelling suggestions duplicated themselves (probably because of stacked filters or something), and didn't have any more time investigating.
If anybody find a clean and generic way of implementing this, I'm always open of merging pull requests!