我必须用Java编写一些逻辑,该逻辑应该从Solr检索所有索引数据。
截至目前,我正在这样做
String confSolrUrl = "http://localhost/solr/master/select?q=*%3A*&wt=json&indent=true"
LOG.info(confSolrUrl);
url = new URL(confSolrUrl);
URLConnection conn = url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
//save to this filename
String fileName = "/qwertyuiop.html";
File file = new File(fileName);
if (!file.exists())
{
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
while ((inputLine = br.readLine()) != null) {
bw.write(inputLine);
}
bw.close();
br.close();
System.out.println("Done");
在我的文件中,我将获得HTML
可以解析并提取文件的整个文件JSON
。
有什么更好的方法吗?而不是从url获取资源并解析它?
我刚刚编写了一个应用程序来执行此操作,请看一下github:https : //github.com/freedev/solr-import-export-json
如果要从solr集合中读取所有数据,那么您面临的第一个问题就是分页,在这种情况下,我们正在谈论深度分页。
像您这样的直接http请求将返回相对较少的文档。Solr集合中甚至可以包含数百万或数十亿个文档。因此,您应该使用正确的API,即Solrj。
在我的项目中,我只是做到了。
我也建议阅读以下内容:https : //lucidworks.com/blog/2013/12/12/coming-soon-to-solr-efficiency-cursor-based-iteration-of-large-result-sets/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句