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:

lib/style/skins/nceas/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
}
lib/style/skins/nceas/index.jsp
38 38
  <script language="JavaScript" type="text/JavaScript"
39 39
          src="<%=STYLE_SKINS_URL%>/nceas/nceas.js"></script>
40 40
  <script language="JavaScript" type="text/JavaScript"
41
          src="<%=STYLE_COMMON_URL%>/branding.js"></script>
41
          src="<%=STYLE_COMMON_URL%>/branding.js"></script>           
42 42
  <script type="text/javascript" 
43 43
          src="<%=STYLE_SKINS_URL%>/nceas/navigation.js"></script>
44 44
  <script type="text/javascript"
......
78 78
  <tr class="sectheader">
79 79
    <td class="borderbottom"><a name="search" ></a>
80 80
        <p align="center" class="largetext"> Search for Data Sets </p></td>
81
  </tr> 
82
  <tr>
83
    <td align="left">
84
    	<form id="searchForm" name="searchForm"
85
    		action="javascript:doSearch('<%=CONTEXT_URL%>/d1/mn/v1/query/solr', 'searchForm', true)" >
86
	        <div class="searchresultsdividerPale">
87
	        <p>
88
				&nbsp;
89
		        <input size="14" name="searchstring" type="text" value="" id="searchBox">
90
		        <input name="qformat" value="nceas" type="hidden">
91
		        <input value="Search" type="submit">
92
		        </p>
93
	        </div>
94
        </form> 
95
      </td>
81 96
  </tr>
82
  <tr class="sectbody"></tr>
83
 
84 97
  <tr >
85
    <td align="left">
86
    <form method="POST" 
87
    	action="<%=SERVLET_URL%>" target="_top"
88
    	id="searchForm" name="searchForm" 
89
    	onSubmit="return checkSearch(this)">
90
        <div class="searchresultsdividerPale">
91
        <p>
92
        <input value="UNION" name="operator" type="hidden">
93
&nbsp;
94
        <input size="14" name="searchstring" type="text" value="" id="searchBox">
95
        <input name="query" type="hidden">
96
        <input name="qformat" value="nceas" type="hidden">
97
        <input name="enableediting" value="true" type="hidden">
98
        <input type="hidden" name="action" value="squery">
99
        <input value="Search" type="submit">
100
        </p>
101
        <p>
102
        <input name="search" type="radio" checked>
103
        Search Title, Abstract, Keywords, Personnel (Quicker) <br>
104
        <input name="search" type="radio" id="searchAll">
105
        Search all fields (Slower) <br>
106
        </p>
107
        </div>
108
        </form> 
109
        <div align="center">
110
          <p align="left">This tool allows you to search the registry for data sets of interest. When you type text in the box and click on the "Search" button, the search will only be conducted within the title, author, abstract, and keyword fields. Checking the "Search All Fields" box will search on these and all other existing fields (this search will take more time). <br>
111
                <br>
98
    <td class="borderbottom">
99
		<div align="center">
100
          <p align="left">
112 101
          You can use the '%' character as a wildcard in your searches (e.g., '%biodiversity%' would locate any phrase with the word biodiversity embedded within it). </p>
113
      </div></td>
102
		</div>
103
		<div align="center">
104
	    	<a href="javascript:doSearch('<%=CONTEXT_URL%>/d1/mn/v1/query/solr', 'searchForm', true)">Browse existing NCEAS data sets</a>
105
			<br/><br/>
106
			<a href="<%=STYLE_SKINS_URL%>/nceas/map.jsp"> View Interactive Map </a>
107
		</div>
108
	</td>
114 109
  </tr>
115
  <tr >
116
    <td class="borderbottom"><div align="center">
117
    	<a href="javascript:browseAll('searchForm')">Browse existing NCEAS data sets</a>
118
<br/><br/>
119
<a href="<%=STYLE_SKINS_URL%>/nceas/map.jsp"> View Interactive Map </a> </div>
120
</td></tr></table>
110
</table>
111

  
121 112
<br><br>
113

  
122 114
<table class="tables regular" cellpadding="8" cellspacing="0">
123 115
  <tr class="sectheader">
124 116
    <td class="borderbottom" colspan="2" align="left"><span class="label"> </span>

Also available in: Unified diff