# -*- coding: utf-8 -*-
+
from django.conf import settings
from lucene import SimpleFSDirectory, IndexWriter, File, Field, \
NumericField, Version, Document, JavaError, IndexSearcher, \
BlockJoinQuery, BlockJoinCollector, TermsFilter, \
HashSet, BooleanClause, Term, CharTermAttribute, \
PhraseQuery, StringReader, TermQuery, BlockJoinQuery, \
- Sort, Integer
+ Sort, Integer, \
+ initVM, CLASSPATH
# KeywordAnalyzer
+JVM = initVM(CLASSPATH)
import sys
import os
import errno
if overwrite:
self.remove_book(book)
-
doc = self.extract_metadata(book)
parts = self.extract_content(book)
block = ArrayList().of_(Document)
self.index = ReusableIndex.index
else:
print("opening index")
- ReusableIndex.pool = ThreadPool(threads)
+ ReusableIndex.pool = ThreadPool(threads, initializer=lambda: JVM.attachCurrentThread() )
ReusableIndex.pool_jobs = []
Index.open(self, analyzer)
ReusableIndex.index = self.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(Index.index_book, (self,) + args, kw)
ReusableIndex.pool_jobs.append(job)
@staticmethod
if ReusableIndex.index is not None:
print("closing index")
for job in ReusableIndex.pool_jobs:
- job.wait()
+ job.get()
+ sys.stdout.write('.')
+ sys.stdout.flush()
ReusableIndex.pool.close()
ReusableIndex.index.optimize()