solr查询返回JSON格式


SolrDocumentList docs = response.getResults();

1、JSONObject返回类似{"SolrDocument":{“1”:{},“2”:{}}

Map mapDoc = new HashMap();

int count = 1;

for(SolrDocument doc : docs){

mapDoc.put(count, doc);

count++;

}

JSONObject json = new JSONObject();

json.put("SolrDocument", mapDoc);

//json.put(mapDoc);输出{{“1”:{},“2”:{}}

String strResult = json.toString();

2、JSONArray返回格式:[{},{}]为json数组

JSONArray arrJson = new JSONArray();

for(SolrDocument doc :docs){

arrJson.add(doc);

}

String strResult = arrJson.toString(); 

3、JSONObject和JSONArray组合显示{"data":[{},{},{}]}

在2的基础上继续向下写:

JSONObject json = new JSONObject();

json.put("data",arrJson);

String strResult = json.toString();

4、query添加param

param中设置显示字段,添加到query时,没有作用,在query中添加显示字段,可以按要求显示字段


sorl创建索引字段和动态自动、创建索引、查询的相关参考资料:

http://codego.net/477246/

http://my.oschina.net/HuifengWang/blog/307501

http://www.importnew.com/12707.html

http://blog.csdn.net/kissmelove01/article/details/45196941

http://www.360doc.com/content/14/0306/18/203871_358295621.shtml

http://www.tuicool.com/articles/uAzQnaz

http://www.boyunjian.com/javadoc/org.apache.servicemix.bundles/org.apache.servicemix.bundles.solr-solrj/4.3.0_1/_/org/apache/solr/client/solrj/SolrQuery.html#setFields(java.lang.String...)

http://blog.csdn.net/itbasketplayer/article/details/8086160

http://www.blogjava.net/conans/articles/379556.html

http://zhidao.baidu.com/link?url=pAi93scWL7cEnD7K1MIpjR8FBRqn0hC8yY45tb9OdZJHzjEBC-8u7i8DcfOJKZRnQCPdO1-EhDwIiPLXENlDrSElKcXcgZ4qo-uVUkrQT4C

http://www.sxt.cn/u/2718/blog/4090

http://blog.sina.com.cn/s/blog_a61684c501019n5h.html

http://www.fx114.net/qa-202-108415.aspx

http://www.sxt.cn/info-5072-u-756.html


你可能感兴趣的:(大数据,HBase,json,java,solr,solr,json,索引)