mysql - get json object from apache solr using java for autocomplete -
i did apache solr indexing (mysql) data, searching select , suggest, how json object dynamically apache solr while keyup characters, here given apache solr url , corresponding results
urllocalhost:8983/solr/collection1/select?q=hotelname%3a%22royal+orchid%22&wt=json&indent=true
output { "responseheader": { "status": 0, "qtime": 0, "params": { "indent": "true", "q": "hotelname:\"royal orchid\"", "_": "1403088370128", "wt": "json" } }, "response": { "numfound": 20, "start": 0, "docs": [ { "hotelname": [ "royal orchid metropole mysore" ], "cityname": "mysore", "id": "224433", "_version_": 1471227815192952800 }, { "hotelname": [ "royal orchid central bangalore" ], "cityname": "bengaluru (and vicinity)", "id": "240388", "_version_": 1471227815235944400 }, { "hotelname": [ "royal orchid central jaipur" ], "cityname": "jaipur", "id": "258200", "_version_": 1471227815290470400 }, { "hotelname": [ "royal orchid brindavan gardens" ], "cityname": "mysore", "id": "258917", "_version_": 1471227815293616000 }, { "hotelname": [ "royal orchid central pune" ], "cityname": "pune", "id": "267814", "_version_": 1471227815330316300 }, { "hotelname": [ "royal orchid suites" ], "cityname": "bengaluru (and vicinity)", "id": "309427", "_version_": 1471227815379599400 }, { "hotelname": [ "royal orchid central ahmedabad" ], "cityname": "ahmedabad", "id": "326301", "_version_": 1471227815444611000 }, { "hotelname": [ "royal orchid fort resort" ], "cityname": "mussoorie", "id": "327797", "_version_": 1471227815467679700 }, { "hotelname": [ "royal orchid resort pattaya" ], "cityname": "pattaya", "id": "344270", "_version_": 1471227815546323000 }, { "hotelname": [ "royal orchid central grazia" ], "cityname": "navi mumbai", "id": "350799", "_version_": 1471227815558905900 } ] } }
is possible phone call apache solr url jquery autocomplete or shall write restful client json data, pls help me out.
yes, if javascript running in localhost:8983
. if not, phone call violate cross-domain policy of browser.
if not, need create simple backend bouncer on same domain website. so, if solr running @ localhost:8983
, website running @ localhost:80
, need backend helper javascript.
the js in question quite simple, can utilize $.get
or $.getjson
. recommend getjson this, see documentation , examples @ http://api.jquery.com/jquery.getjson/.
i have no clue how backend built, c# mvc ajax controller action bouncing this. note wrote without testing, not work straight can utilize guideline.
public jsonresult search(string searchterm) { // if searchterm value "q". might have encode it. var url = "localhost:8983/solr/collection1/select?q=" + searchterm + "&wt=json&indent=true"; doxlog.info("contacting sovelia api url: " + url); var request = (httpwebrequest)webrequest.create(url); request.useragent = "dox"; // fire request using (var response = request.getresponse()) { var datastream = response.getresponsestream(); using (var reader = new streamreader(datastream)) { var responseasstring = reader.readtoend(); homecoming json(responseasstring, jsonrequestbehavior.allowget); } } }
java mysql json apache solr
No comments:
Post a Comment