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


發佈了86 篇原創文章 · 獲贊 23 · 訪問量 25萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章