solr的使用,
solr实现索引的增加,删除,更新操作
@Test
public void addDocumentTest() throws Exception{
//创建一个SOlrServer对象(抽象类),使用其实现类HttpSolrServer
//指定solr服务的地址
String url = "http://192.168.254.128:8080/solr/collection1";
SolrServer solrServer = new HttpSolrServer(url);
//创建一个文档对象SolrInputDucument
SolrInputDocument document = new SolrInputDocument();
//添加字段
document.addField("id", "121");
document.addField("item_title", "电脑");
document.addField("item_price", 1000);
//把文档对象写入索引库
solrServer.add(document);
//提交
solrServer.commit();
}
@Test
public void deleteById() throws Exception {
String url = "http://192.168.254.128:8080/solr/collection1";
SolrServer solrServer = new HttpSolrServer(url);
solrServer.deleteById("test01");
solrServer.commit();
}
@Test
public void deleteByQuery() throws Exception {
String url = "http://192.168.254.128:8080/solr/collection1";
SolrServer solrServer = new HttpSolrServer(url);
solrServer.deleteByQuery("item_title:手机");
solrServer.commit();
}
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。