2017-02-13 80 views
1
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错误,甚至当我尝试过其他的东西像目录= SimpleFSDirectory(文件(os.path.abspath则( “路径”)))SimpleFSDirectory不是蟒蛇Lucene的工作

InvalidArgsError :( '初始化',(,))

回答

0

作为5.0时,SimpleFSDirectory构造函数不再需要File说法,它需要一个Path。你可以转换成路径,File.toPath()

此外,我建议您使用FSDirectory.open,而不是。 FSDirectory.open允许lucene尝试为当前环境选择最佳的目录实现,这通常比SimpleFS目录执行得更好。

所以,像这样:

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