【问题标题】:How to read a Lucene index?如何读取 Lucene 索引?
【发布时间】:2011-01-21 01:49:46
【问题描述】:

我正在做一个项目,我想通过读取 Lucene 索引并对其进行修剪来构建标签云。我没有设置Lucene引擎,是团队中的其他人,现在我只想阅读它的索引。你是如何用 Java 做到这一点的?

【问题讨论】:

    标签: java lucene indexing


    【解决方案1】:

    不确定“阅读”索引是什么意思:

    1. 如果要查询,可以使用 IndexSearcher 类。

    2. IndexReader 允许您以读取模式打开索引。

    如果要查看索引的内容,可以使用Luke

    【讨论】:

    • 谢谢!卢克似乎是我正在寻找的解决方案!
    • 顺便说一句,您可以像这样初始化IndexSearchIndexSearcher indexSearcher = new IndexSearcher(DirectoryReader.open(FSDirectory.open(new File(pathToIndex)))); IndexSearcher 也有一个接受ExecutorService 的构造函数,您应该查看用于并行搜索不同段的构造函数。
    【解决方案2】:

    你这样做 -

    IndexReader r = IndexReader.open( "prdb_index");
    
    int num = r.numDocs();
    for ( int i = 0; i < num; i++)
    {
        if ( ! r.isDeleted( i))
        {
            Document d = r.document( i);
            System.out.println( "d=" +d);
        }
    }
    r.close();
    

    【讨论】:

      【解决方案3】:

      您需要寻找的是如何使用 IndexReader 类,.terms() 方法将返回索引中的所有术语。

      【讨论】:

      • 这看起来更好!如果索引位于 WEB-INF/index 文件夹中,您是否有机会知道如何访问该索引?我使用 OpenCMS,这是默认位置。
      • 来自 API 文档。 IndexReader 的具体子类通常通过调用静态 open() 方法之一来构建,例如打开(字符串)。
      【解决方案4】:

      这样做:

      File indexDirectory = new File("YourIndexLocation");
      IndexReader reader = IndexReader.open(FSDirectory.open(indexDirectory));
      return reader.maxDoc(); //return total docs in index
      

      【讨论】:

        猜你喜欢
        • 2018-07-25
        • 2014-08-27
        • 2014-07-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-15
        • 1970-01-01
        相关资源
        最近更新 更多