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

Smart Filtering on the Server Side #110

Open
maysu1914 opened this issue Jul 9, 2021 · 2 comments
Open

Smart Filtering on the Server Side #110

maysu1914 opened this issue Jul 9, 2021 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested

Comments

@maysu1914
Copy link
Contributor

Do we have any support for smart filtering on the server-side?

https://datatables.net/forums/discussion/24637/smart-search-whith-serverside-ssp#Comment_68324
https://datatables.net/forums/discussion/8045/smart-filtering-does-not-work-on-server-side-processing

Thank you for this package, it is very useful.

@maysu1914 maysu1914 changed the title Smart Filtering on Server Side Smart Filtering on the Server Side Jul 9, 2021
@izimobil
Copy link
Owner

izimobil commented Jul 9, 2021

I guess smart filtering is splitting the search string into words and do the search for each word ?
No this is not supported at the moment, If you want to help with a pull request, you're welcome.

@izimobil izimobil added enhancement New feature or request question Further information is requested help wanted Extra attention is needed labels Jul 9, 2021
@mmmcorpsvit
Copy link

mmmcorpsvit commented Sep 12, 2021

my ugly solution:
use https://github.com/vsemionov/django-rest-fuzzysearch
little magic:

# region 'SmartSearch'
class DatatablesFilterBackend2(DatatablesFilterBackend):
    def get_q(self, datatables_query):
        q = Q()
        return q

    def filter_queryset(self, request, queryset, view):
        queryset = super().filter_queryset(request, queryset, view).distinct()
        return queryset


class SmartFuzzySearchMixin:
    filter_backends = (RankedFuzzySearchFilter, DatatablesFilterBackend2)
    min_rank = 0.1

    # search_fields = ('id', )  # use search by id

    def __init__(self):
        if hasattr(self, 'search_fields'):
            self.search_fields = ('id', ) + self.search_fields # noqa
        pass
# endregion

.
.
.
class RequestResultViewSet(SmartFuzzySearchMixin, viewsets.ReadOnlyModelViewSet):
    search_fields = ('id', 'context') # define fields for smart search
# the you usual code, not rewrite filter_backends !

for speedup use GinIndex for search fields in models
and i have fully working django-rest-framework-datatables but with FuzzySearch filter
i know, ugly, but work fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants