Project

General

Profile

« Previous | Next » 

Revision 7656

Use solr query instead of path query in the NCEAS skin. https://projects.ecoinformatics.org/ecoinfo/issues/5917

View differences:

search.js
1
function trim(stringToTrim) {
2
    return stringToTrim.replace(/^\s*/, '').replace(/\s*$/,'');
1
/**
2
 * Performs the search 
3
 */
4
function doSearch(serviceURL, searchFormId, browseAll) {
5
	var solrQuery = getSolrQuery(searchFormId);
6
	//alert(solrQuery);
7
	var url = serviceURL + "/" + solrQuery;
8
	// go directly there!
9
	document.location = url;
3 10
}
4 11

  
5
function checkSearch(submitFormObj) {
12
/**
13
 * Constructs the SOLR query to use
14
 */
15
function getSolrQuery(searchFormId, browseAll) {
16
	var submitFormObj = document.getElementById(searchFormId);
6 17
    var searchString = trim(submitFormObj.searchstring.value);
7
    var checkBox = document.getElementById("searchAll");
18
    if (browseAll) {
19
    	searchString = "";
20
    }
21
    var qformat = submitFormObj.qformat.value;
8 22

  
9 23
    if (searchString=="") {
10 24
        if (confirm("Show *all* data?")) {
11
            searchString = "%";
25
            searchString = "*";
12 26
        } else {
13 27
            return false;
14 28
        }
15 29
    }
16 30

  
17
    if (!checkBox.checked && searchString!="%") {
18
        submitFormObj.query.value = "<pathquery version=\"1.2\">"
19
            +"<querytitle>Web-Search</querytitle>"
20
            +"<returndoctype>eml://ecoinformatics.org/eml-2.1.1</returndoctype>"
21
            +"<returndoctype>eml://ecoinformatics.org/eml-2.1.0</returndoctype>"
22
            +"<returndoctype>eml://ecoinformatics.org/eml-2.0.1</returndoctype>"
23
            +"<returndoctype>eml://ecoinformatics.org/eml-2.0.0</returndoctype>"
24
            +"<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN</returndoctype>"
25
            +"<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta4//EN</returndoctype>"
26
            +"<returndoctype>-//NCEAS//resource//EN</returndoctype>"
27
            +"<returndoctype>-//NCEAS//eml-dataset//EN</returndoctype>"
28
            +"<returndoctype>metadata</returndoctype>"
29
            +"<returnfield>originator/individualName/surName</returnfield>"
30
            +"<returnfield>originator/individualName/givenName</returnfield>"
31
            +"<returnfield>creator/individualName/surName</returnfield>"
32
            +"<returnfield>creator/individualName/givenName</returnfield>"
33
            +"<returnfield>originator/organizationName</returnfield>"
34
            +"<returnfield>creator/organizationName</returnfield>"
35
            +"<returnfield>dataset/title</returnfield>"
36
            +"<returnfield>dataset/title/value</returnfield>"
37
            +"<returnfield>keyword</returnfield>"
38
            +"<returnfield>keyword/value</returnfield>"
39
            //fgdc fields
40
            +"<returnfield>idinfo/citation/citeinfo/title</returnfield>"
41
            +"<returnfield>idinfo/citation/citeinfo/origin</returnfield>"
42
			+"<returnfield>idinfo/keywords/theme/themekey</returnfield>"
43
            +"<querygroup operator=\"INTERSECT\">"
44
            	+"<querygroup operator=\"UNION\">"
45
	                +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
46
	                    +"<value>National Center for Ecological Analysis and Synthesis</value>"
47
	                    +"<pathexpr>organizationName</pathexpr>"
48
	                +"</queryterm>"
49
	                +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
50
	                    //+"<value>%</value>"
51
	                    +"<value>National Center for Ecological Analysis and Synthesis</value>"	                    
52
	                    +"<pathexpr>placekey</pathexpr>"
53
	                +"</queryterm>"
54
                +"</querygroup>"
55
                +"<querygroup operator=\"UNION\">"
56
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
57
                        +"<value>" + searchString + "</value>"
58
                        +"<pathexpr>surName</pathexpr>"
59
                    +"</queryterm>"
60
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
61
                        +"<value>" + searchString + "</value>"
62
                        +"<pathexpr>givenName</pathexpr>"
63
                    +"</queryterm>"
64
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
65
                        +"<value>" + searchString + "</value>"
66
                        +"<pathexpr>keyword</pathexpr>"
67
                    +"</queryterm>"
68
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
69
	                    +"<value>" + searchString + "</value>"
70
	                    +"<pathexpr>keyword/value</pathexpr>"
71
	                +"</queryterm>"
72
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
73
                        +"<value>" + searchString + "</value>"
74
                        +"<pathexpr>para</pathexpr>"
75
                    +"</queryterm>"
76
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
77
                        +"<value>" + searchString + "</value>"
78
                        +"<pathexpr>geographicDescription</pathexpr>"
79
                    +"</queryterm>"
80
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
81
                        +"<value>" + searchString + "</value>"
82
                        +"<pathexpr>literalLayout</pathexpr>"
83
                    +"</queryterm>"
84
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
85
                        +"<value>" + searchString + "</value>"
86
                        +"<pathexpr>title</pathexpr>"
87
                    +"</queryterm>"
88
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
89
	                    +"<value>" + searchString + "</value>"
90
	                    +"<pathexpr>title/value</pathexpr>"
91
	                +"</queryterm>"
92
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
93
                        +"<value>" + searchString + "</value>"
94
                        +"<pathexpr>@packageId</pathexpr>"
95
                    +"</queryterm>"
96
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
97
                        +"<value>" + searchString + "</value>"
98
                        +"<pathexpr>abstract/para</pathexpr>"
99
                    +"</queryterm>"
100
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
101
	                    +"<value>" + searchString + "</value>"
102
	                    +"<pathexpr>abstract/para/value</pathexpr>"
103
	                +"</queryterm>"
104
                    
105
                    //FGDC fields
106
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
107
                        +"<value>" + searchString + "</value>"
108
                        +"<pathexpr>abstract</pathexpr>"
109
                    +"</queryterm>"
110
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
111
                        +"<value>" + searchString + "</value>"
112
                        +"<pathexpr>idinfo/citation/citeinfo/title</pathexpr>"
113
                    +"</queryterm>"
114
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
115
                        +"<value>" + searchString + "</value>"
116
                        +"<pathexpr>idinfo/citation/citeinfo/origin</pathexpr>"
117
                    +"</queryterm>"
118
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
119
                        +"<value>" + searchString + "</value>"
120
                        +"<pathexpr>idinfo/keywords/theme/themekey</pathexpr>"
121
                    +"</queryterm>"
122
                    +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
123
                        +"<value>" + searchString + "</value>"
124
                        +"<pathexpr>placekey</pathexpr>"
125
                    +"</queryterm>"
126
                +"</querygroup>"
127
            +"</querygroup>"
128
            +"</pathquery>";
129

  
130
    } else {
131
        queryTermString = "";
132
        if (searchString != "%"){
133
            queryTermString = "<queryterm searchmode=\"contains\" casesensitive=\"false\">"
134
                                  +"<value>" + searchString + "</value>"
135
                              +"</queryterm>";
136
        }
137
        submitFormObj.query.value = "<pathquery version=\"1.2\">"
138
            +"<querytitle>Web-Search</querytitle>"
139
            +"<returndoctype>eml://ecoinformatics.org/eml-2.1.1</returndoctype>"
140
            +"<returndoctype>eml://ecoinformatics.org/eml-2.1.0</returndoctype>"
141
            +"<returndoctype>eml://ecoinformatics.org/eml-2.0.1</returndoctype>"
142
            +"<returndoctype>eml://ecoinformatics.org/eml-2.0.0</returndoctype>"
143
            +"<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN</returndoctype>"
144
            +"<returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta4//EN</returndoctype>"
145
            +"<returndoctype>-//NCEAS//resource//EN</returndoctype>"
146
            +"<returndoctype>-//NCEAS//eml-dataset//EN</returndoctype>"
147
            +"<returndoctype>metadata</returndoctype>"
148
            +"<returnfield>originator/individualName/surName</returnfield>"
149
            +"<returnfield>originator/individualName/givenName</returnfield>"
150
            +"<returnfield>creator/individualName/surName</returnfield>"
151
            +"<returnfield>creator/individualName/givenName</returnfield>"
152
            +"<returnfield>originator/organizationName</returnfield>"
153
            +"<returnfield>creator/organizationName</returnfield>"
154
            +"<returnfield>dataset/title</returnfield>"
155
            +"<returnfield>dataset/title/value</returnfield>"
156
            +"<returnfield>keyword</returnfield>"
157
            +"<returnfield>keyword/value</returnfield>"
158
            //fgdc fields
159
            +"<returnfield>idinfo/citation/citeinfo/title</returnfield>"
160
            +"<returnfield>idinfo/citation/citeinfo/origin</returnfield>"
161
			+"<returnfield>idinfo/keywords/theme/themekey</returnfield>"
162
            +"<querygroup operator=\"INTERSECT\">"
163
                +"<querygroup operator=\"UNION\">"
164
	                +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
165
	                    +"<value>National Center for Ecological Analysis and Synthesis</value>"
166
	                    +"<pathexpr>organizationName</pathexpr>"
167
	                +"</queryterm>"
168
	                +"<queryterm searchmode=\"contains\" casesensitive=\"false\">"
169
	                    //+"<value>%</value>"
170
	                    +"<value>National Center for Ecological Analysis and Synthesis</value>"	                    
171
	                    +"<pathexpr>placekey</pathexpr>"
172
	                +"</queryterm>"
173
                +"</querygroup>"
174
                + queryTermString
175
            +"</querygroup>"
176
            +"</pathquery>";
177

  
178
    }
179
    return true;
31
    var formats = 
32
    	"("
33
        +"formatId: \"eml\\://ecoinformatics.org/eml-2.1.1\""
34
        +" OR "
35
        +"formatId: \"eml\\://ecoinformatics.org/eml-2.1.0\""
36
        +" OR "
37
        +"formatId: \"eml\\://ecoinformatics.org/eml-2.0.1\""
38
        +" OR "
39
        +"formatId: \"eml\\://ecoinformatics.org/eml-2.0.0\""
40
        +" OR "
41
        +"formatId: \"-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN\""
42
        +" OR "
43
        +"formatId: \"-//ecoinformatics.org//eml-dataset-2.0.0beta4//EN\""
44
        +" OR "
45
        +"formatId: \"-//NCEAS//resource//EN\""
46
        +" OR "
47
        +"formatId: \"-//NCEAS//eml-dataset//EN\""
48
        +" OR "
49
        +"formatId: \"metadata\""
50
    	+")";
51
    
52
	var solrQuery = "q="
53
		+ searchString
54
		+" AND "
55
    	+ formats
56
    	+" AND "         
57
    	+"("
58
            +"contactOrganization: \"National Center for Ecological Analysis and Synthesis\""	                    
59
        +")"
60
        +"&wt=" + qformat;
61
    	
62
    	solrQuery = encodeURIComponent(solrQuery);
63
    
64
    return solrQuery;
180 65
}
181 66

  
182
function browseAll(searchFormId) {
183
	var searchForm = document.getElementById(searchFormId);
184
	var searchString = searchForm.searchstring;
185
    var checkBox = document.getElementById("searchAll");
186
    searchString.value="";
187
    checkBox.checked = true;
188
    if (checkSearch(searchForm)) {
189
		searchForm.submit();
190
	}
191

  
67
function trim(stringToTrim) {
68
    return stringToTrim.replace(/^\s*/, '').replace(/\s*$/,'');
192 69
}
193

  
194
function searchAll(){
195
    var checkBox = document.getElementById("searchCheckBox");
196
    if (checkBox.checked == true) {
197
        alert("You have selected to search all possible existing fields. This search will take longer.");
198
    }
199
}

Also available in: Unified diff