Project

General

Profile

Revision 5058

search across items as well as assessments
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=4387
note: you can switch this feature off using the checkbox provided in the search form. the search can be slow otherwise

View differences:

lib/style/skins/first/search.js
397 397
	keys are search values
398 398
*   values are pathexprs
399 399
**/
400
function generateSearchString(searchTerms, operator, searchAssessments, searchAssessmentItems) {
400
function generateSearchString(
401
		searchTerms,
402
		assessmentItemIds,
403
		operator, 
404
		searchAssessments, 
405
		searchAssessmentItems) {
401 406
	var queryString = 
402 407
		"<pathquery version=\"1.2\">"
403 408
			+"<querytitle>Web-Search</querytitle>";
......
442 447
			+"<returnfield>response_label/material/mattext</returnfield>";
443 448
	}		
444 449
    
445
    queryString +=
446
    	"<querygroup operator=\"" + operator + "\">";
447
                         
450
	// a query group for search terms
451
	var termQueryString = "";
452
    termQueryString +=
453
    	"<querygroup operator=\"" + operator + "\">";                    
448 454
    for (var i in searchTerms) {
449 455
    	var key = i;
450 456
    	var value = searchTerms[i];
451 457
    	//only if we have a value  
452 458
    	if (value.length > 0) {                   
453
			queryString +=
459
    		termQueryString +=
454 460
				"<queryterm searchmode=\"contains\" casesensitive=\"false\">";
455 461
				if (key != "anyValue") {
456
					queryString += "<pathexpr>" + key + "</pathexpr>";
462
					termQueryString += "<pathexpr>" + key + "</pathexpr>";
457 463
				}	
458
		      	queryString += "<value>" + value + "</value>";
459
		    queryString +="</queryterm>";
464
				termQueryString += "<value>" + value + "</value>";
465
				termQueryString +="</queryterm>";
460 466
		}
461 467
    }
462
    
468
    termQueryString += "</querygroup>";
469
	
470
	// querygroup for assessmentItemIds
471
	var itemQueryString = "";
472
	if (assessmentItemIds) {
473
		//the pathexpr
474
		var pathexpr = "assessmentItems/assessmentItem/assessmentItemId";
475
		// a query group for search terms
476
		itemQueryString +=
477
	    	"<querygroup operator=\"" + "UNION" + "\">";
478
	    for (var i in assessmentItemIds) {
479
	    	var itemId = assessmentItemIds[i];
480
	    	//only if we have a value  
481
	    	if (itemId.length > 0) {                   
482
	    		itemQueryString +=
483
					"<queryterm searchmode=\"contains\" casesensitive=\"false\">";
484
					if (key != "anyValue") {
485
						itemQueryString += "<pathexpr>" + pathexpr + "</pathexpr>";
486
					}	
487
					itemQueryString += "<value>" + itemId + "</value>";
488
					itemQueryString +="</queryterm>";
489
			}
490
	    }
491
	    itemQueryString += "</querygroup>";
492
	}
493
	
494
	//combine the various conditions
463 495
	queryString +=
464
		"</querygroup>"
465
	+"</pathquery>";
496
    	"<querygroup operator=\"" + "UNION" + "\">";
497
	queryString += termQueryString;
498
	queryString += itemQueryString;
499
	queryString += "</querygroup>";
466 500
	
501
	//end the pathquery
502
	queryString += "</pathquery>";
503
	
467 504
	return queryString;
468 505
				
469 506
}
......
476 513
		     
477 514
		     +"<returndoctype>edml://ecoinformatics.org/edml</returndoctype>"
478 515
		                           
479
                      +"<returnfield>assessment/title</returnfield>"
480
                      +"<returnfield>assessment/@id</returnfield>"
481
                      +"<returnfield>assessment/duration</returnfield>"
482
                      +"<returnfield>dataset/dataTable/entityName</returnfield>"
483
                      +"<returnfield>lom/general/title/string</returnfield>"
484
                      +"<returnfield>lom/general/keyword/string</returnfield>"
485
                      +"<returnfield>individualName/surName</returnfield>"
486
                      +"<returnfield>organizationName</returnfield>"
516
		     +"<returnfield>assessment/duration</returnfield>"
517
             +"<returnfield>assessment/title</returnfield>"
518
             +"<returnfield>assessment/@id</returnfield>"
519
             +"<returnfield>dataset/dataTable/entityName</returnfield>"
520
             +"<returnfield>lom/general/title/string</returnfield>"
521
             +"<returnfield>lom/general/keyword/string</returnfield>"
522
             +"<returnfield>individualName/surName</returnfield>"
523
             +"<returnfield>organizationName</returnfield>"
487 524
                      
488
                      +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
525
             +"<returnfield>assessmentItems/assessmentItem/assessmentItemId</returnfield>";
489 526
                      
