solr

1:solr是什么?

说白了底层就是lucene

--------------------------------------------------

2:入门级小案列

public class IndexWriterTest {

    /**
     * 添加索引库的操作
     */
    @Test
    public void indexWriterTest01() throws IOException, SolrServerException {
        //1. 创建一个solr的连接对象 solrServer
        /**
         * 注意:浏览器的url:http://localhost:8080/solr/#/collection1
         * java代码里面去掉井号
         */
        String baseURL = "http://localhost:8080/solr/collection1";
        HttpSolrServer httpSolrServer = new HttpSolrServer(baseURL);

        //2. 创建document对象
        SolrInputDocument doc = new SolrInputDocument();
        /**
         * field字段的名称必须在schema.xml文件中配置过,才能使用
         */
        doc.addField("id","5");
        doc.addField("title","王祖蓝陪产部分画面曝光,为李亚男整理头发画面超有爱");
        doc.addField("content","王祖蓝录制完节目马上赶回香港去陪产 路上回忆和老婆的点点滴滴");
        doc.addField("editor","吃瓜群众");
        //3. 添加索引
        httpSolrServer.add(doc);
        //4. 提交
        httpSolrServer.commit();
        //5. 关闭资源
        httpSolrServer.shutdown();
    }
}
原文地址:https://www.cnblogs.com/xlhlx/p/10743665.html