首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >InvalidArgsError in PyLucene试图创建FSDirectory

InvalidArgsError in PyLucene试图创建FSDirectory
EN

Stack Overflow用户
提问于 2017-03-27 23:29:34
回答 1查看 859关注 0票数 1

因此,我试图在PyLucene中实现一个基本的索引编写器。我通常是一个java,但是由于技术上的限制,我在python中这样做,否则就不会有问题了。我正在遵循PyLucene Tarball中的示例,但是

代码语言:javascript
复制
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())

我遇到的问题是,每当我运行这个程序时,我都会得到以下错误:

代码语言:javascript
复制
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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-29 14:05:28

所以有些文档中有

代码语言:javascript
复制
fl = File('index')
indexDir = SimpleFSDirectory(fl)

在较新的版本(我使用的是基于Lucene6.4.1的PyLucene )中,SimpleFSDirectory期望使用Path而不是File (这是在python中使用java库的乐趣: java与python类型安全的简洁性)。在上面,我也没有意识到我必须要attachCurrentThread

修正代码:

代码语言:javascript
复制
path = Paths.get('index')
self.index_directory = SimpleFSDirectory(path)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43058131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档