summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_files/tests.py2
-rw-r--r--ishtar_common/models.py48
2 files changed, 28 insertions, 22 deletions
diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py
index cb73ffb96..7d6ede6f5 100644
--- a/archaeological_files/tests.py
+++ b/archaeological_files/tests.py
@@ -137,7 +137,7 @@ class FileTest(TestCase, FileInit):
self.assertEqual(self.item.history.count(), nb_hist)
new_values = self.item.values()
for k in initial_values.keys():
- if k == 'last_modified':
+ if k in ('last_modified', 'search_vector'):
continue
elif k == 'history_m2m' and not initial_values[k]:
initial_values[k] = dict(
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 96dfa716c..c0243787b 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1422,14 +1422,15 @@ class FullSearch(models.Model):
key = M2M_SEARCH_VECTOR.split('__')[0]
rel_key = getattr(self, key)
for item in rel_key.values('pk').all():
- query_dct = {key + "__pk": item['pk']}
- q = copy.copy(base_q).filter(**query_dct)
- q = q.annotate(
- search=SearchVector(
- M2M_SEARCH_VECTOR,
- config=settings.ISHTAR_SEARCH_LANGUAGE)
- ).values('search')
- search_vectors.append(q.all()[0]['search'])
+ for lang in ("simple", settings.ISHTAR_SEARCH_LANGUAGE):
+ query_dct = {key + "__pk": item['pk']}
+ q = copy.copy(base_q).filter(**query_dct)
+ q = q.annotate(
+ search=SearchVector(
+ M2M_SEARCH_VECTOR,
+ config=lang)
+ ).values('search')
+ search_vectors.append(q.all()[0]['search'])
# int/float are not well managed by the SearchVector
for INT_SEARCH_VECTOR in self.INT_SEARCH_VECTORS:
@@ -1466,10 +1467,12 @@ class FullSearch(models.Model):
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])
+ for lang in ("simple", settings.ISHTAR_SEARCH_LANGUAGE):
+ with connection.cursor() as cursor:
+ cursor.execute("SELECT to_tsvector(%s, %s)",
+ [lang, data])
+ row = cursor.fetchone()
+ search_vectors.append(row[0])
if self.PROPERTY_SEARCH_VECTORS:
for attr in self.PROPERTY_SEARCH_VECTORS:
@@ -1479,10 +1482,12 @@ class FullSearch(models.Model):
if not data:
continue
data = unicode(data)
- with connection.cursor() as cursor:
- cursor.execute("SELECT to_tsvector(%s)", [data])
- row = cursor.fetchone()
- search_vectors.append(row[0])
+ for lang in ("simple", settings.ISHTAR_SEARCH_LANGUAGE):
+ with connection.cursor() as cursor:
+ cursor.execute("SELECT to_tsvector(%s, %s)",
+ [lang, data])
+ row = cursor.fetchone()
+ search_vectors.append(row[0])
if hasattr(self, 'data') and self.data:
content_type = ContentType.objects.get_for_model(self)
@@ -1498,11 +1503,12 @@ class FullSearch(models.Model):
data = data[key]
if no_data:
continue
- with connection.cursor() as cursor:
- cursor.execute("SELECT to_tsvector(%s)",
- [data])
- row = cursor.fetchone()
- search_vectors.append(row[0])
+ for lang in ("simple", settings.ISHTAR_SEARCH_LANGUAGE):
+ with connection.cursor() as cursor:
+ cursor.execute("SELECT to_tsvector(%s, %s)",
+ [lang, data])
+ row = cursor.fetchone()
+ search_vectors.append(row[0])
new_search_vector = merge_tsvectors(search_vectors)
changed = old_search != new_search_vector
if save and changed: