changeset 6bf9bd2b6c2a in trytond:6.0
details: https://hg.tryton.org/trytond?cmd=changeset&node=6bf9bd2b6c2a
description:
        Search by similarity only if a threshold is defined

        issue10710
        review363851002
        (grafted from bb31ef4d81ad395677e9b6f6ca78d67e915d54c5)
diffstat:

 doc/ref/models/fields.rst    |  5 +++--
 trytond/model/fields/char.py |  8 ++++----
 2 files changed, 7 insertions(+), 6 deletions(-)

diffs (34 lines):

diff -r 46c577b70e20 -r 6bf9bd2b6c2a doc/ref/models/fields.rst
--- a/doc/ref/models/fields.rst Fri Sep 10 19:11:45 2021 +0200
+++ b/doc/ref/models/fields.rst Fri Sep 10 19:13:05 2021 +0200
@@ -269,9 +269,10 @@
 A single line string field.
 
 Search by similarity is used for the ``ilike`` operator and
-:meth:`~trytond.tools.is_full_text` value if the backend supports it.
+:meth:`~trytond.tools.is_full_text` value if the backend supports it and a
+threshold is set.
 The similarity threshold is defined for the context key ``<model name>.<field
-name>.search_similarity`` (default value is ``0.3``).
+name>.search_similarity`` or ``search_similarity``.
 
 The field is ordered using the similarity with the context value from the key
 ``<model name>.<field name>.order`` if it is set.
diff -r 46c577b70e20 -r 6bf9bd2b6c2a trytond/model/fields/char.py
--- a/trytond/model/fields/char.py      Fri Sep 10 19:11:45 2021 +0200
+++ b/trytond/model/fields/char.py      Fri Sep 10 19:13:05 2021 +0200
@@ -98,10 +98,10 @@
                 column = self.sql_column(table)
             column = self._domain_column(operator, column)
 
-            if database.has_similarity() and is_full_text(value):
-                threshold = context.get(
-                    '%s.%s.search_similarity' % (Model.__name__, name),
-                    context.get('search_similarity', 0.3))
+            threshold = context.get(
+                '%s.%s.search_similarity' % (Model.__name__, name),
+                context.get('search_similarity'))
+            if database.has_similarity() and is_full_text(value) and threshold:
                 sim_value = unescape_wildcard(value)
                 sim_value = self._domain_value(operator, sim_value)
                 expression = (

Reply via email to