summaryrefslogtreecommitdiff
path: root/django/contrib/postgres/search.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/contrib/postgres/search.py')
-rw-r--r--django/contrib/postgres/search.py18
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'