问题
I am using those code below for searching but some methods shows error;
FSDirectory.open(new File(indexDirectoryPath));
writer = new IndexWriter(indexDirectory,
new StandardAnalyzer(),true,
IndexWriter.MaxFieldLength.UNLIMITED);
In this code open and MaxFieldLength shows error. I am using lucene 6.0.0.
The open() method shows the error
The method open(Path) in the type FSDirectory is not applicable for the arguments (File)
and MaxFieldLength shows:
MaxFieldLength cannot be resolved or is not a field
I used the code provided here:
http://www.tutorialspoint.com/lucene/lucene_first_application.htm
回答1:
Probably the code is written against an older version of lucene.
Newer versions have switched form the old java io to the java nio.
So you would use something like this:FSDirectory.open(FileSystems.getDefault().getPath("yourPath", "index")
In version 6.0 the IndexWriter hasn't got a member called MaxFieldLength Please see Lucene IndexWriter API.
More help can be found in the migration guide
You may wan't to look up older versions of the migration guides as well.
回答2:
If you check the documentation of the [FSDirectory.open][1] method in the Lucene documentation you will find that it except Path argument. You can Paths.get(URI) method to get Paths from the URI. Paths are part of the Java 7.
来源:https://stackoverflow.com/questions/36542551/lucene-in-java-method-not-found