Project

General

Profile

1
function encodeXML(theString) {
2
	return theString.replace(/&/g, '&')
3
		.replace(/</g, '&lt;')
4
		.replace(/>/g, '&gt;')
5
		.replace(/"/g, '&quot;');
6
}
7

    
8
function generateQueryString(organizationScope, anyValue, searchFields) {
9
	// make sure it is valid XML
10
	var searchTerm = encodeXML(anyValue);
11
	
12
	var queryString = ""; 
13
	queryString += "<pathquery version='1.2'>";
14
	queryString += "<returndoctype>metadata</returndoctype>";
15
	queryString += "<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN</returndoctype>";
16
	queryString += "<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta4//EN</returndoctype>";
17
	queryString += "<returndoctype>eml://ecoinformatics.org/eml-2.1.1</returndoctype>";
18
	queryString += "<returndoctype>eml://ecoinformatics.org/eml-2.1.0</returndoctype>";
19
	queryString += "<returndoctype>eml://ecoinformatics.org/eml-2.0.1</returndoctype>";
20
	queryString += "<returndoctype>eml://ecoinformatics.org/eml-2.0.0</returndoctype>";
21
	queryString += "<returndoctype>-//NCEAS//eml-dataset-2.0//EN</returndoctype>";
22
	queryString += "<returndoctype>-//NCEAS//resource//EN</returndoctype>";
23
	queryString += "<returnfield>originator/individualName/surName</returnfield>";
24
	queryString += "<returnfield>originator/individualName/givenName</returnfield>";
25
	queryString += "<returnfield>originator/organizationName</returnfield>";
26
	queryString += "<returnfield>creator/individualName/surName</returnfield>";
27
	queryString += "<returnfield>creator/organizationName</returnfield>";
28
	queryString += "<returnfield>dataset/title</returnfield>";
29
	queryString += "<returnfield>dataset/title/value</returnfield>";
30
	queryString += "<returnfield>keyword</returnfield>";
31
	queryString += "<returnfield>keyword/value</returnfield>";
32
	queryString += "<returnfield>creator/individualName/givenName</returnfield>";
33
	queryString += "<returnfield>idinfo/citation/citeinfo/title</returnfield>";
34
	queryString += "<returnfield>idinfo/citation/citeinfo/origin</returnfield>";
35
	queryString += "<returnfield>idinfo/keywords/theme/themekey</returnfield>";
36
	
37
	queryString += "<querygroup operator='INTERSECT'>";
38
	
39
	//search particular fields, or all?
40
	if (searchFields.length > 0) {
41
		queryString += "<querygroup operator='UNION'>";
42
		for (var i = 0; i < searchFields.length; i++) {
43
			queryString += "<queryterm casesensitive='false' searchmode='contains'>";
44
			queryString += "<value>" + searchTerm + "</value>";
45
			queryString += "<pathexpr>" + searchFields[i] +"</pathexpr>";
46
			queryString += "</queryterm>";
47
		}
48
		queryString += "</querygroup>";
49
	}
50
	else {
51
		queryString += "<queryterm casesensitive='false' searchmode='contains'>";
52
		queryString += "<value>" + searchTerm + "</value>";
53
		queryString += "</queryterm>";
54
	}
55
	
56
	//now limit by the organization
57
	queryString += "<querygroup operator='UNION'>";
58
	
59
	for (var i = 0; i < organizationScope.length; i++) {
60
		queryString += "<queryterm casesensitive='false' searchmode='contains'>";
61
		queryString += "<value>" + organizationScope[i] + "</value>";
62
		queryString += "<pathexpr>placekey</pathexpr>";
63
		queryString += "</queryterm>";
64
		
65
		queryString += "<queryterm casesensitive='false' searchmode='contains'>";
66
		queryString += "<value>" + organizationScope[i] + "</value>";
67
		queryString += "<pathexpr>keyword</pathexpr>";
68
		queryString += "</queryterm>";
69
	}
70
	
71
	queryString += "</querygroup>";
72
	
73
	queryString += "</querygroup>";
74
	
75
	queryString += "</pathquery>";
76
	
77
	//alert(queryString);
78
	
79
	return queryString;
80
}
81

    
82
function setQueryFormField() {
83
	//alert('setQueryFormField');
84
	var queryField = document.getElementById("query");
85
	//alert('queryField=' + queryField);
86
	var anyfieldField = document.getElementById("anyfield");
87
	//alert('anyfieldField=' + anyfieldField);
88
	var organizationScopeField = document.getElementById("organizationScope");
89
	//alert('organizationScopeField=' + organizationScopeField.value);
90
	var searchAll = document.getElementById("searchAll");
91
	//alert('searchAll=' + searchAll.checked);
92
	
93
	//make the array for organization
94
	var orgArray = new Array();
95
	orgArray[0] = organizationScopeField.value;
96
	//if "All", include multiple entries
97
	if (organizationScopeField.value == '') {
98
		orgArray[0] = "SANParks, South Africa";
99
		orgArray[1] = "SAEON, South Africa";
100
	}
101
	
102
	//make the array for paths to search
103
	var searchFieldArray = new Array();
104
	if (!searchAll.checked) {
105
		var counter = 0;
106
		//EML fields
107
		searchFieldArray[counter++] = "abstract/para";
108
		searchFieldArray[counter++] = "abstract/para/value";
109
		searchFieldArray[counter++] = "surName";
110
		searchFieldArray[counter++] = "givenName";
111
		searchFieldArray[counter++] = "organizationName";		
112
		searchFieldArray[counter++] = "title";
113
		searchFieldArray[counter++] = "title/value";
114
		searchFieldArray[counter++] = "keyword";
115
		searchFieldArray[counter++] = "keyword/value";
116
		searchFieldArray[counter++] = "para";
117
		searchFieldArray[counter++] = "geographicDescription";
118
		searchFieldArray[counter++] = "literalLayout";
119
		searchFieldArray[counter++] = "@packageId";
120
		
121
		//FGDC fields
122
		searchFieldArray[counter++] = "abstract";
123
		searchFieldArray[counter++] = "idinfo/citation/citeinfo/title";
124
		searchFieldArray[counter++] = "idinfo/citation/citeinfo/origin";
125
		searchFieldArray[counter++] = "idinfo/keywords/theme/themekey";
126
		searchFieldArray[counter++] = "placekey";
127
	}
128
	
129
	//generate the query
130
	queryField.value = 
131
		generateQueryString(
132
			orgArray,
133
			anyfieldField.value,
134
			searchFieldArray);
135
	
136
	//alert(queryField.value);
137
}
138

    
139
function setBrowseAll() {
140
	//set the field to wildcard
141
	var anyfieldField = document.getElementById("anyfield");
142
	anyfieldField.value = "";
143
	
144
	//set the query
145
	setQueryFormField();
146
}
(26-26/36)