solrJ 基本使用

添加:

PropertiesUtils pro = new PropertiesUtils();
String path = pro.load("solr.properties", "solr.Url");
SolrServer solrServer = new HttpSolrServer(path);
SolrInputDocument document = new SolrInputDocument();
document.addField("uid", data.getId());
document.addField("title", data.getYhtitle());
document.addField("startTime", data.getStartdate());
document.addField("endTime", data.getEnddate());

UpdateResponse response = solrServer.add(document);
// 提交
solrServer.commit();

删除:

PropertiesUtils pro = new PropertiesUtils();
String path = pro.load("solr.properties", "solr.Url");
SolrServer solrServer = new HttpSolrServer(path);
if (ListUtils.isNotBlank(ids)) {
UpdateResponse d = solrServer.deleteById(ids);
UpdateResponse ds = solrServer.deleteByQuery("*");

}
if (StringUtils.isNotBlank(id)) {
UpdateResponse d = solrServer.deleteById(id);

}
solrServer.commit();

 

搜索:

 

 


搜索:

 

SolrQuery query=new SolrQuery();
//查询条件
query.set("q","par");

 

//分页
SolrDocumentList doc=query.getResults()//结果集 返回documentList对象
doc.getStart()//开始记录
doc.getNumFound()//总记录数

 

solrServer.query(query);

 

posted @ 2017-06-07 17:12  洞玄巅峰  阅读(196)  评论(0编辑  收藏  举报