本文整理汇总了Python中PyLucene.getVMEnv方法的典型用法代码示例。如果您正苦于以下问题:Python PyLucene.getVMEnv方法的具体用法?Python PyLucene.getVMEnv怎么用?Python PyLucene.getVMEnv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyLucene
的用法示例。
在下文中一共展示了PyLucene.getVMEnv方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: begin_transaction
# 需要导入模块: import PyLucene [as 别名]
# 或者: from PyLucene import getVMEnv [as 别名]
def begin_transaction(self):
"""PyLucene does not support transactions
Thus this function just opens the database for write access.
Call "cancel_transaction" or "commit_transaction" to close write
access in order to remove the exclusive lock from the database
directory.
"""
jvm = PyLucene.getVMEnv()
jvm.attachCurrentThread()
self._writer_open()
示例2: __del__
# 需要导入模块: import PyLucene [as 别名]
# 或者: from PyLucene import getVMEnv [as 别名]
def __del__(self):
"""remove lock and close writer after loosing the last reference"""
jvm = PyLucene.getVMEnv()
jvm.attachCurrentThread()
self._writer_close()
if hasattr(self, "reader") and self.reader is not None:
self.reader.close()
self.reader = None
if hasattr(self, "searcher") and self.searcher is not None:
self.searcher.close()
self.searcher = None
示例3: __init__
# 需要导入模块: import PyLucene [as 别名]
# 或者: from PyLucene import getVMEnv [as 别名]
def __init__(self, basedir, analyzer=None, create_allowed=True):
"""Initialize or open an indexing database.
Any derived class must override __init__.
:raise ValueError: The given location exists, but the database type
is incompatible (e.g. created by a different indexing engine)
:raise OSError: the database failed to initialize
:param basedir: The parent directory of the database
:type basedir: str
:param analyzer: Bitwise combination of possible analyzer flags
to be used as the default analyzer for this database.
Leave it empty to use the system default analyzer
(self.ANALYZER_DEFAULT). See self.ANALYZER_TOKENIZE,
self.ANALYZER_PARTIAL, ...
:type analyzer: int
:param create_allowed: create the database, if necessary; default: True
:type create_allowed: bool
"""
jvm = PyLucene.getVMEnv()
jvm.attachCurrentThread()
super(PyLuceneDatabase, self).__init__(basedir, analyzer=analyzer, create_allowed=create_allowed)
self.pyl_analyzer = PyLucene.StandardAnalyzer()
self.writer = None
self.reader = None
self.index_version = None
try:
# try to open an existing database
tempreader = PyLucene.IndexReader.open(self.location)
tempreader.close()
except PyLucene.JavaError, err_msg:
# Write an error out, in case this is a real problem instead of an absence of an index
# TODO: turn the following two lines into debug output
# errorstr = str(e).strip() + "\n" + self.errorhandler.traceback_str()
# DEBUG_FOO("could not open index, so going to create: " + errorstr)
# Create the index, so we can open cached readers on it
if not create_allowed:
raise OSError("Indexer: skipping database creation")
try:
# create the parent directory if it does not exist
parent_path = os.path.dirname(self.location)
if not os.path.isdir(parent_path):
# recursively create all directories up to parent_path
os.makedirs(parent_path)
except IOError, err_msg:
raise OSError(
"Indexer: failed to create the parent "
+ "directory (%s) of the indexing database: %s" % (parent_path, err_msg)
)
示例4: make_query
# 需要导入模块: import PyLucene [as 别名]
# 或者: from PyLucene import getVMEnv [as 别名]
def make_query(self, *args, **kwargs):
jvm = PyLucene.getVMEnv()
jvm.attachCurrentThread()
return super(PyLuceneDatabase, self).make_query(*args, **kwargs)
示例5: __init__
# 需要导入模块: import PyLucene [as 别名]
# 或者: from PyLucene import getVMEnv [as 别名]
def __init__(self, basedir, analyzer=None, create_allowed=True):
"""Initialize or open an indexing database.
Any derived class must override __init__.
:raise ValueError: The given location exists, but the database type
is incompatible (e.g. created by a different indexing engine)
:raise OSError: the database failed to initialize
:param basedir: The parent directory of the database
:type basedir: str
:param analyzer: Bitwise combination of possible analyzer flags
to be used as the default analyzer for this database.
Leave it empty to use the system default analyzer
(self.ANALYZER_DEFAULT). See self.ANALYZER_TOKENIZE,
self.ANALYZER_PARTIAL, ...
:type analyzer: int
:param create_allowed: create the database, if necessary; default: True
:type create_allowed: bool
"""
jvm = PyLucene.getVMEnv()
jvm.attachCurrentThread()
super(PyLuceneDatabase, self).__init__(
basedir, analyzer=analyzer, create_allowed=create_allowed)
self.pyl_analyzer = PyLucene.StandardAnalyzer()
self.writer = None
self.reader = None
self.index_version = None
try:
# try to open an existing database
tempreader = PyLucene.IndexReader.open(self.location)
tempreader.close()
except PyLucene.JavaError as err_msg:
# Write an error out, in case this is a real problem instead of an absence of an index
# TODO: turn the following two lines into debug output
#errorstr = str(e).strip() + "\n" + self.errorhandler.traceback_str()
#DEBUG_FOO("could not open index, so going to create: " + errorstr)
# Create the index, so we can open cached readers on it
if not create_allowed:
raise OSError("Indexer: skipping database creation")
try:
# create the parent directory if it does not exist
parent_path = os.path.dirname(self.location)
if not os.path.isdir(parent_path):
# recursively create all directories up to parent_path
os.makedirs(parent_path)
except IOError as err_msg:
raise OSError("Indexer: failed to create the parent "
"directory (%s) of the indexing database: %s" %
(parent_path, err_msg))
try:
tempwriter = PyLucene.IndexWriter(
self.location, self.pyl_analyzer, True)
tempwriter.close()
except PyLucene.JavaError as err_msg:
raise OSError("Indexer: failed to open or create a Lucene"
" database (%s): %s" % (self.location, err_msg))
# the indexer is initialized - now we prepare the searcher
# windows file locking seems inconsistent, so we try 10 times
numtries = 0
#self.dir_lock.acquire(blocking=True)
# read "self.reader", "self.indexVersion" and "self.searcher"
try:
while numtries < 10:
try:
self.reader = PyLucene.IndexReader.open(self.location)
self.indexVersion = self.reader.getCurrentVersion(
self.location)
self.searcher = PyLucene.IndexSearcher(self.reader)
break
except PyLucene.JavaError as e:
# store error message for possible later re-raise (below)
lock_error_msg = e
time.sleep(0.01)
numtries += 1
else:
# locking failed for 10 times
raise OSError("Indexer: failed to lock index database"
" (%s)" % lock_error_msg)
finally:
pass
# self.dir_lock.release()
# initialize the searcher and the reader
self._index_refresh()