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

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

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