solrJ

导入jar包

solrJ

solrJ

solrJ

solrJ

package com.tzy.solrJ;

import java.io.IOException;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

public class SolrJManager {

    @Test
    public void testAdd() throws SolrServerException, IOException{
        String baseURL = "http://localhost:8080/solr/";
        SolrServer solrServer = new HttpSolrServer(baseURL);
        SolrInputDocument doc = new SolrInputDocument();
        doc.setField("id", "lala");
        doc.setField("name", "张三");
        //添加
        solrServer.add(doc);
        solrServer.commit();
        
    }
}

solrJ

solrJ

 

@Test
    public void deleteDocumentByid() throws Exception {
        //创建连接
        SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr");
        //根据id删除文档
        solrServer.deleteById("lala");
        //删除全部
        //solrServer.deleteByQuery("*:*", 1000);
        //提交修改
        solrServer.commit();
    }
删除方法

相关文章:

  • 2021-12-23
  • 2021-08-23
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
  • 2021-08-04
  • 2021-12-20
猜你喜欢
  • 2021-04-12
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
相关资源
相似解决方案