因此,我试图在PyLucene中实现一个基本的索引编写器。我通常是一个java,但是由于技术上的限制,我在python中这样做,否则就不会有问题了。我正在遵循PyLucene Tarball中的示例,但是
import lucene
from java.io import File
from org.apache.lucene.analysis.standard import StandardAnalyzer
from org.apache.lucene.document import Document, Field
from org.apache.lucene.index import IndexWriter, IndexWriterConfig
from org.apache.lucene.store import SimpleFSDirectory
from org.apache.lucene.util import Version
from org.apache.lucene.store import IOContext
lucene.initVM()
fl = File('index')
indexDir = SimpleFSDirectory(fl)
writerConfig = IndexWriterConfig(Version.LUCENE_6_4_1, StandardAnalyzer())我遇到的问题是,每当我运行这个程序时,我都会得到以下错误:
Traceback (most recent call last):
File "Indexer.py", line 40, in <module>
indexer = Indexer()
File "Indexer.py", line 22, in __init__
indexDir = SimpleFSDirectory(fl)
lucene.InvalidArgsError: (<type 'SimpleFSDirectory'>, '__init__', (<File: index>,))我已经检查了这里代码,它看起来有一个构造函数public SimpleFSDirectory(File path),即使在跟踪错误中也是这样传递的。我是不是错过了jcc的一些东西?
这是使用Lucene 6.4.1,我可以成功地导入lucene和jcc。
发布于 2017-03-29 14:05:28
所以有些文档中有
fl = File('index')
indexDir = SimpleFSDirectory(fl)在较新的版本(我使用的是基于Lucene6.4.1的PyLucene )中,SimpleFSDirectory期望使用Path而不是File (这是在python中使用java库的乐趣: java与python类型安全的简洁性)。在上面,我也没有意识到我必须要attachCurrentThread
修正代码:
path = Paths.get('index')
self.index_directory = SimpleFSDirectory(path)https://stackoverflow.com/questions/43058131
复制相似问题