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
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));
You should use .toPath() for the path to files.
File f=new File(INDEX_DIRECTORY);
Directory index = FSDirectory.open(f.toPath());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With