I need to implement full text search for my Django application, running MySQL as backend.
Let\'s say I\'ve got a model as follows:
class MyItem(model
From django docs regarding full-text search:
Example:
Entry.objects.filter(headline__search="+Django -jazz Python")SQL equivalent:
SELECT ... WHERE MATCH(tablename, headline) AGAINST (+Django -jazz Python IN BOOLEAN MODE);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.
Now to the direct manipulation of the database. In MySQL you can create full-text index by following these steps (source article):
mysql -u root -p. On prompt enter the root password.use your_db_name to switch to your django database.CREATE FULLTEXT INDEX index_name ON table_name (column_names).That's it! FTS indexing in enabled in your django database. Now you can use the django's rich QuerySet API to do full-text searches.
Edit: The above quote no longer exists in the django version >1.9.