summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_finds/models_finds.py4
-rw-r--r--ishtar_common/management/commands/update_search_vectors.py24
-rw-r--r--ishtar_common/utils.py4
3 files changed, 29 insertions, 3 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 96c21e79e..8052601bf 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -240,8 +240,8 @@ class BaseFind(BulkUpdatedItem, BaseHistorizedItem, OwnPerms):
RELATED_POST_PROCESS = ['find']
CACHED_LABELS = ['cache_short_id', 'cache_complete_id']
PARENT_SEARCH_VECTORS = ['context_record']
- BASE_SEARCH_VECTORS = ["cached_label", "label", "description",
- "comment", "cache_short_id", "cache_complete_id"]
+ BASE_SEARCH_VECTORS = ["label", "description", "comment", "cache_short_id",
+ "cache_complete_id"]
class Meta:
verbose_name = _(u"Base find")
diff --git a/ishtar_common/management/commands/update_search_vectors.py b/ishtar_common/management/commands/update_search_vectors.py
new file mode 100644
index 000000000..c73a6e88e
--- /dev/null
+++ b/ishtar_common/management/commands/update_search_vectors.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+
+from django.core.management.base import BaseCommand
+import django.apps
+
+
+class Command(BaseCommand):
+ help = "./manage.py update_search_vectors\n\n"\
+ "Update full texte search vectors."
+
+ def handle(self, *args, **options):
+ for model in django.apps.apps.get_models():
+ if hasattr(model, "update_search_vector") and \
+ getattr(model, "BASE_SEARCH_VECTORS", None):
+ self.stdout.write("\n* update {}".format(model))
+ total = model.objects.count()
+ for idx, item in enumerate(model.objects.all()):
+ sys.stdout.write("\r{}/{} ".format(idx, total))
+ sys.stdout.flush()
+ item.update_search_vector()
+ self.stdout.write("\n")
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index f3b1a821b..5d9e85c60 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -313,7 +313,9 @@ def merge_tsvectors(vectors):
current_position = max_position
for dct_member in vector.split(" "):
- key, positions = dct_member.split(':')
+ splitted = dct_member.split(':')
+ key = ":".join(splitted[:-1])
+ positions = splitted[-1]
key = key[1:-1] # remove quotes
positions = [int(pos) + current_position
for pos in positions.split(',')]