SimpleFSDirectory无法在python lucene中工作

时间:2017-02-13 15:44:49

标签: python indexing lucene

import sys, os
import lucene

from java.io import File
from org.apache.lucene.analysis.standard import StandardAnalyzer
from org.apache.lucene.index import DirectoryReader
from org.apache.lucene.queryparser.classic import QueryParser
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


def index(start, no, dom): 
    lucene.initVM()
    # join base dir and index dir
    path = raw_input("Path for index: ")
    index_path = File(path)
    directory = SimpleFSDirectory(index_path) # the index

我一直在使用SimpleFSDirectory时遇到错误,即使我尝试了其他内容,例如directory = SimpleFSDirectory(File(os.path.abspath(“paths”)))

InvalidArgsError :(,' init ',(,))

1 个答案:

答案 0 :(得分:0)

从5.0开始,SimpleFSDirectory ctor不再采用File参数,需要Path。您可以使用File.toPath()转换为路径。

另外,我建议你使用FSDirectory.open。 FSDirectory.open允许lucene尝试为当前环境选择最佳的Directory实现,这通常比SimpleFSDirectory执行得更好。

所以,比如:

index_path = File(path).toPath()
directory = FSDirectory.open(index_path)