diff options
author | Nikita Marchant <nikita.marchant@gmail.com> | 2021-09-15 12:57:49 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-09-17 13:05:15 +0200 |
commit | 4e4082f9396e21de0bd88dbfc651da9ad01c7c0c (patch) | |
tree | 34d93d1ef520a097f95cf46cd854ea47700214ef /django/contrib/postgres/search.py | |
parent | 4ca508a68916dd43da45fd6e8b9004824a62d9c8 (diff) | |
download | django-4e4082f9396e21de0bd88dbfc651da9ad01c7c0c.tar.gz |
Fixed #32492 -- Added TrigramWordSimilarity() and TrigramWordDistance() on PostgreSQL.
Diffstat (limited to 'django/contrib/postgres/search.py')
-rw-r--r-- | django/contrib/postgres/search.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/django/contrib/postgres/search.py b/django/contrib/postgres/search.py index f1640d85ba..164d359b91 100644 --- a/django/contrib/postgres/search.py +++ b/django/contrib/postgres/search.py @@ -293,6 +293,15 @@ class TrigramBase(Func): super().__init__(expression, string, **extra) +class TrigramWordBase(Func): + output_field = FloatField() + + def __init__(self, string, expression, **extra): + if not hasattr(string, 'resolve_expression'): + string = Value(string) + super().__init__(string, expression, **extra) + + class TrigramSimilarity(TrigramBase): function = 'SIMILARITY' @@ -300,3 +309,12 @@ class TrigramSimilarity(TrigramBase): class TrigramDistance(TrigramBase): function = '' arg_joiner = ' <-> ' + + +class TrigramWordDistance(TrigramWordBase): + function = '' + arg_joiner = ' <<-> ' + + +class TrigramWordSimilarity(TrigramWordBase): + function = 'WORD_SIMILARITY' |