Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to retrieve spelling suggestions in the serializer? #84

Open
pymarco opened this issue Nov 22, 2016 · 8 comments
Open

How to retrieve spelling suggestions in the serializer? #84

pymarco opened this issue Nov 22, 2016 · 8 comments
Assignees

Comments

@pymarco
Copy link

pymarco commented Nov 22, 2016

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

@rhblind
Copy link
Owner

rhblind commented Nov 22, 2016

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.

@rhblind rhblind self-assigned this Nov 22, 2016
@pymarco
Copy link
Author

pymarco commented Jan 6, 2017

Any chance there is an update on this?

@rhblind
Copy link
Owner

rhblind commented Jan 8, 2017

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..

@ChadTaljaardt
Copy link

Any news on this?

@jpatel3
Copy link

jpatel3 commented Jul 5, 2017

@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.

@pymarco
Copy link
Author

pymarco commented Aug 11, 2017

@jpatel3 have you made any progress on this implementation?

@jpatel3
Copy link

jpatel3 commented Aug 14, 2017

@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!

@rhblind
Copy link
Owner

rhblind commented Aug 14, 2017

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants