root/other-projects/tipple-android/i-greenstone-server-files/greenstone/webapps/greenstone3/search.html @ 26899

Revision 26899, 8.2 KB (checked in by davidb, 7 years ago)

Tipple reborn after Chris's Summer of Code 2013

RevLine 
[26899]1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
3<html>
4<head>
5<title>AJAX GS3 Search</title>
6<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
7<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
8<style type="text/css">
9<!--
10BODY, P, LI { font-family: sans-serif; }
11H2 {font-size: 90%;}
12BUTTON {font-size: 0.8em; margin: 0 1em; color: red;}
13#searchArea {background-color:white; }
14#resultArea {background-color:white; padding: 0em 0em;}
15#resultSummary {font-size: 80%; padding: 0.2 em 0.2em;}
16#resultSummary P {padding: 0.2em 0.3em;}
17#query {padding: 0.1em 0.5em; width: 400px; height: 150px; background-color:#d3d3d3;}
18#timing {float:right; width: 250px; border: thin solid #d3d3d3; padding: 0.2em 0.2em; display: none;}
19#resultList {   list-style-image: none;
20                        list-style-type: square;
21                        font-size: 85%; padding: 1em 0em 1em 2em;}
22#resultList LI {padding: 0.3em 0em; }
23-->
24</style>
25<script type="text/javascript" src="xmlextras.js">
26</script>
27<script type="text/javascript" src="gs_ajax_utils.js">
28</script>
29<script type="text/javascript">
30<!--
31
32localsiteServerAddress = "/greenstone3/services/SOAPServerlocalsite";
33libraryAddress = "/greenstone3/library";
34function loadAsync(sUri, SOAPMessage, callbackFunction) {
35   var xmlHttp = XmlHttp.create();
36   var async = true;
37   xmlHttp.open("POST", sUri, async);
38   xmlHttp.onreadystatechange = function () {
39      if (xmlHttp.readyState == 4){
40        var result = xmlHttp.responseText;
41            //getTitle2(xmlHttp.responseXML, xmlHttp.responseText);
42            eval(callbackFunction);
43    }     
44   }
45   xmlHttp.setRequestHeader("SOAPAction", " ");
46   xmlHttp.setRequestHeader("Content-Type", "Content-Type: text/xml; charset=utf-8");
47 
48   xmlHttp.send(SOAPMessage);
49}
50
51
52function ajaxSearch() {
53
54searchStartTime = new Date();
55
56resultList = document.getElementById('resultList');
57removeAllChildren(resultList);
58resultSummary = document.getElementById('resultSummary');
59removeAllChildren(resultSummary);
60
61/*
62for (i=0; i < 10; i++) {
63    listElement = document.createElement('li');
64    anchor = document.createElement('a');
65    anchor.setAttribute('href', url);
66    anchor.appendChild(document.createTextNode(  text));
67    listElement.appendChild(anchor);
68    resultList.appendChild(listElement);
69}
70*/
71
72queryText = document.getElementById('queryText').value;
73
74maxdocs = newElementAtt('param', '', new Array('name', 'value'), new Array('maxDocs', '100') ) ;
75level = newElementAtt('param', '', new Array('name', 'value'), new Array('level', 'Sec') ) ;
76indexValue = newElementAtt('param', '', new Array('name', 'value'), new Array('index', 'ZZ') ) ;
77matchMode = newElementAtt('param', '', new Array('name', 'value'), new Array('matchMode', 'some') ) ;
78query = newElementAtt('param', '', new Array('name', 'value'), new Array('query', queryText) ) ;
79caseValue = newElementAtt('param', '', new Array('name', 'value'), new Array('case', '1') ) ;
80sortBy = newElementAtt('param', '', new Array('name', 'value'), new Array('sortBy', '1') ) ;
81stem = newElementAtt('param', '', new Array('name', 'value'), new Array('stem', '1') ) ;
82
83
84paramList = newElement('paramList', maxdocs + level + indexValue + matchMode + query + caseValue + sortBy + stem);
85
86collection = document.getElementById('collectionText').value;
87request = newElementAtt('request', paramList, new Array('lang', 'to', 'type', 'uid'), new Array('en',collection + '/TextQuery', 'process', '1'  ) );
88message = newElement('message', request );
89soapMessage = messageToSOAP(message);
90loadAsync(localsiteServerAddress, soapMessage, 'getResults(xmlHttp.responseXML)');
91}
92
93function getResults(xmlDoc) {
94idsReturnedTime = new Date();
95    metadataList = xmlDoc.getElementsByTagName('metadata');
96    for (i=0; i < metadataList.length; i++) {
97        metadata = metadataList[i];
98        if (isElement(metadata)) {
99          nameAtt = metadata.getAttribute('name')
100            if ( nameAtt == 'numDocsMatched') {
101                numDocsMatched = getText(metadata);
102            }
103            if (nameAtt == 'numDocsReturned') {
104                numDocsReturned = getText(metadata);
105            }
106            if (nameAtt  == 'query') {
107                query = getText(metadata);
108            }
109        }
110    }
111   
112    resultSummary = document.getElementById('resultSummary');
113    para = document.createElement('p');
114    para.appendChild(document.createTextNode('Query: ' + query + ' Number of Matching Docs: ' + numDocsMatched + ' Number of returned documents: ' + numDocsReturned));
115    resultSummary.appendChild(para);
116   
117    documentNodeList = xmlDoc.getElementsByTagName('documentNode');
118       
119    for (i=0; i < documentNodeList.length; i++) {
120        documentNode = documentNodeList[i];
121        if (isElement(documentNode)) {
122            docIDArray[i] = documentNode.getAttribute('nodeID');
123        }
124    }
125   
126    var docsList = '';
127    for (i=0; i < docIDArray.length; i++) {
128        docsList += newElementAtt1('documentNode', '', 'nodeID', docIDArray[i]);
129    }
130   
131    docNodeList = newElement('documentNodeList', docsList);
132    collection = document.getElementById('collectionText').value;
133    param = newElementAtt('param', '', new Array('name', 'value'), new Array('metadata', 'Title') );
134    paramList = newElement('paramList', param);
135    request = newElementAtt('request', paramList + docNodeList, new Array('lang', 'to', 'type', 'uid'), new Array('en',collection + '/DocumentMetadataRetrieve', 'process', '1'  ) );
136    message = newElement('message', request );
137    soapMessage = messageToSOAP(message);
138    //alert(soapMessage);
139    loadAsync(localsiteServerAddress, soapMessage, 'displayResults(xmlHttp.responseXML)');
140}
141
142
143function displayResults(xmlDoc) {
144    metadataReturnedTime = new Date();
145    url1 = libraryAddress+'?a=d&d=';
146    url2 = '&c=' + document.getElementById('collectionText').value + '&dt=hierarchy';
147    resultList = document.getElementById('resultList');
148    metadataList = xmlDoc.getElementsByTagName('metadata');
149    //alert('in display results ' + metadataList.length + xmlDoc.xml);
150        for (i=0; i < metadataList.length; i++) {
151              //alert('in display results ' + i);
152            metadata = metadataList[i];
153            if (isElement(metadata)) {
154                if (metadata.getAttribute('name') == 'Title') {
155                   
156                  listElement = document.createElement('li');
157                anchor = document.createElement('a');
158                anchor.setAttribute('href', url1 + docIDArray[i] + url2);
159                anchor.appendChild(document.createTextNode(getText(metadata)) );
160                listElement.appendChild(anchor);
161                resultList.appendChild(listElement);
162                }           
163            }
164        }
165            finishedTime = new Date();
166            displayTime();
167           
168}
169
170function displayTime() {
171searchStart = document.getElementById('searchStart');
172idsReturned = document.getElementById('idsReturned');
173metadataReturned = document.getElementById('metadataReturned');
174//removeAllChildren(searchStart);
175//searchStart.appendChild(document.createTextNode(searchStartTime.getMilliseconds() + ' ms'))
176removeAllChildren(idsReturned);
177idsReturned.appendChild(document.createTextNode(idsReturnedTime.getMilliseconds() - searchStartTime.getMilliseconds()+ ' ms'))
178removeAllChildren(metadataReturned);
179metadataReturned.appendChild(document.createTextNode(metadataReturnedTime.getMilliseconds() - idsReturnedTime.getMilliseconds()+ ' ms'))
180//alert(searchStartTime.getMilliseconds() + ' ' + idsReturnedTime.getMilliseconds() + ' ' + metadataReturnedTime.getMilliseconds() + ' ' + ' ' + finishedTime.getMilliseconds());
181}
182
183
184var docIDArray = new Array();
185var searchStartTime, idsReturnedTime, metadataReturnedTime, finishedTime;
186
187
188
189
190// -->
191</script>
192</head>
193<body>
194
195
196
197<div id="searchArea">
198
199<div id="timing">
200<p><strong>Timing</strong></p>
201<table border="0" cellpadding="0" cellspacing="0" summary="">
202<!-- <tr><td>Search started:</td><td id="searchStart"></td></tr> -->
203<tr><td>Time to get IDs:</td><td id="idsReturned"></td></tr>
204<tr><td>Time to get Metadata:</td><td id="metadataReturned"></td></tr>
205</table>
206</div>
207
208<div id="query"><h2>Search a Greenstone 3 Collection</h2>
209<form action="">
210<p><label for="collectionText">GS3 Collection:</label>
211<input id="collectionText" type="text" value="gs2mgppdemo"/></p>
212
213<p><input id="queryText" type="text" /><input id="searchButton" type="submit" value="Search" onclick="ajaxSearch();return false;"></input></p>
214
215</form></div>
216</div>
217
218<div id="resultArea">
219<div id="resultSummary"></div>
220<ul id="resultList"></ul>
221</div>
222 
223</body>
224</html>
Note: See TracBrowser for help on using the browser.