solr5.5版本使用solrJ

1,首先导入solrJ所需jar包,如下图所示:


2,使用IntelliJ创建Web工程,把上面jar放入lib中,并引用


3,打开Solr服务器管理界面


4,编写代码,进行solr查询

public class SolrJTest {
    public static void main(String[] args) throws Exception {
        String URL="http://localhost:8080/solr/mycore";
        HttpSolrClient solr = new HttpSolrClient(URL);
        Map<String, String> map = new HashMap<String, String>();
        map.put("q", "*:*");
        SolrParams params = new MapSolrParams(map);
        QueryResponse resp = solr.query(params);
        SolrDocumentList docsList = resp.getResults();
        for (SolrDocument doc : docsList) {
            System.out.println(doc.get("ajdz"));
        }
        solr.close();

    }
}

5,调用成功,结束

参考博客地址:https://blog.csdn.net/pizi995/article/details/54405939

猜你喜欢

转载自blog.csdn.net/u013517229/article/details/80053204
今日推荐