응답을 HttpSolrServer
에서 json 형식으로 변환하려고하는 검색 작업을하고 있습니다. 응답은 SolrDocumentList
입니다. 내가 지금 가지고있는 코드는 다음과 같습니다 자신의 예제 데이터를 사용하여 canon
에 검색solr 응답 (solrdocumentlist)을 json (또는 xml)으로 변환
{numFound=2,start=0,docs=[SolrDocument{cat=[electronics, camera], features=[3x zoop, 7.1 megapixel Digital ELPH, movie clips up to 640x480 @30 fps, 2.0" TFT LCD, 118,000 pixels, built in flash, red-eye reduction], id=9885A004, inStock=true, includes=32MB SD card, USB cable, AV cable, battery, manu=Canon Inc., manufacturedate_dt=Mon Feb 13 10:26:37 EST 2006, name=Canon PowerShot SD500, popularity=7, price=329.95, store=45.17614,-93.87341, weight=6.4}, SolrDocument{cat=[electronics, multifunction printer, printer, scanner, copier], features=[Multifunction ink-jet color photo printer, Flatbed scanner, optical scan resolution of 1,200 x 2,400 dpi, 2.5" color LCD preview screen, Duplex Copying, Printing speed up to 29ppm black, 19ppm color, Hi-Speed USB, memory card: CompactFlash, Micro Drive, SmartMedia, Memory Stick, Memory Stick Pro, SD Card, and MultiMediaCard], id=0579B002, inStock=true, manu=Canon Inc., name=Canon PIXMA MP500 All-In-One Photo Printer, popularity=6, price=179.99, store=45.17614,-93.87341, weight=352.0}]}}
:
SolrQuery solrQuery = new SolrQuery(query);
solrQuery.setParam("wt", "json"); //doesn't affect the return format
QueryResponse rsp = solrServer.query(solrQuery);
SolrDocumentList docs = rsp.getResults();
return docs.toString();
내가 반환을 인쇄 할 때, 그것은 다시로 제공됩니다. 내가 대신 return rsp.toString();
을 할 경우
나는대로와 헤더 정보를 다시 얻을 :
{responseHeader={status=0,QTime=1,params={indent=true,q=canon\*,wt=xml,version=2.2}},response={numFound=2,start=0,docs=[SolrDocument{cat=[electronics, camera], features=[3x zoop, 7.1 megapixel Digital ELPH, movie clips up to 640x480 @30 fps, 2.0" TFT LCD, 118,000 pixels, built in flash, red-eye reduction], id=9885A004, inStock=true, includes=32MB SD card, USB cable, AV cable, battery, manu=Canon Inc., manufacturedate_dt=Mon Feb 13 10:26:37 EST 2006, name=Canon PowerShot SD500, popularity=7, price=329.95, store=45.17614,-93.87341, weight=6.4}, SolrDocument{cat=[electronics, multifunction printer, printer, scanner, copier], features=[Multifunction ink-jet color photo printer, Flatbed scanner, optical scan resolution of 1,200 x 2,400 dpi, 2.5" color LCD preview screen, Duplex Copying, Printing speed up to 29ppm black, 19ppm color, Hi-Speed USB, memory card: CompactFlash, Micro Drive, SmartMedia, Memory Stick, Memory Stick Pro, SD Card, and MultiMediaCard], id=0579B002, inStock=true, manu=Canon Inc., name=Canon PIXMA MP500 All-In-One Photo Printer, popularity=6, price=179.99, store=45.17614,-93.87341, weight=352.0}]}}
내가 HttpSolrServer
로 응답 형식은 현재 (I XML로 설정) XML 또는 javabin이 될 수 있다는 사실을 알고 . 이것은 실제 결과와 형식에 영향을주지 않는 것으로 보입니다.
응답을 json으로 변환하는 방법을 찾지 못했습니다. 어떤 아이디어?
자세히 알려주십시오. 나는 이것이 갈 길이라고 생각하지 않는다. –