solr查詢返回JSON格式
SolrDocumentList docs = response.getResults();
1、JSONObject返回類似{"SolrDocument":{“1”:{},“2”:{}}
Map<Integer,Object> mapDoc = new HashMap<Iteger, Object>();
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