SOLR provides a JSON-formatted search result, but how is it called in a cross-domain scenario? We can get the SOLR search results using the JSONP provided by jquery.
<Scripttype= "Text/javascript"src= "./resources/js/jquery-1.8.2.min.js"></Script> <inputtype= "text"size= " the"value=""ID= "keyword"name= "keyword" /> <inputtype= "button"value= "Search"ID= "Search" /> <DivID= "Result"></Div> <Scripttype= "Text/javascript"> $("#search"). Click (function() { varkeyword= $("#keyword"). Val (); varSolrserver= "Http://localhost:8080/solr/solrfirstcore/select"; $.ajax ({type:"Get", Url:solrserver, data: {WT:"JSON", Q:"Search_item:" +keyword, indent:true, "JSON.WRF" : 'Callback', "HL" : "true", "HL.FL" : "Title, Summary", "Hl.simple.pre" : "<font color=\ "red\" >", "Hl.simple.post" : "</font>", "Start":"0", "rows":" -"}, DataType:"Jsonp", //JSONP: "Callback",Jsonpcallback:"Callback",//Custom JSONP callback function name, default to jquery auto-generated random function nameError:function() { $("#result"). HTML ("<font color=\ "red\" > not the result you want to query. </font>"); } }); }); functionCallback (data) {varResponseheader=Data.responseheader; varResponse=Data.response; varhighlighting=data.highlighting; varDocs=Response.docs; varresult= NewArray (); Result.push ("Number of results:" +Response.numfound+ "time-consuming:" +Responseheader.qtime/ + + "seconds"); varhlstring= ""; for ( varIndexinchdocs) { varDoc=Docs[index]; varDocId=doc.id; Hl_string= ""ID":" +doc.id; varHdoc=Highlighting[docid]; vartitle=Doc.title; varSummary=doc.summary; if(hdoc.title) {title=Hdoc.title; } if(hdoc.summary) {Summary=hdoc.summary; } hl_string+= ", "title":" +title+ ", "description":" +Summary; Result.push ("------------------------------------------------------------"); Result.push (hl_string); } $("#result"). HTML ("</br>" +Result.join ("</br>")); } </Script>
Cross-domain request get SOLR JSON search results and highlight