X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/3fc3ab8693fc63c350e26484e876a8092f6b5d90..3b73241bfb6fa47f8b7c1d6629a3e537d34aad3c:/apps/search/index.py diff --git a/apps/search/index.py b/apps/search/index.py index 5ebae2c42..7ec88c619 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -22,7 +22,7 @@ import catalogue.models from multiprocessing.pool import ThreadPool from threading import current_thread import atexit - +import traceback class WLAnalyzer(PerFieldAnalyzerWrapper): def __init__(self): @@ -125,7 +125,7 @@ class Index(IndexStore): doc = self.create_book_doc(book) doc.add(Field("slug", book.slug, Field.Store.NO, Field.Index.ANALYZED_NO_NORMS)) - doc.add(Field("tags", ','.join([t.name for t in book.tags]), Field.Store.NO, Field.Index.ANALYZED)) + #doc.add(Field("tags", ','.join([t.name for t in book.tags]), Field.Store.NO, Field.Index.ANALYZED)) doc.add(Field("is_book", 'true', Field.Store.NO, Field.Index.NOT_ANALYZED)) # validator, name @@ -247,6 +247,17 @@ class Index(IndexStore): self.close() +def log_exception_wrapper(f): + def _wrap(*a): + try: + f(*a) + except Exception, e: + print("Error in indexing thread: %s" % e) + traceback.print_exc() + raise e + return _wrap + + class ReusableIndex(Index): """ Works like index, but does not close/optimize Lucene index @@ -271,17 +282,18 @@ class ReusableIndex(Index): atexit.register(ReusableIndex.close_reusable) def index_book(self, *args, **kw): - job = ReusableIndex.pool.apply_async(Index.index_book, (self,) + args, kw) + job = ReusableIndex.pool.apply_async(log_exception_wrapper(Index.index_book), (self,) + args, kw) ReusableIndex.pool_jobs.append(job) @staticmethod def close_reusable(): if ReusableIndex.index is not None: - print("closing index") + print("wait for indexing to finish") for job in ReusableIndex.pool_jobs: job.get() sys.stdout.write('.') sys.stdout.flush() + print("done.") ReusableIndex.pool.close() ReusableIndex.index.optimize()