Project

General

Profile

« Previous | Next » 

Revision 4290

refactor search methods into common search.js file.
start on making ajax-based search from the index page.
state of things: now merging across assessments and including question-level metadata

View differences:

lib/style/skins/first/search.js
32 32
	questionIds[0] = questionId;
33 33
	
34 34
	var documentObjects = new Array();
35
	
35
	var index = 0;
36 36
	if (submitFormObj.docids.length > 1) {
37 37
		for (var i=0; i < submitFormObj.docids.length; i++) {
38
			var documentObject = new Object();
39
			documentObject.docid = submitFormObj.docids[i].value;
40
			documentObject.questionIds = questionIds;
41
			documentObjects[i] = documentObject;
38
			if (submitFormObj.docids[i].checked) {
39
				var documentObject = new Object();
40
				documentObject.docid = submitFormObj.docids[i].value;
41
				
42
				for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
43
					questionIds[z] = submitFormObj[documentObject.docid][z].value;
44
				}
45
			
46
				documentObject.questionIds = questionIds;
47
				documentObjects[index] = documentObject;
48
				index++;
49
			}
42 50
		}
43 51
	}
44 52
	else {
45
		var documentObject = new Object();
46
		documentObject.docid = submitFormObj.docids.value;
47
		for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
48
			questionIds[z] = submitFormObj[documentObject.docid][z].value;
53
		if (submitFormObj.docids.checked) {
54
			var documentObject = new Object();
55
			documentObject.docid = submitFormObj.docids.value;
56
			
57
			for (var z = 0; z < submitFormObj[documentObject.docid].length; z++) {
58
				questionIds[z] = submitFormObj[documentObject.docid][z].value;
59
			}
60
			
61
			documentObject.questionIds = questionIds;
62
			documentObjects[0] = documentObject;
49 63
		}
50
		documentObject.questionIds = questionIds;
51
		documentObjects[0] = documentObject;
52 64
	}
53 65
		
54 66
	var query = generateQuery(documentObjects, metadataObjs);
......
258 270
	alert(tempQuery);
259 271
             
260 272
    return tempQuery;
