2017-03-27 1 views
1

그래서 PyLucene에 기본 색인 작성기를 구현하려고합니다. 나는 보통 자바 개발자이지만 기술적인 제약으로 인해 파이썬에서 이렇게하고있다. 그렇지 않으면 문제가되지 않을 것이다. 나는하여 PyLucene 타르볼 샘플 만 따라하고PyLucene의 InvalidArgsError가 FSDirectory를 만들려고합니다

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

오전 데 문제는이를 실행할 때마다 나는 다음과 같은 오류 얻을 것이다 : 나는 자바 코드 here 그것을 확인했다

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를 성공적으로 가져올 수 있습니다.

답변

0

그래서 문서의 일부가 최신 버전이

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

(나는 루씬 6.4.1을 기반으로 PyLucene을 사용하고 있습니다) SimpleFSDirectory가 대신 자바를 사용하는 File (이러한있는 기쁨의 Path을 기대하고있다 파이썬 라이브러리 :.

path = Paths.get('index') 
self.index_directory = SimpleFSDirectory(path) 
: 파이썬의 유형 안전과 자바의 간결함) 위에서 나는 또한 몰랐어요 나는 attachCurrentThread

수정 코드에 있었다

+0

'경로 '를 가져 오는 방법은 무엇입니까? –

+1

Java 8 라이브러리 경로 패키지 만 사용할 수 있습니다. –

관련 문제