Project

General

Profile

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

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

    
124
function setBrowseAll() {
125
	//set the field to wildcard
126
	var anyfieldField = document.getElementById("anyfield");
127
	anyfieldField.value = "";
128
	
129
	//set the query
130
	setQueryFormField();
131
}
(31-31/38)