当前位置: 首页>>代码示例>>Python>>正文


Python PyLucene.getVMEnv方法代码示例

本文整理汇总了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()
开发者ID:jagg81,项目名称:translate-toolkit,代码行数:13,代码来源:PyLuceneIndexer.py

示例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
开发者ID:jagg81,项目名称:translate-toolkit,代码行数:13,代码来源:PyLuceneIndexer.py

示例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)
                )
开发者ID:ChrisOelmueller,项目名称:translate,代码行数:52,代码来源:PyLuceneIndexer.py

示例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)
开发者ID:jagg81,项目名称:translate-toolkit,代码行数:6,代码来源:PyLuceneIndexer.py

示例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()
开发者ID:XLeonardo,项目名称:translate-1,代码行数:86,代码来源:PyLuceneIndexer.py


注:本文中的PyLucene.getVMEnv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。