use of org.apache.solr.client.solrj.impl.HttpSolrServer in project e3mall by colg-cloud.
the class TestSolr method queryIndex.
/**
* 查询索引库 - 简单
*/
@Test
public void queryIndex() throws SolrServerException {
// 创建一个SolrServer对象
SolrServer solrServer = new HttpSolrServer(BASE_URL);
// 创建一个SolrQuery对象
SolrQuery query = new SolrQuery();
// 设置查询条件
query.setQuery("*:*");
// 执行查询QueryResponse对象
QueryResponse queryResponse = solrServer.query(query);
// 取文档列表,取查询结果的总记录数
SolrDocumentList solrDocumentList = queryResponse.getResults();
System.out.println("查询结果总记录数:" + solrDocumentList.getNumFound());
System.out.println("当前记录数:" + solrDocumentList.size());
// 遍历文档列表,取域的内容
/*
for (SolrDocument doc : solrDocumentList) {
doc.get("id");
doc.get("item_title");
doc.get("item_title");
doc.get("item_sell_point");
doc.get("item_price");
doc.get("item_image");
doc.get("item_category_name");
}
*/
System.out.println(JSON.toJSONString(solrDocumentList));
}
use of org.apache.solr.client.solrj.impl.HttpSolrServer in project e3mall by colg-cloud.
the class TestSolr method deleteDocument.
/**
* 删除文档
*/
@Test
public void deleteDocument() throws SolrServerException, IOException {
SolrServer solrServer = new HttpSolrServer(BASE_URL);
// 根据id删除
// solrServer.deleteById("doc01");
// 根据查询删除
solrServer.deleteByQuery("id:doc01");
solrServer.commit();
}
use of org.apache.solr.client.solrj.impl.HttpSolrServer in project e3mall by colg-cloud.
the class TestSolr method queryIndexFuza.
/**
* 查询索引库 - 复杂
* @throws SolrServerException
*/
@Test
public void queryIndexFuza() throws SolrServerException {
SolrServer solrServer = new HttpSolrServer(BASE_URL);
SolrQuery query = new SolrQuery();
// 查询条件
query.setStart(0).setRows(10).setQuery("手机");
// 默认搜索域
query.set("df", "item_title");
// 高亮显示
query.setHighlight(true);
// 高亮显示字段
query.addHighlightField("item_title");
// 高亮显示标签
query.setHighlightSimplePre("<em>").setHighlightSimplePost("</em>");
// 执行查询
QueryResponse queryResponse = solrServer.query(query);
SolrDocumentList solrDocumentList = queryResponse.getResults();
System.out.println(JSON.toJSONString(solrDocumentList));
// 高亮结果
Map<String, Map<String, List<String>>> map = queryResponse.getHighlighting();
System.out.println(JSON.toJSON(map));
}
Aggregations