예제 #1
0
    def handle(self, *args, **opts):
        from catalogue.models import Book
        from search.index import Index
        idx = Index()
        
        if not opts['just_tags']:
            if args:
                books = []
                for a in args:
                    if opts['book_id']:
                        books += Book.objects.filter(id=int(a)).all()
                    else:
                        books += Book.objects.filter(slug=a).all()
            else:
                books = list(Book.objects.all())

            while books:
                try:
                    b = books[0]
                    print b.title
                    idx.index_book(b)
                    idx.index.commit()
                    books.pop(0)
                except Exception, e:
                    print "Error occured: %s" % e
                    try:
                        # we might not be able to rollback
                        idx.index.rollback()
                    except:
                        pass
                    retry = query_yes_no("Retry?")
                    if not retry:
                        break
예제 #2
0
 def search_index(self, book_info=None, index=None, index_tags=True, commit=True):
     if index is None:
         from search.index import Index
         index = Index()
     try:
         index.index_book(self, book_info)
         if index_tags:
             index.index_tags()
         if commit:
             index.index.commit()
     except Exception, e:
         index.index.rollback()
         raise e
예제 #3
0
파일: reindex.py 프로젝트: fnp/wolnelektury
    def handle(self, **opts):
        from catalogue.models import Book
        from search.index import Index
        idx = Index()
        
        if not opts['just_tags']:
            if opts['args']:
                books = []
                for a in opts['args']:
                    if opts['book_id']:
                        books += Book.objects.filter(id=int(a)).all()
                    else:
                        books += Book.objects.filter(slug=a).all()
            else:
                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]
                    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:
                    traceback.print_exc()
                    try:
                        # we might not be able to rollback
                        idx.index.rollback()
                    except:
                        pass
                    retry = query_yes_no("Retry?")
                    if not retry:
                        break

        print('Reindexing tags.')
        idx.index_tags()
        idx.index.commit()