changeset 9cc55cca68b0 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=9cc55cca68b0
description:
Use subquery when searching for similarity on translated Char
issue10624
review363621002
diffstat:
trytond/model/fields/char.py | 5 +++++
trytond/tests/test_field_char.py | 32 ++++++++++++++++++++++++--------
2 files changed, 29 insertions(+), 8 deletions(-)
diffs (86 lines):
diff -r b7ba7525fd00 -r 9cc55cca68b0 trytond/model/fields/char.py
--- a/trytond/model/fields/char.py Thu Aug 12 18:35:15 2021 +0200
+++ b/trytond/model/fields/char.py Thu Aug 12 18:38:15 2021 +0200
@@ -2,6 +2,7 @@
# this repository contains the full copyright notices and license terms.
import warnings
+from sql.conditionals import Coalesce, NullIf
from sql.operators import Not
from trytond.rpc import RPC
@@ -91,6 +92,7 @@
language = transaction.language
model, join, column = self._get_translation_column(
Model, name)
+ column = Coalesce(NullIf(column, ''), self.sql_column(model))
else:
language = None
column = self.sql_column(table)
@@ -106,6 +108,9 @@
database.similarity(column, sim_value) >= threshold)
if operator.startswith('not'):
expression = Not(expression)
+ if self.translate:
+ expression = table.id.in_(
+ join.select(model.id, where=expression))
key = '%s.%s.search_full_text' % (Model.__name__, name)
if ((self.search_full_text or context.get(key))
diff -r b7ba7525fd00 -r 9cc55cca68b0 trytond/tests/test_field_char.py
--- a/trytond/tests/test_field_char.py Thu Aug 12 18:35:15 2021 +0200
+++ b/trytond/tests/test_field_char.py Thu Aug 12 18:38:15 2021 +0200
@@ -586,11 +586,7 @@
activate_module('tests')
super().setUpClass()
- @with_transaction()
- def test_search(self):
- "Test search"
- pool = Pool()
- Model = pool.get('test.char')
+ def _test_search(self, Model):
record1, record2 = Model.create([{
'char': "word",
}, {
@@ -602,10 +598,18 @@
]), [record1])
@with_transaction()
- def test_order(self):
- "Test order"
+ def test_search(self):
+ "Test search"
pool = Pool()
- Model = pool.get('test.char')
+ self._test_search(pool.get('test.char'))
+
+ @with_transaction()
+ def test_search_translated(self):
+ "Test search translated"
+ pool = Pool()
+ self._test_search(pool.get('test.char_translate'))
+
+ def _test_order(self, Model):
record1, record2 = Model.create([{
'char': "word",
}, {
@@ -618,6 +622,18 @@
], order=[('char', 'DESC')]),
[record2, record1])
+ @with_transaction()
+ def test_order(self):
+ "Test order"
+ pool = Pool()
+ self._test_order(pool.get('test.char'))
+
+ @with_transaction()
+ def test_order_translated(self):
+ "Test order translated"
+ pool = Pool()
+ self._test_order(pool.get('test.char_translate'))
+
def suite():
suite_ = unittest.TestSuite()