如何检查 Lucene 文件夹数据包含的内容



你好,我正在研究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);
}

有没有工具可以下载它??

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

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

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

你可以使用 Luke,它将执行与上面的代码相同的操作,甚至更多。

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