[Django]-To Use Django-Haystack or not?

4đź‘Ť

âś…

Don’t use haystack — that’s for fast full-text search when the underlying relational database can’t handle it easily. The use case for haystack is when you store many large documents with huge chunks of text that you want indexed by words in the document so you can easily search.

Django by default already allows you to easily index/search text records. For example, using the admin backend simply specify search fields and you can easily search for name or telephone number. (And it will generally do case insensitive contains searches — this will find partial matches; e.g., the name “John Doe” will come up if you search for just “doe” or “ohn”).

So if your models.py has:

class Donor(models.Model):
    name = models.CharField(max_length=50)
    phone = models.CharField(max_length=15)

and an admin.py with:

from django.contrib import admin
from mysite.myapp.models import Donor

class DonorAdmin(admin.ModelAdmin):
    model = Donor
    search_fields = ['name', 'phone']

admin.site.register(Donor, DonorAdmin)

it should work fine. If an improvement is needed consider adding an full-text index to the underlying RDBMS. For example, with postgres you can create either a text search indexes post 8.3 with a one liner in the underlying database, which django should automatically use: http://www.postgresql.org/docs/8.3/static/textsearch-indexes.html

Leave a comment