简体   繁体   English

如何从solr / data / index读取数据

[英]How to read data from solr/data/index

How to read data from solr/data/index by some simple console Java application? 如何通过一些简单的控制台Java应用程序从solr/data/index读取数据? I found some solution . 我找到了一些解决方案

But maybe there is more simple way. 但也许有更简单的方法。 Help please with that, I really don't know what to do. 请帮忙,我真的不知道该怎么办。

It's my own solution. 这是我自己的解决方案。 I get index files from solr 4.4 and I also use lucene-core-4.4.0.jar library. 我从solr 4.4获得index文件,我也使用lucene-core-4.4.0.jar库。 Maybe it can help someone. 也许它可以帮助某人。

    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;

    import org.apache.lucene.document.Document;
    import org.apache.lucene.index.IndexReader;
    import org.apache.lucene.queryparser.classic.ParseException;
    import org.apache.lucene.store.Directory;
    import org.apache.lucene.store.FSDirectory;
    import org.apache.solr.client.solrj.SolrServerException;

    public class SomeClass {

        public static void main(String[] args) throws IOException {


            Directory dirIndex = FSDirectory.open(new File("solr/home/data/index"));
            IndexReader indexReader = IndexReader.open(dirIndex);
            Document doc = null;   

            for(int i = 0; i < indexReader.numDocs(); i++) {
                doc = indexReader.document(i);
            }

            System.out.println(doc.toString());

            indexReader.close();
            dirIndex.close();
        }
   }

There is a project called Luke which is a GUI for users to inspect Lucene indices. 有一个名为Luke的项目,它是用户检查Lucene索引的GUI。

Here is a blog post with more detail. 是一篇更详细的博客文章。 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM