mirror of
https://github.com/django/django.git
synced 2025-12-04 00:55:36 +00:00
Fixed #24938 -- Added PostgreSQL trigram support.
This commit is contained in:
parent
d7334b405f
commit
1962a96a30
11 changed files with 184 additions and 4 deletions
|
|
@ -2,6 +2,32 @@
|
|||
PostgreSQL specific lookups
|
||||
===========================
|
||||
|
||||
Trigram similarity
|
||||
==================
|
||||
|
||||
.. fieldlookup:: trigram_similar
|
||||
|
||||
.. versionadded:: 1.10
|
||||
|
||||
The ``trigram_similar`` lookup allows you to perform trigram lookups,
|
||||
measuring the number of trigrams (three consecutive characters) shared, using a
|
||||
dedicated PostgreSQL extension. A trigram lookup is given an expression and
|
||||
returns results that have a similarity measurement greater than the current
|
||||
similarity threshold.
|
||||
|
||||
To use it, add ``'django.contrib.postgres'`` in your :setting:`INSTALLED_APPS`
|
||||
and activate the `pg_trgm extension
|
||||
<http://www.postgresql.org/docs/current/interactive/pgtrgm.html>`_ on
|
||||
PostgreSQL. You can install the extension using the
|
||||
:class:`~django.contrib.postgres.operations.TrigramExtension` migration
|
||||
operation.
|
||||
|
||||
The ``trigram_similar`` lookup can be used on
|
||||
:class:`~django.db.models.CharField` and :class:`~django.db.models.TextField`::
|
||||
|
||||
>>> City.objects.filter(name__trigram_similar="Middlesborough")
|
||||
['<City: Middlesbrough>']
|
||||
|
||||
``Unaccent``
|
||||
============
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue