如何从Solr/Data/Index读取数据 [英] How to read data from solr/data/index
本文介绍了如何从Solr/Data/Index读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过一些简单的控制台Java应用程序从solr/data/index
读取数据?我找到了一些解决方案.
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.
推荐答案
这是我自己的解决方案.我从solr 4.4获取index
文件,并且我还使用lucene-core-4.4.0.jar库.也许可以帮助某人.
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();
}
}
这篇关于如何从Solr/Data/Index读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文