Pgfulltext module of django orm extensions package (collection of third party plugins build in one unified package).
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.)
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.
from djorm_pgfulltext.models import SearchManager from djorm_pgfulltext.fields import VectorField from django.db import models class Page(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 default search_field = 'search_index', # this is default auto_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.
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.
>>> Page.objects.search("documentation & about") [<Page: Page: Home page>] >>> Page.objects.search("about | documentation | django | home", raw=True) [<Page: Page: Home page>, <Page: Page: About>, <Page: Page: Navigation>]
FTS extension by default uses plainto_tsquery instead of to_tosquery, for this reason the use of raw parameter.
You must ensure you have installed the extension unaccent:
CREATE EXTENSION unaccent; ALTER FUNCTION unaccent(text) IMMUTABLE;
You can install this extension on template1 database for make this extension automatically available for all new created databases.
|File||Type||Python Version||Uploaded On||Downloads|
|djorm-ext-pgfulltext-0.10.tar.gz||Source||May 22, 2014||15,004|
|0.10||May 22, 2014|
|0.9.3||Aug. 24, 2015|
|0.9.2||July 17, 2014|
|0.9||Dec. 24, 2013|
|0.8||Feb. 23, 2013|
|0.7||Dec. 6, 2012|
|0.6||Nov. 29, 2012|
|0.5||Nov. 17, 2012|
|0.4.2||Nov. 17, 2012|
|0.4.1||Nov. 1, 2012|
|0.4.0||Oct. 1, 2012|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||0.4.2||Release Created|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||0.4.0||Release Created|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||0.4.1||Release Created|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||0.10||Release Created|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||0.6||Release Created|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||0.7||Release Created|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||0.5||Release Created|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||0.9.3||Release Created|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||0.9.2||Release Created|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||0.8||Release Created|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||0.9||Release Created|
|Aug. 24, 2015, 11:06 p.m.||djorm-ext-pgfulltext||Package Created|