mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #32492 -- Added TrigramWordSimilarity() and TrigramWordDistance() on PostgreSQL.
This commit is contained in:
parent
4ca508a689
commit
4e4082f939
10 changed files with 148 additions and 9 deletions
|
@ -14,9 +14,8 @@ 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
|
||||
<https://www.postgresql.org/docs/current/pgtrgm.html>`_ on PostgreSQL. You can
|
||||
install the extension using the
|
||||
and activate the `pg_trgm extension`_ on PostgreSQL. You can install the
|
||||
extension using the
|
||||
:class:`~django.contrib.postgres.operations.TrigramExtension` migration
|
||||
operation.
|
||||
|
||||
|
@ -26,6 +25,31 @@ The ``trigram_similar`` lookup can be used on
|
|||
>>> City.objects.filter(name__trigram_similar="Middlesborough")
|
||||
['<City: Middlesbrough>']
|
||||
|
||||
.. fieldlookup:: trigram_word_similar
|
||||
|
||||
.. versionadded:: 4.0
|
||||
|
||||
The ``trigram_word_similar`` lookup allows you to perform trigram word
|
||||
similarity lookups using a dedicated PostgreSQL extension. It can be
|
||||
approximately understood as measuring the greatest number of trigrams shared
|
||||
between the parameter and any substring of the field. A trigram word lookup is
|
||||
given an expression and returns results that have a word 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`_ on PostgreSQL. You can install the
|
||||
extension using the
|
||||
:class:`~django.contrib.postgres.operations.TrigramExtension` migration
|
||||
operation.
|
||||
|
||||
The ``trigram_word_similar`` lookup can be used on
|
||||
:class:`~django.db.models.CharField` and :class:`~django.db.models.TextField`::
|
||||
|
||||
>>> Sentence.objects.filter(name__trigram_word_similar='Middlesborough')
|
||||
['<Sentence: Gumby rides on the path of Middlesbrough>']
|
||||
|
||||
.. _`pg_trgm extension`: https://www.postgresql.org/docs/current/pgtrgm.html
|
||||
|
||||
``Unaccent``
|
||||
============
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue