【问题标题】:Lucene in java method not found [duplicate]找不到Java方法中的Lucene [重复]
【发布时间】:2016-04-11 07:37:23
【问题描述】:

我正在使用下面的代码进行搜索,但某些方法显示错误;

FSDirectory.open(new File(indexDirectoryPath));
  writer = new IndexWriter(indexDirectory, 
     new StandardAnalyzer(),true,
     IndexWriter.MaxFieldLength.UNLIMITED);

在此代码中打开并且 MaxFieldLength 显示错误。我正在使用 lucene 6.0.0。

open() 方法显示错误

FSDirectory 类型中的方法 open(Path) 不适用于 参数(文件)

和 MaxFieldLength 显示:

MaxFieldLength 无法解析或不是字段

我使用了这里提供的代码:

http://www.tutorialspoint.com/lucene/lucene_first_application.htm

【问题讨论】:

  • 您可以查看 javadoc 了解不同版本的 Lucene 并找出我猜的问题。

标签: java lucene


【解决方案1】:

可能代码是针对旧版本的 lucene 编写的。 较新的版本已从旧的 java io 切换到 java nio。 所以你会使用这样的东西:FSDirectory.open(FileSystems.getDefault().getPath("yourPath", "index")

在 6.0 版中,IndexWriter 没有名为 MaxFieldLength 的成员,请参阅 Lucene IndexWriter API

更多帮助可以在migration guide找到

您可能也不想查找旧版本的迁移指南。

【讨论】:

    【解决方案2】:

    如果您查看 Lucene 文档中 [FSDirectory.open][1] 方法的文档,您会发现它除了 Path 参数。您可以使用 Paths.get(URI) 方法从 URI 中获取路径。路径是 Java 7 的一部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-13
      • 2014-11-10
      • 2017-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多