作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我必须用 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 .
在我的项目中,我刚刚做到了。
关于java - 如何从 Solr 获取整个数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41740815/
我是一名优秀的程序员,十分优秀!