Use subquery when searching for similarity on translated Char

issue10624
review363621002
This commit is contained in:
Cédric Krier committed 2021-08-12 18:38:15 +02:00
1 parent 97c0707106
commit 0cca1c8d57
2 files changed
+29 -8

No files matched your search

+5
View File
@@ -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 @@ class Char(FieldTranslate):
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 @@ class Char(FieldTranslate):
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))
+24 -8
View File
@@ -586,11 +586,7 @@ class FieldCharSimilarityTestCase(ExtensionTestCase):
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 @@ class FieldCharSimilarityTestCase(ExtensionTestCase):
]), [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 @@ class FieldCharSimilarityTestCase(ExtensionTestCase):
], 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()