X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ae60b2a3949e96357477cc04f90fd0873cee8a92..3af75386ed5c78b09c4669442a2422a388e949c3:/src/search/management/commands/reindex.py?ds=inline diff --git a/src/search/management/commands/reindex.py b/src/search/management/commands/reindex.py index f982b2a3e..da4574fe0 100755 --- a/src/search/management/commands/reindex.py +++ b/src/search/management/commands/reindex.py @@ -3,6 +3,8 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # import sys +import traceback + from django.core.management.base import BaseCommand from optparse import make_option @@ -49,6 +51,8 @@ class Command(BaseCommand): help='book id instead of slugs'), make_option('-t', '--just-tags', action='store_true', dest='just_tags', default=False, help='just reindex tags'), + make_option('--start', dest='start_from', default=None, help='start from this slug'), + make_option('--stop', dest='stop_after', default=None, help='stop after this slug'), ) def handle(self, *args, **opts): @@ -65,17 +69,26 @@ class Command(BaseCommand): else: books += Book.objects.filter(slug=a).all() else: - books = list(Book.objects.all()) - + books = list(Book.objects.order_by('slug')) + start_from = opts.get('start_from') + stop_after = opts.get('stop_after') + if start_from: + start_from = start_from.replace('-', '') + if stop_after: + stop_after = stop_after.replace('-', '') while books: try: b = books[0] - print b.title - idx.index_book(b) - idx.index.commit() + slug = b.slug.replace('-', '') + if stop_after and slug > stop_after: + break + if not start_from or slug >= start_from: + print b.slug + idx.index_book(b) + idx.index.commit() books.pop(0) - except Exception, e: - print "Error occured: %s" % e + except: + traceback.print_exc() try: # we might not be able to rollback idx.index.rollback()