@Test
public void queryTest() throws SolrServerException, IOException {
// 连接solr服务器
HttpSolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core2");
// 创建查询条件对象
SolrQuery params = new SolrQuery("*:*");
// 执行查询,获取响应数据
QueryResponse response = solrServer.query(params);
// 获取结果集数据
SolrDocumentList list = response.getResults();
// 处理结果集
System.out.println("一共获取了" + list.size()+"条结果:");
for (SolrDocument solrDocument : list) {
System.out.println("id: " + solrDocument.getFieldValue("id"));
System.out.println("title:" + solrDocument.getFieldValue("title"));
}
}
原文地址:https://blog.51cto.com/13587708/2415815
时间: 2024-10-11 16:06:57