Project

General

Profile

1
function trim(stringToTrim) {
2
    return stringToTrim.replace(/^\s*/, '').replace(/\s*$/,'');
3
}
4

    
5
function checkSearch(submitFormObj) {
6

    
7
	var operator = "OR";
8
	if (submitFormObj.matchAll.checked) {
9
		operator = "AND";
10
	}
11
	var strict = "false";
12
	if (submitFormObj.strict.checked) {
13
		strict = "true";
14
	}
15
    submitFormObj.query.value = 
16
    	"<sq:query queryId='query.1' system='semtools' " +
17
    	"xmlns:sq='http://ecoinformatics.org/semQuery-1.0.0' " +
18
    	"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
19
    	"xsi:schemaLocation='http://ecoinformatics.org/semQuery-1.0.0 semQuery.xsd '>" +
20
        	"<namespace prefix='sms'>http://ecoinformatics.org/sms/annotation.1.0beta1</namespace>" +
21
        	"<returnField>/@id</returnField>" +
22
        	"<returnField>/@dataPackage</returnField>" +
23
        	"<title>Semantic Search Example</title>" +
24
        	"<!-- Match all criteria, must be on same observation -->" +
25
        	"<" + operator + " strict='" + strict + "'>";
26
        	
27
        	// handle specific classes
28
        	// Entity
29
    		if (submitFormObj.activeEntitiesClass.value) {
30
    			var searchClass = submitFormObj.activeEntitiesClass.value;
31
        	    var searchValue = submitFormObj.activeEntitiesValue.value;
32
        	    if (searchValue!="") {
33
	        	    submitFormObj.query.value += 
34
	        	    	"<condition " +
35
		        		"concept='" + searchClass + "' " +
36
						"operator='EQUALS'>" +
37
						searchValue +
38
					"</condition>";
39
        	    }
40
    		} else {
41
	        	for (var i=0; i < submitFormObj.activeEntitiesValue.length; i++) {
42
	        		var searchClass = submitFormObj.activeEntitiesClass[i].value;
43
	        	    var searchValue = submitFormObj.activeEntitiesValue[i].value;
44
	        	    if (searchValue!="") {
45
		        	    submitFormObj.query.value += 
46
		        	    	"<condition " +
47
			        		"concept='" + searchClass + "' " +
48
							"operator='EQUALS'>" +
49
							searchValue +
50
						"</condition>";
51
	        	    }
52
	        	}
53
    		}
54
        	// Characteristic
55
    		if (submitFormObj.activeCharacteristicsClass.value) {
56
    			var searchClass = submitFormObj.activeCharacteristicsClass.value;
57
        	    var searchValue = submitFormObj.activeCharacteristicsValue.value;
58
        	    if (searchValue!="") {
59
	        	    submitFormObj.query.value += 
60
	        	    	"<condition " +
61
		        		"concept='" + searchClass + "' " +
62
						"operator='EQUALS'>" +
63
						searchValue +
64
					"</condition>";
65
        	    }
66
    		} else {
67
	        	for (var i=0; i < submitFormObj.activeCharacteristicsValue.length; i++) {
68
	        		var searchClass = submitFormObj.activeCharacteristicsClass[i].value;
69
	        	    var searchValue = submitFormObj.activeCharacteristicsValue[i].value;
70
	        	    if (searchValue!="") {
71
		        	    submitFormObj.query.value += 
72
		        	    	"<condition " +
73
			        		"concept='" + searchClass + "' " +
74
							"operator='EQUALS'>" +
75
							searchValue +
76
						"</condition>";
77
	        	    }
78
	        	}
79
    		}	
80
        	// Protocol
81
    		if (submitFormObj.activeProtocolsValue.value) {
82
    			var searchClass = submitFormObj.activeProtocolsClass.value;
83
        	    var searchValue = submitFormObj.activeProtocolsValue.value;
84
        	    if (searchValue!="") {
85
	        	    submitFormObj.query.value += 
86
	        	    	"<condition " +
87
		        		"concept='" + searchClass + "' " +
88
						"operator='EQUALS'>" +
89
						searchValue +
90
					"</condition>";
91
        	    }
92
    		} else {
93
	        	for (var i=0; i < submitFormObj.activeProtocolsValue.length; i++) {
94
	        		var searchClass = submitFormObj.activeProtocolsClass[i].value;
95
	        	    var searchValue = submitFormObj.activeProtocolsValue[i].value;
96
	        	    if (searchValue!="") {
97
		        	    submitFormObj.query.value += 
98
		        	    	"<condition " +
99
			        		"concept='" + searchClass + "' " +
100
							"operator='EQUALS'>" +
101
							searchValue +
102
						"</condition>";
103
	        	    }
104
	        	}
105
    		}	
106
        	// Measurement
107
    		if (submitFormObj.activeMeasurementsValue.value) {
108
    			var searchClass = submitFormObj.activeMeasurementsClass.value;
109
        	    var searchValue = submitFormObj.activeMeasurementsValue.value;
110
        	    if (searchValue!="") {
111
	        	    submitFormObj.query.value += 
112
	        	    	"<condition " +
113
		        		"concept='" + searchClass + "' " +
114
						"operator='EQUALS'>" +
115
						searchValue +
116
					"</condition>";
117
        	    }
118
    		} else {
119
	        	for (var i=0; i < submitFormObj.activeMeasurementsValue.length; i++) {
120
	        		var searchClass = submitFormObj.activeMeasurementsClass[i].value;
121
	        	    var searchValue = submitFormObj.activeMeasurementsValue[i].value;
122
	        	    if (searchValue!="") {
123
		        	    submitFormObj.query.value += 
124
		        	    	"<condition " +
125
			        		"concept='" + searchClass + "' " +
126
							"operator='EQUALS'>" +
127
							searchValue +
128
						"</condition>";
129
	        	    }
130
	        	}
131
    		}
132
        	submitFormObj.query.value += "</" + operator + ">";
133
    	submitFormObj.query.value += "</sq:query>";
134
		
135
    //alert("query: " + submitFormObj.query.value);
136

    
137
    return true;
138
}
(10-10/16)