From f0e8bab97707a729bada5b7fa17d81202ab8eaa8 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 18 Sep 2018 12:16:31 +0200 Subject: Unidecode "simple" fields for search index --- ishtar_common/models.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 15d6a0ba9..5be06fd32 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1262,16 +1262,15 @@ class FullSearch(models.Model): if self.BASE_SEARCH_VECTORS: # query "simple" fields - q = base_q.annotate( - search=SearchVector( - *self.BASE_SEARCH_VECTORS, - config=settings.ISHTAR_SEARCH_LANGUAGE - )).values('search') - search_vectors.append( - unidecode( - q.all()[0]['search'].decode('utf-8') - ) - ) + q = base_q.values(*self.BASE_SEARCH_VECTORS) + res = q.all()[0] + for base_search_vector in self.BASE_SEARCH_VECTORS: + data = res[base_search_vector] + data = unidecode(unicode(data)) + with connection.cursor() as cursor: + cursor.execute("SELECT to_tsvector(%s)", [data]) + row = cursor.fetchone() + search_vectors.append(row[0]) if self.PROPERTY_SEARCH_VECTORS: for attr in self.PROPERTY_SEARCH_VECTORS: -- cgit v1.2.3