summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-03-20 18:24:31 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-03-20 18:24:31 +0100
commit5864bd0cb09d4de5d2b192a9f3cb59bfbacfae46 (patch)
tree968f764d40143646b26a17bb8486e1c6b975642a /ishtar_common
parent0ea89f12deae7c59b0f5901662c6a519a8f1e017 (diff)
downloadIshtar-5864bd0cb09d4de5d2b192a9f3cb59bfbacfae46.tar.bz2
Ishtar-5864bd0cb09d4de5d2b192a9f3cb59bfbacfae46.zip
Search: index simple and localized lexeme
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/models.py48
1 files changed, 27 insertions, 21 deletions
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: