一、环境
二、添加依赖
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>4.10.1</version>
</dependency>
三、测试
public class SolrJTest {
@Test
public void addDocument() throws Exception {
SolrServer solrServer = new HttpSolrServer("http://127.0.0.1:8080/solr");
SolrInputDocument document = new SolrInputDocument();
document.addField("id", "10001");
document.addField("title", "测试");
solrServer.add(document);
solrServer.commit();
}
@Test
public void deleteDocument() throws Exception {
SolrServer solrServer = new HttpSolrServer("http://127.0.0.1:8080/solr");
solrServer.deleteByQuery("*:*");
solrServer.commit();
}
}