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
		        		"type='" + searchClass + "' " +
36
		        		"concept='" + searchValue + "' " +
37
					"/>";
38
        	    }
39
    		} 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
	        	    	submitFormObj.query.value += 
45
		        	    	"<condition " +
46
			        		"type='" + searchClass + "' " +
47
			        		"concept='" + searchValue + "' " +
48
						"/>";
49
	        	    }
50
	        	}
51
    		}
52
        	// Characteristic
53
    		if (submitFormObj.activeCharacteristicsClass.value) {
54
    			var searchClass = submitFormObj.activeCharacteristicsClass.value;
55
        	    var searchValue = submitFormObj.activeCharacteristicsValue.value;
56
        	    var dataValue = submitFormObj.dataValue.value;
57
        	    var dataOperator = submitFormObj.dataOperator.value;
58
        	    if (searchValue != "") {
59
	        	    submitFormObj.query.value += 
60
	        	    	"<condition " +
61
		        		"type='" + searchClass + "' " +
62
		        		"concept='" + searchValue + "' ";
63
        	    	if (dataValue != "") {
64
	        	    	submitFormObj.query.value += 
65
	        	    		"operator='" + dataOperator + "'>" +
66
	        	    		dataValue +
67
	        	    		"</condition>";
68
	        	    } else {
69
		        	    submitFormObj.query.value += "/>";
70
	        	    }
71
        	    }
72
    		} 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
	        	    var dataValue = submitFormObj.dataValue[i].value;
77
	        	    var dataOperator = submitFormObj.dataOperator[i].value;
78
	        	    if (searchValue != "") {
79
	        	    	submitFormObj.query.value += 
80
		        	    	"<condition " +
81
			        		"type='" + searchClass + "' " +
82
			        		"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
	        	    }
93
	        	}
94
    		}	
95
        	// Protocol
96
    		if (submitFormObj.activeProtocolsValue.value) {
97
    			var searchClass = submitFormObj.activeProtocolsClass.value;
98
        	    var searchValue = submitFormObj.activeProtocolsValue.value;
99
        	    if (searchValue!="") {
100
        	    	submitFormObj.query.value += 
101
	        	    	"<condition " +
102
		        		"type='" + searchClass + "' " +
103
		        		"concept='" + searchValue + "' " +
104
					"/>";
105
        	    }
106
    		} 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
	        	    	submitFormObj.query.value += 
112
		        	    	"<condition " +
113
			        		"type='" + searchClass + "' " +
114
			        		"concept='" + searchValue + "' " +
115
						"/>";
116
	        	    }
117
	        	}
118
    		}	
119
        	// Measurement
120
    		if (submitFormObj.activeMeasurementsValue.value) {
121
    			var searchClass = submitFormObj.activeMeasurementsClass.value;
122
        	    var searchValue = submitFormObj.activeMeasurementsValue.value;
123
        	    if (searchValue!="") {
124
        	    	submitFormObj.query.value += 
125
	        	    	"<condition " +
126
		        		"type='" + searchClass + "' " +
127
		        		"concept='" + searchValue + "' " +
128
					"/>";
129
        	    }
130
    		} 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
	        	    	submitFormObj.query.value += 
136
		        	    	"<condition " +
137
			        		"type='" + searchClass + "' " +
138
			        		"concept='" + searchValue + "' " +
139
						"/>";
140
	        	    }
141
	        	}
142
    		}
143
        	submitFormObj.query.value += "</" + operator + ">";
144
    	submitFormObj.query.value += "</sq:query>";
145
		
146
    //alert("query: " + submitFormObj.query.value);
147

    
148
    return true;
149
}
(10-10/16)