Why does Django Rest Framework only support a full text search for MYSQL backend when there is much more capable db like Postgres, I read this and was surprised :/
http://www.django-rest-framework.org/api-guide/filtering
"@' Full-text search. (Currently only supported Django's MySQL backend.)"
Know any concrete reason behind this ?
This has changed since @stalk answered. As of Django 1.10, the Django Rest Framework can support PostgreSQL as well.
And since django.contrib.postgres
provides the same __search
interface as MySQL does, you can connect your API to Postgres using the same setup as for MySQL:
django.contrib.postgres
to your INSTALLED_APPS
.In your view, use the @
symbol to mark the full-text search fields:
search_fields = ('@title', '@description')
In fact, it sounds like Django's full-text search support for MySQL is either deprecated or is at least changing, according to the deprecation note on the Django docs link in @stalk's original answer. That note links to the following explanation, which also contains example code for replacing it:
The search lookup, which supports MySQL only and is extremely limited in features, is deprecated. Replace it with a custom lookup...
I apologize, I don't have enough reputation to post additional direct links.
That is because django-rest-framework use django's __search
.
From current latest commit in master of django-rest-framework:
def construct_search(self, field_name):
if field_name.startswith('^'):
return "%s__istartswith" % field_name[1:]
elif field_name.startswith('='):
return "%s__iexact" % field_name[1:]
elif field_name.startswith('@'):
return "%s__search" % field_name[1:]
else:
return "%s__icontains" % field_name
And django docs tells about __search
(boolean full-text search):
Note this is only available in MySQL and requires direct manipulation of the database
to add the full-text index. By default Django uses BOOLEAN MODE for full text searches.
See the MySQL documentation for additional details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With