Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java PyLucene中的InvalidArgsError正在尝试创建目录_Java_Python_Lucene_Jcc - Fatal编程技术网

Java PyLucene中的InvalidArgsError正在尝试创建目录

Java PyLucene中的InvalidArgsError正在尝试创建目录,java,python,lucene,jcc,Java,Python,Lucene,Jcc,所以我试图在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 impor

所以我试图在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>,))
回溯(最近一次呼叫最后一次):
文件“Indexer.py”,第40行,在
索引器=索引器()
文件“Indexer.py”,第22行,在_init中__
indexDir=SimpleFSDirectory(fl)
lucene.InvalidArgsError:(,'_uinit_uuu',(,)
我检查了Java代码,它似乎有一个构造函数
public SimpleFSDirectory(File path)
,即使在回溯错误中,它看起来也是我要传递的。我是否在
jcc
中遗漏了什么


这是使用Lucene 6.4.1,我可以成功导入Lucene和jcc

所以一些文档中有

fl = File('index')
indexDir = SimpleFSDirectory(fl)
在较新的版本中(我使用的是基于Lucene 6.4.1的PyLucene)
SimpleFSDirectory
需要一个
Path
而不是
文件
(这就是在python中使用java库的乐趣:java的简洁性和python的类型安全性。)在上面我也没有意识到我必须
attachCurrentThread

更正代码:

path = Paths.get('index')
self.index_directory = SimpleFSDirectory(path)

如何导入
路径
?您只需使用Java 8库路径包即可