1. Nam Nguyen
  2. mysql_search

Overview

HTTPS SSH

How to use

Follow these simple steps:

  1. Declare your TextField and CharField as FulltextTextField and FulltextCharField respectively:

    from django.db import models
    from mysql_search.models import (FulltextTextField, FulltextCharField,
        SearchManager)
    
    class Message(models.Model):
        title = FulltextCharField(max_length=160, default='')
        content = FulltextTextField(default='')
    
  2. You can either use an included object manager SearchManager or use Django search field lookup. To use the object manager, add it to your model:

    #
        objects = SearchManager(['title'])
    

    search field lookup: https://docs.djangoproject.com/en/1.0/ref/models/querysets/#search

  3. Then query with either:

    Message.objects.filter(title__search='mysql') # BOOLEAN MODE
    

    Or when your object manager is SearchManager:

    Message.objects.search('mysql') # NATURAL LANGUAGE
    
  4. Set SOUTH_DATABASE_ADAPTERS for your database to mysql_search.south. This is done in your settings.py file:

    SOUTH_DATABASE_ADAPTERS = {
        'default': 'mysql_search.south'
    }
    
  5. Convert your application to use South. Please read South's documentation for how to do this step.

    South's documentation: http://south.readthedocs.org

Caveats

This only works with MySQL.

This only works with MyISAM tables. When migration is run, the tables will be silently converted to MyISAM. If you need InnoDB, create a different model just to hold fulltext indexes.

License

Copyright 2013 Nam T. Nguyen

Distributed under the terms of the BSD license.