mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Drop JSON Query result example in to solr homepage.
This commit is contained in:
@@ -21,6 +21,60 @@
|
||||
<link rel="icon" href="favicon.ico" type="image/ico"></link>
|
||||
<link rel="shortcut icon" href="favicon.ico" type="image/ico"></link>
|
||||
<title>Welcome to Solr</title>
|
||||
<script language="Javascript">
|
||||
// derived from http://www.degraeve.com/reference/simple-ajax-example.php
|
||||
function xmlhttpPost(strURL) {
|
||||
var xmlHttpReq = false;
|
||||
var self = this;
|
||||
if (window.XMLHttpRequest) { // Mozilla/Safari
|
||||
self.xmlHttpReq = new XMLHttpRequest();
|
||||
}
|
||||
else if (window.ActiveXObject) { // IE
|
||||
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
}
|
||||
self.xmlHttpReq.open('POST', strURL, true);
|
||||
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
self.xmlHttpReq.onreadystatechange = function() {
|
||||
if (self.xmlHttpReq.readyState == 4) {
|
||||
updatepage(self.xmlHttpReq.responseText);
|
||||
}
|
||||
}
|
||||
|
||||
var params = getstandardargs().concat(getquerystring());
|
||||
var strData = params.join('&');
|
||||
self.xmlHttpReq.send(strData);
|
||||
}
|
||||
|
||||
function getstandardargs() {
|
||||
var params = [
|
||||
'wt=json'
|
||||
, 'indent=on'
|
||||
, 'hl=true'
|
||||
, 'hl.fl=name,features'
|
||||
];
|
||||
|
||||
return params;
|
||||
}
|
||||
function getquerystring() {
|
||||
var form = document.forms['f1'];
|
||||
var query = form.query.value;
|
||||
qstr = 'q=' + escape(query);
|
||||
return qstr;
|
||||
}
|
||||
|
||||
// this function does all the work of parsing the solr response and updating the page.
|
||||
function updatepage(str){
|
||||
document.getElementById("raw").innerHTML = str;
|
||||
var rsp = eval("("+str+")"); // use eval to parse Solr's JSON response
|
||||
var html= "<br>numFound=" + rsp.response.numFound;
|
||||
var first = rsp.response.docs[0];
|
||||
html += "<br>product name="+ first.name;
|
||||
var hl=rsp.highlighting[first.id];
|
||||
if (hl.name != null) { html += "<br>name highlighted: " + hl.name[0]; }
|
||||
if (hl.features != null) { html += "<br>features highligted: " + hl.features[0]; }
|
||||
document.getElementById("result").innerHTML = html;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -38,5 +92,16 @@
|
||||
<a href="admin/">Solr Admin</a>
|
||||
<% } %>
|
||||
|
||||
|
||||
<h1>Solr Ajax Example</h1>
|
||||
|
||||
<form name="f1" onsubmit='xmlhttpPost("select"); return false;'>
|
||||
<p>query: <input name="query" type="text">
|
||||
<input value="Go" type="submit"></p>
|
||||
|
||||
<div id="result"></div>
|
||||
<p/><pre>Raw JSON String: <div id="raw"></div></pre>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user