Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lucene using FSDirectory

Tags:

java

lucene

I wrote a simple java program to create a lucene index, but I get an error with the syntax.

My code:

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

I get the following error,

open (java.nio.file.path) in FSDirectory cannot be applied to java.io.file
like image 660
user2628641 Avatar asked Mar 10 '16 19:03

user2628641


2 Answers

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));
like image 54
femtoRgon Avatar answered Nov 06 '22 02:11

femtoRgon


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

File f=new File(INDEX_DIRECTORY);
Directory index = FSDirectory.open(f.toPath());
like image 2
Cristian Iacob Avatar answered Nov 06 '22 01:11

Cristian Iacob