Solr数据导入之SolrInputDocument导入数据

public static void main(String[] args) throws Exception {

String zkHost = "192.168.137.200:2181,192.168.137.201:2181";

CloudSolrClient server = new CloudSolrClient(zkHost);

server.setDefaultCollection("mycollection");

addDocs(server);

query(server);

        server.close();

}

public static void addDocs(CloudSolrClient server) throws Exception{

SolrInputDocument doc1 = new SolrInputDocument();


doc1.addField("id", "00003");

doc1.addField("content", "id测试");

SolrInputDocument doc2 = new SolrInputDocument();

doc2.addField("id", "00004");

doc2.addField("content", "id测试2");

Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();

docs.add(doc1);

docs.add(doc2);

server.add(docs);

server.commit();

}

public static void query(CloudSolrClient server) throws Exception{

SolrQuery parameters = new SolrQuery();

        parameters.set("q", "*:*");

        parameters.set("qt", "/select");        

        parameters.set("collection", "mycollection");

        QueryResponse response = server.query(parameters);

        //SolrDocumentList list = response.getResults();

        System.out.println(response);  

}











本文转自 yntmdr 51CTO博客,原文链接:http://blog.51cto.com/yntmdr/1731479,如需转载请自行联系原作者
上一篇:P2P 应用程序框架


下一篇:如何设定应用程序安装到特定手机中