django-elasticsearch-dsl-drf icon indicating copy to clipboard operation
django-elasticsearch-dsl-drf copied to clipboard

Overriding FilteringFilterBackend.filter_queryset

Open selimt opened this issue 2 years ago • 0 comments

Questions

Is there a way to override filter_queryset in FilteringFilterBackend without having to copy all the code to the inheriting class?

I want to add support for the match_phrase operator but because the conditional defaults to the term filter like in here:

                # `term` filter lookup. This is default if no `default_lookup`
                # option has been given or explicit lookup provided.
                else:
                    queryset = self.apply_filter_term(queryset,
                                                      options,
                                                      value)

I end up with a query like this which doesn't work:

query":{"bool":{"filter":[{"term":{"name":"running"}}],"must":[{"match_phrase":{"name.trigram":"running"}}]}}

My apply method is as follows:

        return self.apply_query(
            queryset=queryset,
            options=options,
            args=[Q("match_phrase", **{"{}.trigram".format(options['field']): value})]
        )

Thanks. -Selim

selimt avatar Oct 02 '23 17:10 selimt