Not Logged In

djorm-ext-pgfulltext 0.6

Pgfulltext module of django orm extensions package (collection of third party plugins build in one unified package).

Now compatible with python2 and python3 with same code base.

Ready for django 1.3, 1.4 and 1.5

Introduction

Full Text Searching (or just text search) provides the capability to identify natural-language documents that satisfy a query, and optionally to sort them by relevance to the query. The most common type of search is to find all documents containing given query terms and return them in order of their similarity to the query. Notions of query and similarity are very flexible and depend on the specific application. The simplest search considers query as a set of words and similarity as the frequency of query words in the document. (From postgresql documentation.)

Classes

djorm_pgfulltext.fields.VectorField

An tsvector index field which stores converted text into special format.

How to use it

To use it, you will need to add a new field. Obviously, this is not mandatory, as it can specify which fields you want to search at the time of calling the search. Keep in mind that you should put the corresponding indices for the fields to be used.

fromdjorm_pgfulltext.modelsimportSearchManagerfromdjorm_pgfulltext.fieldsimportVectorFieldfromdjango.dbimportmodelsclassPage(models.Model):name=models.CharField(max_length=200)description=models.TextField()search_index=VectorField()objects=SearchManager(fields=('name','description'),config='pg_catalog.english',# this is defaultsearch_field='search_index',# this is defaultauto_update_search_field=True)

The manager automatically injected update_search_field method to the model instance.
Also, not to override the save method, you can pass the parameter auto_update_search_field = True, so
the index field is updated automatically by calling the save method.

Usage examples:

The config parameter is optional and defaults to ‘pg_catalog.english’.

The fields parameter is optional. If a list of tuples, you can specify the ranking of each field, if it is None, it gets ‘D’ as the default.

It can also be a simple list of fields, and the ranking will be selected by default. If the field is empty, the index was applied to all fields CharField and TextField.

To search, use the search method of the manager. The current implementation, by default uses unaccent extension for ignore the accents. Also, the searches are case insensitive.