diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-12 17:28:09 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-12 17:28:09 +0200 |
commit | e82219dead1078df30cd7006c024cb44a42e2089 (patch) | |
tree | d9eab5fe8c4eb9aa8b6dde3f74b12281e38cd842 /ishtar_common/management/commands/update_search_vectors.py | |
parent | 2f61567837dab3e2e7354d8b81e844596046cb2a (diff) | |
download | Ishtar-e82219dead1078df30cd7006c024cb44a42e2089.tar.bz2 Ishtar-e82219dead1078df30cd7006c024cb44a42e2089.zip |
Searches: update_search_vectors command
Diffstat (limited to 'ishtar_common/management/commands/update_search_vectors.py')
-rw-r--r-- | ishtar_common/management/commands/update_search_vectors.py | 24 |
1 files changed, 24 insertions, 0 deletions
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") |