Commit 0025f56e authored by Michal Čihař's avatar Michal Čihař

Add command to build index

parent 9f9bb81c
......@@ -85,4 +85,5 @@ On upgrade to version 0.6 you should run :program:`./manage.py syncdb` and
in installation section.
On upgrade to version 0.7 you should run :program:`./manage.py syncdb` to
setup new tables.
setup new tables and :program:`./manage.py rebuild_index` to build index for
fulltext search.
......@@ -21,6 +21,13 @@ The ./manage.py is extended with following commands:
Reloads translations from disk (eg. in case you did some updates in Git
repository).
.. option:: rebuild_index
Rebuilds index for fulltext search. This might be lengthy operation if you
have huge set of translation units.
You can use ``--clean`` to remove all words from database prior updating.
.. option:: setupgroups
Configures default groups and (if called with ``--move``) assigns all users
......
from django.core.management.base import BaseCommand, CommandError
from trans.models import Unit
from ftsearch.models import WordLocation, Word
from optparse import make_option
class Command(BaseCommand):
help = 'updates index for fulltext search'
option_list = BaseCommand.option_list + (
make_option('--clean',
action='store_true',
dest='clean',
default=False,
help='removes also all words from database'),
)
def handle(self, *args, **options):
if options['clean']:
Word.objects.all().delete()
WordLocation.objects.all().delete()
units = Unit.objects.all()
for unit in units:
Unit.objects.add_to_index(unit)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment