欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

solrCloud源码分析之CloudSolrClient 博客分类: solr  

程序员文章站 2024-03-18 19:28:46
...
CloudSolrClient是solrj提供的客户端与solrCloud交互的类。该类的实例与zookeeper进行通信来确定solrCloud collections中的solr endpoint,然后使用LBHttpSolrClient发送请求。

CloudSolrClient查询简单代码:

import java.io.IOException;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;

public class SolrJCloudClientSearch {

    public static void main(String[] args) throws SolrServerException, IOException {
        String zkHost = "127.0.0.1:9983";
        CloudSolrClient server = new CloudSolrClient(zkHost);
        //server = new CloudSolrClient(zkHost);
        server.setParser(new XMLResponseParser());
        SolrQuery parameters = new SolrQuery();
        parameters.set("q", "*:*");
        parameters.set("qt", "/select");        
        parameters.set("collection", "Test");
        QueryResponse response = server.query(parameters);
        SolrDocumentList list = response.getResults();
        System.out.println(list.size());    
    }
}



http://www.cnblogs.com/davidwang456/p/4971298.html