一.
写一个测试用例:
向索引库添加文档(数据)
创建一个SolrServer对象。创建一个HttpSolrServer对象
需要指定solr服务的url
创建一个文档对象SolrInputDocument
向文档中添加域,必须有id域,域的名称必须在schema.xml中定义
把文档对象写入索引库
提交
@Test
public void testAddDocument() throws Exception {
//创建一个SolrServer对象。创建一个HttpSolrServer对象
//需要指定solr服务的url
SolrServer solrServer = new HttpSolrServer("http://192.168.0.128:8080/solr/collection1");
//创建一个文档对象SolrInputDocument
SolrInputDocument document = new SolrInputDocument();
//向文档中添加域,必须有id域,域的名称必须在schema.xml中定义
document.addField("id", "1234");
document.addField("item_title", "测试商品34");
document.addField("item_price", 1000);
//把文档对象写入索引库
solrServer.add(document);
//提交
solrServer.commit();