Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Search for Django and PostgreSQL

branch: master

fix 1.6 compat

latest commit dd7bfd6c3a
Mikko Hellsing sorl authored March 21, 2014
Octocat-spinner-32 pgindex fix 1.6 compat March 21, 2014
Octocat-spinner-32 tests cleanup August 09, 2011
Octocat-spinner-32 .gitignore bring it on February 03, 2011
Octocat-spinner-32 LICENSE bring it on February 03, 2011
Octocat-spinner-32 setup cleanup February 05, 2011
Octocat-spinner-32 README.rst Update README.rst September 04, 2013
Octocat-spinner-32 fix 1.6 compat March 21, 2014


Search for Django and PostgreSQL.


  • Django >= 1.1
  • django-stringfield >= 0.1.5
  • django-cerial >= 0.0.2


First install the package from pypi using pip:

pip install django-pgindex

Then make pgindex an app in your INSTALLED_APPS:


Sync your database:

python syncdb



Create and Index class and register it to your model, much like registering an admin class to your model. Example:

from django.db import models
from .index import ItemIndex
from pgindex import register

class Item(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()

    def get_absolute_url(self):
        return '/item/'

register(Item, ItemIndex)

from pgindex import IndexBase, Vector

class ItemIndex(IndexBase):
    def get_title(self):
        return self.obj.title

    def get_description(self):
        return self.obj.content

    def get_vectors(self):
        return (
            Vector(self.obj.title, weight='A'),
            Vector(self.obj.content, weight='B'),

To search simply use the method which returns a queryset from the pgindex.models.Index model:

from pgindex import search

index_queryset = search('foo')

See tests for examples.

pgindex.IndexBase methods


This should return the title of the indexed object.


This should return the description of the indexed object.


This should return the url of the indexed object.


You can return additional data that will be stored in the index field here, this value will be pickled and depickled.


If this returns False and index will not be created


Can return a datetime.datetime which is the time when the index will be used. Returning None means that it will always be used.


Can return a datetime.datetime which is the time for the index expiration. Returning None means that it will never expire.


This method needs to return a list or tuple of pgindex.Vector instances. This in turn is the base for the text search column.

Something went wrong with that request. Please try again.