Lucene using FSDirectory

2019-01-12 10:38发布

I tried to create a simple Lucene program to create index, But I am having trouble why my syntax iswrong.

My code:

static final String INDEX_DIRECTORY = "/home/yuqing/Desktop/index";
Directory index = FSDirectory.open(new File(INDEX_DIRECTORY));

I get an error from IDE saying

open (java.nio.file.path) in FSDirectory cannot be applied to java.io.file

标签: lucene
2条回答
贪生不怕死
2楼-- · 2019-01-12 10:45

The FSDirectory.open call takes a Path argument, not a File (as of Lucene version 5.0). You can check out the Java tutorial on the Path Class for information on how it works.

So, your code should look like:

static final String INDEX_DIRECTORY = "/home/yuqing/Desktop/index";
Directory index = FSDirectory.open(Paths.get(INDEX_DIRECTORY));
查看更多
我命由我不由天
3楼-- · 2019-01-12 10:49

You should use .toPath() for the path to files.

File f=new File(INDEX_DIRECTORY);
Directory index = FSDirectory.open(f.toPath());
查看更多
登录 后发表回答