欢迎投稿

今日深度:

solr的使用,

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();
    }

www.htsjk.Com true http://www.htsjk.com/solr/37484.html NewsArticle solr的使用, solr实现索引的增加,删除,更新操作 @Test public void addDocumentTest () throws Exception{ //创建一个SOlrServer对象(抽象类),使用其实现类HttpSolrServer //指定solr服务的地址 String url = "http:...
相关文章
    暂无相关文章
评论暂时关闭