1 from django.core.management.base import BaseCommand
4 from optparse import make_option
7 from django.conf import settings
9 class Command(BaseCommand):
10 help = 'Reindex everything.'
13 option_list = BaseCommand.option_list + (
14 make_option('-C', '--check-just-read', action='store_true', dest='check', default=False,
15 help='Check snippets utf-8'),
16 make_option('-c', '--check', action='store_true', dest='check2', default=False,
17 help='Check snippets utf-8 by walking through index'),
21 def handle(self, *args, **opts):
22 from catalogue.models import Book
26 sfn = glob(settings.SEARCH_INDEX+'snippets/*')
30 bkid = int(path.basename(fn))
34 uc = cont.decode('utf-8')
35 except UnicodeDecodeError, ude:
36 print "error in snippets %d" % bkid
39 reader = s.searcher.getIndexReader()
40 numdocs = reader.numDocs()
41 for did in range(numdocs):
42 doc = reader.document(did)
43 if doc and doc.get('book_id'):
44 bkid = int(doc.get('book_id'))
45 #import pdb; pdb.set_trace()
46 stdout.write("\r%d / %d" % (did, numdocs))
48 ss = doc.get('snippet_position')
49 sl = doc.get('snippet_length')
51 snips = Snippets(bkid)
53 txt = snips.get((ss,sl))
55 except UnicodeDecodeError, ude:
56 stdout.write("\nerror in snippets %d\n" % bkid)
59 stdout.write("\ndone.\n")