273
}
274

  
275
function generateSearchString(searchString, searchAssessments, searchAssessmentItems) {
276
	var queryString = 
277
		"<pathquery version=\"1.2\">"
278
			+"<querytitle>Web-Search</querytitle>";
279
		
280
	/** assessments **/
281
	if (searchAssessments) {
282
	
283
		queryString +=
284
			"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
285
			
286
			//assessment fields
287
               +"<returnfield>assessment/duration</returnfield>"
288
               +"<returnfield>assessment/@title</returnfield>"
289
               +"<returnfield>assessment/@id</returnfield>"
290
               +"<returnfield>lom/general/title/string</returnfield>"
291
               +"<returnfield>lom/general/keyword/string</returnfield>"
292
               +"<returnfield>individualName/surName</returnfield>"
293
               +"<returnfield>organizationName</returnfield>"
294
               
295
               +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
296
               
297
	}
298
						
299
	/** questions **/
300
	if (searchAssessmentItems) {
301
		queryString +=
302
			"<returndoctype>http://www.imsglobal.org/xsd/ims_qtiasiv1p2</returndoctype>"
303
			
304
			//question (qti) fields
305
			+"<returnfield>item/@title</returnfield>"
306
			+"<returnfield>item/@ident</returnfield>"
307
               +"<returnfield>qtimetadata/qtimetadatafield/fieldlabel</returnfield>"
308
               +"<returnfield>qtimetadata/qtimetadatafield/fieldentry</returnfield>"
309
			//classification
310
			+"<returnfield>fieldlabel</returnfield>"
311
			+"<returnfield>fieldentry</returnfield>"
312
			+"<returnfield>objectives/material/mattext</returnfield>"
313
			//question content
314
			+"<returnfield>presentation/flow/material/mattext</returnfield>"
315
			+"<returnfield>response_label/@ident</returnfield>"
316
			+"<returnfield>response_label/material/mattext</returnfield>";
317
	}		
318
                                                   
319
	queryString +=
320
                 "<querygroup operator=\"UNION\">"
321
                         +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
322
                                 +"<value>" + searchString + "</value>"
323
                         +"</queryterm>"
324
                 +"</querygroup>"
325
	+"</pathquery>";
326
	
327
	return queryString;
328
				
329
}
330

  
331

  
332
function generateAssessmentSearchString(assessmentItemId) {
333
	var query = 
334
		"<pathquery version='1.2'>"
335
		     +"<querytitle>Containing-Assessment-Search</querytitle>"
336
		     
337
		     +"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
338
		                           
339
                      +"<returnfield>assessment/@title</returnfield>"
340
                      +"<returnfield>assessment/@id</returnfield>"
341
                      +"<returnfield>assessment/duration</returnfield>"
342
                      +"<returnfield>lom/general/title/string</returnfield>"
343
                      +"<returnfield>lom/general/keyword/string</returnfield>"
344
                      +"<returnfield>individualName/surName</returnfield>"
345
                      +"<returnfield>organizationName</returnfield>"
346
                      
347
                      +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
348
                      
349
		    if (assessmentItemId.length > 0) {
350
			    query += "<querygroup operator='UNION'>";
351
			    
352
			    //add the assessmentId if included
353
			    query +=
354
			     		"<queryterm searchmode='contains' casesensitive='false'>"
355
			                  +"<value>"
356
			                  + assessmentItemId
357
			                  +"</value>"
358
			                  +"<pathexpr>assessmentItemId</pathexpr>"
359
			          +"</queryterm>";
360
				
361
			    //close the query group      
362
			     query +=
363
			     "</querygroup>";
364
			}
365
			     
366
		query += "</pathquery>";
367
		
368
	return query;	
369
}
370

  
371
function callAjax(metacatURL, myQuery, qfmt) {
372
														
373
	//alert("calling ajax: " + metacatURL);
374
	//alert("myQuery: " + myQuery);
375
	
376
	//var myRequest = new Ajax.Request(
377
	var myUpdate = new Ajax.Updater(
378
		'ajaxResults',
379
		metacatURL,
380
		{	method: 'post',
381
			parameters: { action: 'squery', qformat: qfmt, query: myQuery},
382
			evalScripts: true, 
383
			//onSuccess: function(transport) {alert('success: ' + transport.status);},
384
			onFailure: function(transport) {alert('failure making ajax call');}
385
		 });
386
		 
387
	 //alert("done calling ajax");
261 388
}
lib/style/skins/first/index.jsp
37 37
<script language="JavaScript" type="text/JavaScript"
38 38
	src="<%=STYLE_SKINS_URL%>/first/first.js"></script>
39 39
<script language="JavaScript" type="text/JavaScript"
40
	src="<%=STYLE_SKINS_URL%>/first/search.js"></script>
41
<script language="JavaScript" type="text/JavaScript"
40 42
	src="<%=STYLE_COMMON_URL%>/branding.js"></script>
43
<script language="Javascript" type="text/JavaScript"
44
	src="<%=STYLE_COMMON_URL%>/prototype-1.5.1.1/prototype.js">
45
</script>	
41 46
<script language="Javascript">
42 47
        function trim(stringToTrim) {
43 48
                return stringToTrim.replace(/^\s*/, '').replace(/\s*$/,'');
......
64 69
				}
65 70
			}
66 71
			
72
			//generate the query
67 73
			var queryString = 
68
				"<pathquery version=\"1.2\">"
69
					+"<querytitle>Web-Search</querytitle>";
70
					
71
					/** assessments **/
72
					if (searchAssessmentsCheckBox.checked == true) {
73
						queryString +=
74
							"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
75
							
76
							//assessment fields
77
			                +"<returnfield>assessment/duration</returnfield>"
78
			                +"<returnfield>assessment/@title</returnfield>"
79
			                +"<returnfield>assessment/@id</returnfield>"
80
			                +"<returnfield>lom/general/title/string</returnfield>"
81
			                +"<returnfield>lom/general/keyword/string</returnfield>"
82
			                +"<returnfield>individualName/surName</returnfield>"
83
			                +"<returnfield>organizationName</returnfield>";
84
					}