490 527
		    if (assessmentItemId.length > 0) {
491 528
			    query += "<querygroup operator='UNION'>";
......
550 587
	return query;	
551 588
}
552 589

  
553
function callAjax(metacatURL, myQuery, qfmt, divId) {
590
function callAjax(metacatURL, myQuery, qfmt, divId, callback) {
554 591
														
555 592
	//alert("calling ajax: " + metacatURL);
556 593
	//alert("myQuery: " + myQuery);
......
562 599
		{	method: 'post',
563 600
			parameters: { action: 'squery', qformat: qfmt, query: myQuery},
564 601
			evalScripts: true, 
565
			//onSuccess: function(transport) {alert('success: ' + transport.status);},
602
			onComplete: callback,
566 603
			onFailure: function(transport) {alert('failure making ajax call');}
567 604
		 });
568 605
		 
lib/style/skins/first/first-item-resultset.xsl
71 71
				<input type="hidden" name="action" value="read" />
72 72
				<input type="hidden" name="docid"/>
73 73
			</form>
74
			<!-- hidden form for the itemids -->
75
			<form action="{$contextURL}/metacat" method="POST" name="itemIdForm" id="itemIdForm">
74 76
			<table width="95%" align="left" border="0" cellpadding="0"
75 77
				cellspacing="0">
76 78

  
......
105 107
								<xsl:value-of select="./param[@name='item/@title']" />
106 108
							</a>
107 109
							(<xsl:value-of select="./docid" />)
110
							<input name="itemIds" id="itemIds" type="hidden" >
111
								<xsl:attribute name="value">
112
									<xsl:value-of select="./docid" />
113
								</xsl:attribute>	
114
							</input>
108 115
								
109 116
						</td>
110 117
						
......
191 198

  
192 199
				</xsl:for-each>
193 200
			</table>
201
			</form>
194 202

  
195 203
		</xsl:if>
196 204
	</xsl:template>
lib/style/skins/first/index.jsp
50 50

  
51 51
		function browseAll() {
52 52
			document.getElementById("searchBox").value = "%";
53
			searchAssessments();
53
			searchAssessments(false);
54 54
		}
55 55
		
56
		function searchAssessments() {
56
		function searchAssessments(includeItems) {
57 57
			var searchString = document.getElementById("searchBox").value;
58 58
			var institution = document.getElementById("institution").value;
59 59
			var instructor = document.getElementById("instructor").value;
......
80 80
			if (document.getElementById("all").checked) {
81 81
				operator = "INTERSECT";
82 82
			}
83
			if (document.getElementById("includeItems").checked) {
84
				includeItems = true;
85
			} else {
86
				includeItems = false;
87
			}
83 88
			
84 89
			var metacatURL = "<%=CONTEXT_URL%>/metacat";
85 90
			
86
			//generate the query
87
			var queryString = 
91
			//generate the query for items
92
			var itemQueryString = 
88 93
				generateSearchString(
89 94
					searchTerms,
95
					null,
90 96
					operator,
91
					true, 
92
					false);
97
					false, 
98
					true);
93 99
			
94
			//alert("queryString=" + queryString);
95
			
96
			callAjax(metacatURL, queryString, "first-assessment", "ajaxSearchResults");
97
			
98
			Effect.Appear('ajaxSearchResults', {duration: 1.5});		
100
			//alert("itemQueryString=" + itemQueryString);
101

  
102
			loadAssessments = function(transport) {
103
				
104
				//harvest the itemIds
105
				var itemIds = new Object();
106
				var itemIdForm = document.getElementById("itemIdForm");
107
				if (itemIdForm) {
108
					var itemIdObj = itemIdForm.itemIds;
109
					//alert("itemIdObj=" + itemIdObj);
110

  
111
					if (itemIdObj.length > 1) {
112
						for (var i=0; i < itemIdObj.length; i++) {
113
							itemIds[i] = itemIdObj[i].value;
114
						}
115
					} else {
116
						itemIds[0] = itemIdObj.value;
117
					}
118
				}
119
				
120
				//generate the assessment query with item ids included
121
				var queryString = 
122
					generateSearchString(
123
							searchTerms,
124
							itemIds,
125
							operator,
126
							true, 
127
							false);
128
	
129
				//alert("queryString=" + queryString);
130
	
131
				//load the assessments
132
				callAjax(metacatURL, queryString, "first-assessment", "ajaxSearchResults", null);
133
				Effect.Appear('ajaxSearchResults', {duration: 1.5});
134
			};
135

  
136
			//do we search using the items or not?
137
			if (includeItems) {
138
				//load the items (which calls the function above)
139
				callAjax(metacatURL, itemQueryString, "first-item", "itemSearchResults", loadAssessments);
140
			} else {
141
				//generate the assessment query with item ids included
142
				var queryString = 
143
					generateSearchString(
144
							searchTerms,
145
							null,
146
							operator,
147
							true, 
148
							false);
149
				// just load the assessments
150
				callAjax(metacatURL, queryString, "first-assessment", "ajaxSearchResults", null);
151
				Effect.Appear('ajaxSearchResults', {duration: 1.5});
152
			}	
99 153
		}
100 154
   </script>
101 155
</head>
......
221 275
								</td>	
222 276
								<td nowrap="nowrap">Match all</td>
223 277
							</tr>
278
							<tr>		
279
								<td nowrap="nowrap">
280
									<input name="includeItems" id="includeItems" checked="checked" type="checkbox"/>
281
								</td>	
282
								<td nowrap="nowrap">Search across Items</td>
283
							</tr>
224 284
						</table>
225 285
					</td>
226 286
					<td valign="bottom" class="borderbottom">
227 287
						<table>
228 288
							<tr>
229 289
								<td colspan="2">
230
									<input type="button" onclick="javascript:searchAssessments()" value="Search"/>
290
									<input type="button" onclick="javascript:searchAssessments(true)" value="Search"/>
231 291
								</td>
232 292
							</tr>
233 293
						</table>
......
258 318
			</div>
259 319
		</td>
260 320
	</tr>
321
	<tr>
322
		<td valign="top" colspan="2">	
323
			<div id="itemSearchResults" style="display:none;">
324
				Loading Assessment Item results 
325
				<img src="<%=CONTEXT_URL%>/style/images/spinner.gif" border="none"/>
326
			</div>
327
		</td>
328
	</tr>
261 329
</table>
262 330

  
263 331
<script language="JavaScript">          

Also available in: Unified diff