Full text search in Django Rest Framework only supported for MYSQL?

Why the Django Rest Framework supports full text search for the MYSQL backend when there are much more capable db like Postgres, I read this and was surprised: /

http://www.django-rest-framework.org/api-guide/filtering

"@ 'Full-text search. (Only the Django MySQL backend is currently supported.)"

Know any specific reason for this?

+5
source share
2 answers

This has changed since @stalk responded. Starting with Django 1.10 , the Django Rest Framework can also support PostgreSQL.

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:

  • Add django.contrib.postgres to your INSTALLED_APPS .
  • In your view, use the @ symbol to mark full-text search fields:

     search_fields = ('@title', '@description') 

In fact, it seems that Django's full-text search support for MySQL is deprecated or at least changing, according to the note about deprecating the Django docs link in the original @stalk answer. This note refers to the following explanation, which also contains sample code to replace it:

Search in search engines that only supports MySQL and is extremely feature-limited is outdated. Replace it with a normal search ...

Sorry, I don't have enough reputation to post additional direct links.

+5
source

This is because the django-rest-framework uses django __search .

From the current last commit in the master 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 talks about __search (logical 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. 
+3
source

Source: https://habr.com/ru/post/1204631/


All Articles