infopages fixtures
[wolnelektury.git] / apps / search / management / commands / reindex.py
1 from django.core.management.base import BaseCommand
2
3 from optparse import make_option
4 class Command(BaseCommand):
5     help = 'Reindex everything.'
6     args = ''
7     
8     option_list = BaseCommand.option_list + (
9         make_option('-n', '--book-id', action='store_true', dest='book_id', default=False,
10             help='book id'),
11     )
12     def handle(self, *args, **opts):
13         from catalogue.models import Book
14         import search
15         idx = search.ReusableIndex()
16         idx.open()
17
18         if args:
19             books = []
20             for a in args:
21                 if opts['book_id']:
22                     books += Book.objects.filter(id=int(a)).all()
23                 else:
24                     books += Book.objects.filter(slug=a).all()
25         else:
26             books = Book.objects.all()
27             
28         for b in books:
29             print b.title
30             idx.index_book(b)
31         print 'Reindexing tags.'
32         idx.index_tags()
33         idx.close()