Project

General

Profile

1 7678 leinfelder
function encodeXML(theString) {
2
	return theString.replace(/&/g, '&')
3
		.replace(/</g, '&lt;')
4
		.replace(/>/g, '&gt;')
5
		.replace(/"/g, '&quot;');
6
}
7
8 3774 leinfelder
function generateQueryString(organizationScope, anyValue, searchFields) {
9 7678 leinfelder
	// make sure it is valid XML
10
	var searchTerm = encodeXML(anyValue);
11
12 3462 leinfelder
	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 5710 leinfelder
	queryString += "<returndoctype>eml://ecoinformatics.org/eml-2.1.1</returndoctype>";
18 4505 daigle
	queryString += "<returndoctype>eml://ecoinformatics.org/eml-2.1.0</returndoctype>";
19 3462 leinfelder
	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 5816 leinfelder
	queryString += "<returnfield>dataset/title/value</returnfield>";
30 3462 leinfelder
	queryString += "<returnfield>keyword</returnfield>";
31 5816 leinfelder
	queryString += "<returnfield>keyword/value</returnfield>";
32 3462 leinfelder
	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 3774 leinfelder
	//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 7678 leinfelder
			queryString += "<value>" + searchTerm + "</value>";
45 3774 leinfelder
			queryString += "<pathexpr>" + searchFields[i] +"</pathexpr>";
46
			queryString += "</queryterm>";
47
		}
48
		queryString += "</querygroup>";
49
	}
50
	else {
51
		queryString += "<queryterm casesensitive='false' searchmode='contains'>";
52 7678 leinfelder
		queryString += "<value>" + searchTerm + "</value>";
53 3774 leinfelder
		queryString += "</queryterm>";
54
	}
55 3462 leinfelder
56 3774 leinfelder
	//now limit by the organization
57 3462 leinfelder
	queryString += "<querygroup operator='UNION'>";
58
59 3650 leinfelder
	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 3462 leinfelder
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 3477 leinfelder
	//alert('setQueryFormField');
84 3462 leinfelder
	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 3650 leinfelder
	//alert('organizationScopeField=' + organizationScopeField.value);
90 3774 leinfelder
	var searchAll = document.getElementById("searchAll");
91
	//alert('searchAll=' + searchAll.checked);
92 3462 leinfelder
93 3774 leinfelder
	//make the array for organization
94 3650 leinfelder
	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 3774 leinfelder
	//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 5816 leinfelder
		searchFieldArray[counter++] = "abstract/para/value";
109 3774 leinfelder
		searchFieldArray[counter++] = "surName";
110
		searchFieldArray[counter++] = "givenName";
111
		searchFieldArray[counter++] = "organizationName";
112
		searchFieldArray[counter++] = "title";
113 5816 leinfelder
		searchFieldArray[counter++] = "title/value";
114 3774 leinfelder
		searchFieldArray[counter++] = "keyword";
115 5816 leinfelder
		searchFieldArray[counter++] = "keyword/value";
116 3774 leinfelder
		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 3778 tao
		searchFieldArray[counter++] = "placekey";
127 3774 leinfelder
	}
128
129
	//generate the query
130 3462 leinfelder
	queryField.value =
131
		generateQueryString(
132 3650 leinfelder
			orgArray,
133 3774 leinfelder
			anyfieldField.value,
134
			searchFieldArray);
135 3462 leinfelder
136 3477 leinfelder
	//alert(queryField.value);
137 3462 leinfelder
}
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
}