85
										
86
					/** questions **/
87
					if (searchQuestionsCheckBox.checked == true) {
88
						queryString +=
89
							"<returndoctype>http://www.imsglobal.org/xsd/ims_qtiasiv1p2</returndoctype>"
90
							
91
							//question (qti) fields
92
							+"<returnfield>item/@title</returnfield>"
93
							+"<returnfield>item/@ident</returnfield>"
94
			                +"<returnfield>qtimetadata/qtimetadatafield/fieldlabel</returnfield>"
95
			                +"<returnfield>qtimetadata/qtimetadatafield/fieldentry</returnfield>"
96
							//classification
97
							+"<returnfield>fieldlabel</returnfield>"
98
							+"<returnfield>fieldentry</returnfield>"
99
							+"<returnfield>objectives/material/mattext</returnfield>"
100
							//question content
101
							+"<returnfield>presentation/flow/material/mattext</returnfield>"
102
							+"<returnfield>response_label/@ident</returnfield>"
103
							+"<returnfield>response_label/material/mattext</returnfield>";
104
					}		
105
                                                      
106
			queryString +=
107
                    "<querygroup operator=\"UNION\">"
108
                            +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
109
                                    +"<value>" + searchString + "</value>"
110
                            +"</queryterm>"
111
                    +"</querygroup>"
112
				+"</pathquery>";
74
				generateSearchString(
75
					searchString, 
76
					searchAssessmentsCheckBox.checked, 
77
					searchQuestionsCheckBox.checked);
113 78
				
114 79
			//set the form value	
115 80
    		submitFormObj.query.value = queryString;
81
    		
82
    		submitFormObj.qformat.value = "first";
83
    		
116 84
    		//alert(submitFormObj.query.value);	
117 85
			return true;
118 86
        }
......
129 97
				submitFormObj.submit();
130 98
			}
131 99
		}
100
		
101
		function searchAssessments(){
102
			var searchString = document.getElementById("searchBox").value;
103
			var metacatURL = "<%=CONTEXT_URL%>/metacat";
104
			
105
			//generate the query
106
			var queryString = 
107
				generateSearchString(
108
					searchString, 
109
					true, 
110
					false);
111
					
112
			callAjax(metacatURL, queryString, "first-assessment");			
113
		}
132 114
   </script>
133 115
</head>
134 116
<body>
......
191 173
								<input name="enableediting"	value="false" type="hidden"> 
192 174
								<input type="hidden" name="action" value="squery"> 
193 175
								<input value="Search" type="submit">
176
								<a href="javascript:searchAssessments()">
177
								Dynamic Search
178
								</a> 
194 179
							</span>
195 180
						</form>
196 181
						<form>
......
227 212
					</td>
228 213
				</tr>
229 214
			</table>
215
			<div id="ajaxResults">Loading Search results...</div>
230 216
			<br />
231 217
			<br />
232 218
	
lib/style/skins/first/first-assessment-resultset.xsl
42 42
              form_ref.action.value=action;
43 43
              form_ref.docid.value=docid;
44 44
              form_ref.sessionid.value="]]><xsl:value-of select="$sessid" /><![CDATA[";
45
              //form_ref.qformat.value="]]><xsl:value-of select="$qformat" /><![CDATA[";
45
              form_ref.qformat.value="first";
46 46
              form_ref.submit();
47 47
          }
48 48
          setSelect = function(form_ref, checkBoxName, checked) {
......
66 66
				}
67 67
								
68 68
				//transfer the assessmentItemId to this form
69
				document.getElementById("questionId").value = document.getElementById("assessmentItemId").value;
69
				//document.getElementById("questionId").value = document.getElementById("assessmentItemId").value;
70 70
				//alert("questionId: " + document.getElementById("questionId").value);
71 71
				
72 72
				var submitFormObj = document.getElementById(formId);

Also available in: Unified diff