Project

General

Profile

1 5509 leinfelder
function trim(stringToTrim) {
2
    return stringToTrim.replace(/^\s*/, '').replace(/\s*$/,'');
3
}
4
5
function checkSearch(submitFormObj) {
6
7 5533 leinfelder
	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 5951 leinfelder
        	"<namespace prefix='sms'>http://ecoinformatics.org/sms/annotation.1.0beta1</namespace>" +
21 5533 leinfelder
        	"<returnField>/@id</returnField>" +
22 5951 leinfelder
        	"<returnField>/@dataPackage</returnField>" +
23 5533 leinfelder
        	"<title>Semantic Search Example</title>" +
24
        	"<!-- Match all criteria, must be on same observation -->" +
25
        	"<" + operator + " strict='" + strict + "'>";
26 5661 leinfelder
27 5633 leinfelder
        	// handle specific classes
28
        	// Entity
29 5774 leinfelder
    		if (submitFormObj.activeEntitiesClass.value) {
30
    			var searchClass = submitFormObj.activeEntitiesClass.value;
31 5656 leinfelder
        	    var searchValue = submitFormObj.activeEntitiesValue.value;
32 5633 leinfelder
        	    if (searchValue!="") {
33
	        	    submitFormObj.query.value +=
34
	        	    	"<condition " +
35 5993 leinfelder
		        		"type='" + searchClass + "' " +
36
		        		"concept='" + searchValue + "' " +
37
					"/>";
38 5633 leinfelder
        	    }
39 5774 leinfelder
    		} else {
40
	        	for (var i=0; i < submitFormObj.activeEntitiesValue.length; i++) {
41
	        		var searchClass = submitFormObj.activeEntitiesClass[i].value;
42
	        	    var searchValue = submitFormObj.activeEntitiesValue[i].value;
43
	        	    if (searchValue!="") {
44 5993 leinfelder
	        	    	submitFormObj.query.value +=
45 5774 leinfelder
		        	    	"<condition " +
46 5993 leinfelder
			        		"type='" + searchClass + "' " +
47
			        		"concept='" + searchValue + "' " +
48
						"/>";
49 5774 leinfelder
	        	    }
50
	        	}
51
    		}
52 5633 leinfelder
        	// Characteristic
53 5774 leinfelder
    		if (submitFormObj.activeCharacteristicsClass.value) {
54
    			var searchClass = submitFormObj.activeCharacteristicsClass.value;
55 5656 leinfelder
        	    var searchValue = submitFormObj.activeCharacteristicsValue.value;
56 5993 leinfelder
        	    var dataValue = submitFormObj.dataValue.value;
57
        	    var dataOperator = submitFormObj.dataOperator.value;
58 5997 leinfelder
        	    if (searchValue != "") {
59 5633 leinfelder
	        	    submitFormObj.query.value +=
60
	        	    	"<condition " +
61 5993 leinfelder
		        		"type='" + searchClass + "' " +
62 5997 leinfelder
		        		"concept='" + searchValue + "' ";
63
        	    	if (dataValue != "") {
64
	        	    	submitFormObj.query.value +=
65
	        	    		"operator='" + dataOperator + "'>" +
66
	        	    		dataValue +
67
	        	    		"</condition>";
68
	        	    } else {
69
		        	    submitFormObj.query.value += "/>";
70
	        	    }
71 5633 leinfelder
        	    }
72 5774 leinfelder
    		} else {
73
	        	for (var i=0; i < submitFormObj.activeCharacteristicsValue.length; i++) {
74
	        		var searchClass = submitFormObj.activeCharacteristicsClass[i].value;
75
	        	    var searchValue = submitFormObj.activeCharacteristicsValue[i].value;
76 5993 leinfelder
	        	    var dataValue = submitFormObj.dataValue[i].value;
77
	        	    var dataOperator = submitFormObj.dataOperator[i].value;
78 5997 leinfelder
	        	    if (searchValue != "") {
79 5993 leinfelder
	        	    	submitFormObj.query.value +=
80 5774 leinfelder
		        	    	"<condition " +
81 5993 leinfelder
			        		"type='" + searchClass + "' " +
82 5997 leinfelder
			        		"concept='" + searchValue + "' ";
83
84
	        	    	if (dataValue != "") {
85
		        	    	submitFormObj.query.value +=
86
		        	    		"operator='" + dataOperator + "'>" +
87
		        	    		dataValue +
88
		        	    		"</condition>";
89
		        	    } else {
90
			        	    submitFormObj.query.value += "/>";
91
		        	    }
92 5774 leinfelder
	        	    }
93
	        	}
94
    		}
95 5633 leinfelder
        	// Protocol
96 5774 leinfelder
    		if (submitFormObj.activeProtocolsValue.value) {
97 5954 leinfelder
    			var searchClass = submitFormObj.activeProtocolsClass.value;
98 5656 leinfelder
        	    var searchValue = submitFormObj.activeProtocolsValue.value;
99 5633 leinfelder
        	    if (searchValue!="") {
100 5993 leinfelder
        	    	submitFormObj.query.value +=
101 5633 leinfelder
	        	    	"<condition " +
102 5993 leinfelder
		        		"type='" + searchClass + "' " +
103
		        		"concept='" + searchValue + "' " +
104
					"/>";
105 5633 leinfelder
        	    }
106 5774 leinfelder
    		} else {
107
	        	for (var i=0; i < submitFormObj.activeProtocolsValue.length; i++) {
108
	        		var searchClass = submitFormObj.activeProtocolsClass[i].value;
109
	        	    var searchValue = submitFormObj.activeProtocolsValue[i].value;
110
	        	    if (searchValue!="") {
111 5993 leinfelder
	        	    	submitFormObj.query.value +=
112 5774 leinfelder
		        	    	"<condition " +
113 5993 leinfelder
			        		"type='" + searchClass + "' " +
114
			        		"concept='" + searchValue + "' " +
115
						"/>";
116 5774 leinfelder
	        	    }
117
	        	}
118
    		}
119 5633 leinfelder
        	// Measurement
120 5774 leinfelder
    		if (submitFormObj.activeMeasurementsValue.value) {
121 5954 leinfelder
    			var searchClass = submitFormObj.activeMeasurementsClass.value;
122 5656 leinfelder
        	    var searchValue = submitFormObj.activeMeasurementsValue.value;
123 5633 leinfelder
        	    if (searchValue!="") {
124 5993 leinfelder
        	    	submitFormObj.query.value +=
125 5633 leinfelder
	        	    	"<condition " +
126 5993 leinfelder
		        		"type='" + searchClass + "' " +
127
		        		"concept='" + searchValue + "' " +
128
					"/>";
129 5633 leinfelder
        	    }
130 5774 leinfelder
    		} else {
131
	        	for (var i=0; i < submitFormObj.activeMeasurementsValue.length; i++) {
132
	        		var searchClass = submitFormObj.activeMeasurementsClass[i].value;
133
	        	    var searchValue = submitFormObj.activeMeasurementsValue[i].value;
134
	        	    if (searchValue!="") {
135 5993 leinfelder
	        	    	submitFormObj.query.value +=
136 5774 leinfelder
		        	    	"<condition " +
137 5993 leinfelder
			        		"type='" + searchClass + "' " +
138
			        		"concept='" + searchValue + "' " +
139
						"/>";
140 5774 leinfelder
	        	    }
141
	        	}
142
    		}
143 5533 leinfelder
        	submitFormObj.query.value += "</" + operator + ">";
144
    	submitFormObj.query.value += "</sq:query>";
145
146 5635 leinfelder
    //alert("query: " + submitFormObj.query.value);
147 5509 leinfelder
148
    return true;
149 5704 leinfelder
}