【问题标题】:how to check that what lucene folder data contain?如何检查 lucene 文件夹数据包含哪些内容?
【发布时间】:2014-04-04 11:25:57
【问题描述】:

你好,我正在研究 java,我正在使用 lucene 进行索引。 我在那里存储数据,但如何检查 lucene 数据包含哪些内容?

我尝试用这个来检查 lucene 上的数据。 public static void main(String[] args) 抛出异常 {

    File indexDir = new File("/path/to/solr/data/index/");
    int hits = 100;

    SimpleSearcher searcher = new SimpleSearcher();
    searcher.searchIndex(indexDir, args[0], hits);
}

private void searchIndex(File indexDir, String queryStr, int maxHits)
        throws Exception {

    Directory directory = FSDirectory.open(indexDir);

    IndexSearcher searcher = new IndexSearcher(directory);
    QueryParser parser = new QueryParser(Version.LUCENE_35,
     "title", new SimpleAnalyzer());
    Query query = parser.parse(queryStr);

    TopDocs topDocs = searcher.search(query, maxHits);

    ScoreDoc[] hits = topDocs.scoreDocs;
    for (int i = 0; i < hits.length; i++) {
        int docId = hits[i].doc;
        Document d = searcher.doc(docId);
        List<Fieldable> fields = d.getFields();

        System.out.println( (i+1) + ". ==========================================================");
        for ( Fieldable field : fields ) {
           if (field.isStored()) {
             System.out.println(" >> " + field.name() + " - " + d.get(field.name()));
           }
        }
    }

    System.out.println("Found " + hits.length);
}

有什么工具可以下载吗?

【问题讨论】:

    标签: java lucene


    【解决方案1】:

    是的,你可以看到这个,你只需下载 lucene 客户端

    http://code.google.com/p/luke/downloads/detail?name=lukeall-3.4.0_1.jar&can=2&q

    只需将您的索引文件夹作为其索引目录的路径,您就可以在 UI 上看到它,您也可以使用它来添加、删除或更新。

    【讨论】:

      【解决方案2】:

      您可以使用Luke,它的作用与上面的代码相同,甚至更多。

      如果您使用的 Lucene 版本大于 4.0,则需要在其他地方下载 Luke。获取相关 fork 二进制文件的可能位置之一是:https://github.com/DmitryKey/luke/releases/tag/4.6.0

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-07
        • 1970-01-01
        • 2021-07-01
        相关资源
        最近更新 更多