Project

General

Profile

1 3777 leinfelder
function generateQueryString(organizationScope, anyValue, searchFields) {
2 3640 leinfelder
	var queryString = "";
3
	queryString += "<pathquery version='1.2'>";
4
	queryString += "<returndoctype>metadata</returndoctype>";
5
	queryString += "<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN</returndoctype>";
6
	queryString += "<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta4//EN</returndoctype>";
7
	queryString += "<returndoctype>eml://ecoinformatics.org/eml-2.0.1</returndoctype>";
8
	queryString += "<returndoctype>eml://ecoinformatics.org/eml-2.0.0</returndoctype>";
9
	queryString += "<returndoctype>-//NCEAS//eml-dataset-2.0//EN</returndoctype>";
10
	queryString += "<returndoctype>-//NCEAS//resource//EN</returndoctype>";
11
	queryString += "<returnfield>originator/individualName/surName</returnfield>";
12
	queryString += "<returnfield>originator/individualName/givenName</returnfield>";
13
	queryString += "<returnfield>originator/organizationName</returnfield>";
14
	queryString += "<returnfield>creator/individualName/surName</returnfield>";
15
	queryString += "<returnfield>creator/organizationName</returnfield>";
16
	queryString += "<returnfield>dataset/title</returnfield>";
17
	queryString += "<returnfield>keyword</returnfield>";
18
	queryString += "<returnfield>creator/individualName/givenName</returnfield>";
19
	queryString += "<returnfield>idinfo/citation/citeinfo/title</returnfield>";
20
	queryString += "<returnfield>idinfo/citation/citeinfo/origin</returnfield>";
21
	queryString += "<returnfield>idinfo/keywords/theme/themekey</returnfield>";
22
23
	queryString += "<querygroup operator='INTERSECT'>";
24
25 3777 leinfelder
	//search particular fields, or all?
26
	if (searchFields.length > 0) {
27
		queryString += "<querygroup operator='UNION'>";
28
		for (var i = 0; i < searchFields.length; i++) {
29
			queryString += "<queryterm casesensitive='false' searchmode='contains'>";
30
			queryString += "<value>" + anyValue + "</value>";
31
			queryString += "<pathexpr>" + searchFields[i] +"</pathexpr>";
32
			queryString += "</queryterm>";
33
		}
34
		queryString += "</querygroup>";
35
	}
36
	else {
37
		queryString += "<queryterm casesensitive='false' searchmode='contains'>";
38
		queryString += "<value>" + anyValue + "</value>";
39
		queryString += "</queryterm>";
40
	}
41 3640 leinfelder
42 3777 leinfelder
	//now limit by the organization
43 3640 leinfelder
	queryString += "<querygroup operator='UNION'>";
44
45 3650 leinfelder
	for (var i = 0; i < organizationScope.length; i++) {
46
		queryString += "<queryterm casesensitive='false' searchmode='contains'>";
47
		queryString += "<value>" + organizationScope[i] + "</value>";
48
		queryString += "<pathexpr>placekey</pathexpr>";
49
		queryString += "</queryterm>";
50
51
		queryString += "<queryterm casesensitive='false' searchmode='contains'>";
52
		queryString += "<value>" + organizationScope[i] + "</value>";
53
		queryString += "<pathexpr>keyword</pathexpr>";
54
		queryString += "</queryterm>";
55
	}
56 3640 leinfelder
57
	queryString += "</querygroup>";
58
59
	queryString += "</querygroup>";
60
61
	queryString += "</pathquery>";
62
63
	//alert(queryString);
64
65
	return queryString;
66
}
67
68
function setQueryFormField() {
69
	//alert('setQueryFormField');
70
	var queryField = document.getElementById("query");
71
	//alert('queryField=' + queryField);
72
	var anyfieldField = document.getElementById("anyfield");
73
	//alert('anyfieldField=' + anyfieldField);
74
	var organizationScopeField = document.getElementById("organizationScope");
75 3650 leinfelder
	//alert('organizationScopeField=' + organizationScopeField.value);
76 3777 leinfelder
	var searchAll = document.getElementById("searchAll");
77
	//alert('searchAll=' + searchAll.checked);
78 3640 leinfelder
79 3777 leinfelder
	//make the array for organization
80 3650 leinfelder
	var orgArray = new Array();
81
	orgArray[0] = organizationScopeField.value;
82
	//if "All", include multiple entries
83
	if (organizationScopeField.value == '') {
84
		orgArray[0] = "SANParks, South Africa";
85
		orgArray[1] = "SAEON, South Africa";
86
	}
87
88 3777 leinfelder
	//make the array for paths to search
89
	var searchFieldArray = new Array();
90
	if (!searchAll.checked) {
91
		var counter = 0;
92
		//EML fields
93
		searchFieldArray[counter++] = "abstract/para";
94
		searchFieldArray[counter++] = "surName";
95
		searchFieldArray[counter++] = "givenName";
96
		searchFieldArray[counter++] = "organizationName";
97
		searchFieldArray[counter++] = "title";
98
		searchFieldArray[counter++] = "keyword";
99
		searchFieldArray[counter++] = "para";
100
		searchFieldArray[counter++] = "geographicDescription";
101
		searchFieldArray[counter++] = "literalLayout";
102
		searchFieldArray[counter++] = "@packageId";
103
104
		//FGDC fields
105
		searchFieldArray[counter++] = "abstract";
106
		searchFieldArray[counter++] = "idinfo/citation/citeinfo/title";
107
		searchFieldArray[counter++] = "idinfo/citation/citeinfo/origin";
108
		searchFieldArray[counter++] = "idinfo/keywords/theme/themekey";
109 3790 leinfelder
		searchFieldArray[counter++] = "placekey";
110 3777 leinfelder
	}
111
112
	//generate the query
113 3640 leinfelder
	queryField.value =
114
		generateQueryString(
115 3650 leinfelder
			orgArray,
116 3777 leinfelder
			anyfieldField.value,
117
			searchFieldArray);
118 3640 leinfelder
119
	//alert(queryField.value);
120
}
121
122
function setBrowseAll() {
123
	//set the field to wildcard
124
	var anyfieldField = document.getElementById("anyfield");
125
	anyfieldField.value = "";
126
127
	//set the query
128
	setQueryFormField();
129
}