2017-03-27 6 views
1

したがって、私はPyLuceneで基本的なインデックスライターを実装しようとしています。私は通常、Java開発者ですが、技術的な制約のために私はこれをPythonでやっています。そうしなければ、問題にはならないでしょう。私は、Javaコードhere、それをチェックしたPyLuceneのInvalidArgsErrorはFSDirectoryを作成しようとしています

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>,)) 

:私は、私が午前問題は、私はこれを実行するたびに、私は次のエラーを取得することである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()) 

ています表示されるのはコンストラクタpublic SimpleFSDirectory(File path)であり、それはトレースバックエラーでも渡しているようです。 jccのうち何かが欠けていますか?

これはLucene 6.4.1を使用しており、luceneとjccを正常にインポートできます。

答えて

0

だから、ドキュメントのいくつかは、(私はLuceneの6.4.1に基づいてPyLuceneを使用しています)より新しいバージョンでは、この

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

を持ってSimpleFSDirectoryは、代わりにFilePathは(そのようなJavaを使用しての喜びです期待していPythonでライブラリー:。

path = Paths.get('index') 
self.index_directory = SimpleFSDirectory(path) 
:パイソンの型の安全性を持つJavaの簡潔)上記で私も実現しなかったが、私は attachCurrentThread

修正したコードに持っていました

+0

'Paths'をインポートするには? –

+1

Java 8ライブラリパスパッケージを使用することができます –

関連する問題