Lucene in java method not found [duplicate]

*爱你&永不变心* 提交于 2019-12-23 04:39:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!