2017-02-13 32 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)