gpt4 book ai didi

java - PyLucene 尝试创建 FSDirectory 时出现 InvalidArgsError

转载 作者:行者123 更新时间:2023-11-30 06:49:46 24 4
gpt4 key购买 nike

所以我试图在 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>,))

我检查了Java代码here似乎有一个构造函数 public SimpleFSDirectory(File path) ,看起来这就是我在回溯错误中传递的内容。我是否遗漏了 jcc 中的某些内容?

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

最佳答案

所以一些文档有这个

fl = File('index')
indexDir = SimpleFSDirectory(fl)

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

更正的代码:

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

关于java - PyLucene 尝试创建 FSDirectory 时出现 InvalidArgsError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43058131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com