1. Shmigelsky Andrey
  2. django-tsearch2

Wiki

Clone wiki

django-tsearch2 / Home

Description

Django application that provide full-text search in PostgreSQL.

Requirements

Usage

First, import tsearch2 in your models.py file and run register method with model class as first parameter and dictionary of fields names with their weight as second parameter.

import tsearch2

tsearch2.register(YourModel, {'content': 'A', 'title': 'B', 'user__username': 'D'} )

It will attach search manager to your model with default name "index" and also add tsvector column to your database. As you can see, dictionary can use two underscores syntax to access related models. You can read about weights here.

After you have done with your model, insert to django shell, import your model and run

YourModel.index.update_index()

Now you can use full text search:

YourModel.search.filter(is_published=True).search("mystring")

Updated