How to read data from solr/data/index

时光怂恿深爱的人放手 提交于 2019-12-12 08:59:07

问题


How to read data from solr/data/index by some simple console Java application? I found some solution.

But maybe there is more simple way. Help please with that, I really don't know what to do.


回答1:


It's my own solution. I get index files from solr 4.4 and I also use lucene-core-4.4.0.jar library. 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();
        }
   }



回答2:


There is a project called Luke which is a GUI for users to inspect Lucene indices.

Here is a blog post with more detail.



来源:https://stackoverflow.com/questions/17849946/how-to-read-data-from-solr-data-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!