-
Notifications
You must be signed in to change notification settings - Fork 771
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
Support for PostgreSQL to_tsvector function with multiple fields #885
base: main
Are you sure you want to change the base?
Conversation
Q encapsulation from SearchVectorFilter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HI @Charnelx.
Thanks for the effort here. I am basically all for this! (It's been on my list for a while...)
Ultimately I'd like to offer a few options for a search filter:
- A Poor man's search™ using
LIKE
, similar to the existing search filter in DRF. - A wrapper around Django Watson (for which I have much love)
- And then per-DB options such as this, but including SQLite etc.
I say this now because I guess it should all probably go in a separate search
module. (I kind of feel filters.py
is long enough already. 🙂)
Good work thus far!
Hi, @carltongibson . If you don't mind, I'll share my vision regarding your options:
Maybe compromise solution will be to implement |
Just on Watson:
I'd expect users to have done all that themselves. The |
Than it could be as simple as this code snippet? class TextSearchFilter(CharFilter):
def __init__(self, field_name=None, lookup_expr='exact', *, **kwargs):
try:
from watson import search as watson
except ImportError:
raise ImportError('django-watson package should be installed in order to use this filter')
super().__init__(field_name, lookup_expr, **kwargs)
def filter(self, qs, value):
# here we are using filter method because our filtering class
# should make search by fields of not all registered models
# but a concret one
qs = watson.filter(qs, value)
return qs |
Yeah, something like that. Our job here is just to wrap up the boilerplate of pulling the search value from the query string, doing basic validation, and then finally handing it off to Watson. We're not in the market for more, so, yes, about that simple. (Plus docs and tests of course.) |
I've got the idea. I'll try to participate. |
Hey guys! I just googled here and wonder what would be a minimal example to leverage Django/Postgres native FTS engine with django-filter. Thanks in advance! |
Any docs regarding this feature? |
This is a second try (previous #884) to add SearchVectorFilter to support to_tsvector function for full text search.
Case of use:
models.py
views.py
##test.py**