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
						"operator='" + dataOperator + "'>" +
64
						dataValue +
65
					"</condition>";
66
        	    }
67
    		} else {
68
	        	for (var i=0; i < submitFormObj.activeCharacteristicsValue.length; i++) {
69
	        		var searchClass = submitFormObj.activeCharacteristicsClass[i].value;
70
	        	    var searchValue = submitFormObj.activeCharacteristicsValue[i].value;
71
	        	    var dataValue = submitFormObj.dataValue[i].value;
72
	        	    var dataOperator = submitFormObj.dataOperator[i].value;
73
	        	    if (searchValue!="") {
74
	        	    	submitFormObj.query.value += 
75
		        	    	"<condition " +
76
			        		"type='" + searchClass + "' " +
77
			        		"concept='" + searchValue + "' " +
78
							"operator='" + dataOperator + "'>" +
79
							dataValue +
80
						"</condition>";
81
	        	    }
82
	        	}
83
    		}	
84
        	// Protocol
85
    		if (submitFormObj.activeProtocolsValue.value) {
86
    			var searchClass = submitFormObj.activeProtocolsClass.value;
87
        	    var searchValue = submitFormObj.activeProtocolsValue.value;
88
        	    if (searchValue!="") {
89
        	    	submitFormObj.query.value += 
90
	        	    	"<condition " +
91
		        		"type='" + searchClass + "' " +
92
		        		"concept='" + searchValue + "' " +
93
					"/>";
94
        	    }
95
    		} else {
96
	        	for (var i=0; i < submitFormObj.activeProtocolsValue.length; i++) {
97
	        		var searchClass = submitFormObj.activeProtocolsClass[i].value;
98
	        	    var searchValue = submitFormObj.activeProtocolsValue[i].value;
99
	        	    if (searchValue!="") {
100
	        	    	submitFormObj.query.value += 
101
		        	    	"<condition " +
102
			        		"type='" + searchClass + "' " +
103
			        		"concept='" + searchValue + "' " +
104
						"/>";
105
	        	    }
106
	        	}
107
    		}	
108
        	// Measurement
109
    		if (submitFormObj.activeMeasurementsValue.value) {
110
    			var searchClass = submitFormObj.activeMeasurementsClass.value;
111
        	    var searchValue = submitFormObj.activeMeasurementsValue.value;
112
        	    if (searchValue!="") {
113
        	    	submitFormObj.query.value += 
114
	        	    	"<condition " +
115
		        		"type='" + searchClass + "' " +
116
		        		"concept='" + searchValue + "' " +
117
					"/>";
118
        	    }
119
    		} else {
120
	        	for (var i=0; i < submitFormObj.activeMeasurementsValue.length; i++) {
121
	        		var searchClass = submitFormObj.activeMeasurementsClass[i].value;
122
	        	    var searchValue = submitFormObj.activeMeasurementsValue[i].value;
123
	        	    if (searchValue!="") {
124
	        	    	submitFormObj.query.value += 
125
		        	    	"<condition " +
126
			        		"type='" + searchClass + "' " +
127
			        		"concept='" + searchValue + "' " +
128
						"/>";
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)