solr客戶端的使用


1:添加

 

 2查詢

  

 

 3:刪除:

  

 

刪除兩種方法:

1、根據id刪除:

<delete>

<id>test001</id>

</delete>

<commit/>

2、根據查詢刪除:

<delete>

<query>*:*</query>

</delete>

<commit/>

   二使用java代碼:實現功能

     

    @Test
    public void addDoc() throws SolrServerException, IOException{
        //創建一個連接
        //單機版
        SolrServer solrServer=new HttpSolrServer("http://192.168.100.91:8080/solr");
        //集群版
        //SolrServer solrServer2=new CloudSolrServer("");
        //創建一個文檔對象
        SolrInputDocument document=new SolrInputDocument();
        document.addField("id", "test001");
        document.addField("item_title", "測試商品");
        
        //把文檔寫入索引庫
        solrServer.add(document);
        //提交
        solrServer.commit();
    }
    @Test
    public void delDoc() throws SolrServerException, IOException{
        //創建一個連接
        SolrServer solrServer=new HttpSolrServer("http://192.168.100.91:8080/solr");
        solrServer.deleteById("test001");
        //提交
        solrServer.commit();
    }

     

  
  

 

 

 

 

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM