forked from bcfuchs/uredb_website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.gsp
182 lines (160 loc) · 6.98 KB
/
index.gsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<%@ page defaultCodec="html" %>
<%@ page import="org.springframework.util.ClassUtils" %>
<%@ page import="grails.plugin.searchable.internal.lucene.LuceneUtils" %>
<%@ page import="grails.plugin.searchable.internal.util.StringQueryUtils" %>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title><g:if test="${params.q && params.q?.trim() != ''}">${params.q} - </g:if>Grails Searchable Plugin</title>
<style type="text/css">
* {
font-family: Arial, sans-serif;
padding: 0;
margin: 0;
}
body {
font-size: 0.9em;
padding: .5em;
}
#header form input {
padding: .1em;
}
#header .hint {
color: gray;
}
#header h1 a {
text-decoration: none;
font-family: Georgia, serif;
color: dimgray;
}
#header h1 {
letter-spacing: -0.1em;
float: left;
}
#header h1 span {
font-family: Georgia, serif;
color: #424242;
}
#header form {
margin-left: 22em;
padding-top: .1em;
}
.title {
margin: 1em 0;
padding: .3em .5em;
text-align: right;
background-color: seashell;
border-top: 1px solid lightblue;
}
.result {
margin-bottom: 1em;
}
.result .displayLink {
color: green;
}
.result .name {
font-size: larger;
}
.paging a.step {
padding: 0 .3em;
}
.paging span.currentStep {
font-weight: bold;
}
ul {
margin: 1em 2em;
}
li, p {
margin-bottom: 1em;
}
#searchable-title {
}
</style>
<script type="text/javascript">
var focusQueryInput = function() {
document.getElementById("q").focus();
}
</script>
</head>
<body onload="focusQueryInput();">
<div id="header">
<h1><a href="http://grails.org/Searchable+Plugin" target="_blank">Grails <span>Searchable</span> Plugin</a></h1>
<g:form url='[controller: "searchable", action: "index"]' id="searchableForm" name="searchableForm" method="get">
<g:textField name="q" value="${params.q}" size="50"/> <input type="submit" value="Search" />
</g:form>
<div style="clear: both; display: none;" class="hint">See <a href="http://lucene.apache.org/java/docs/queryparsersyntax.html">Lucene query syntax</a> for advanced queries</div>
</div>
<div id="main">
<g:set var="haveQuery" value="${params.q?.trim()}" />
<g:set var="haveResults" value="${searchResult?.results}" />
<div class="title" id="searchable-title">
<span>
<g:if test="${haveQuery && haveResults}">
Showing <strong>${searchResult.offset + 1}</strong> - <strong>${searchResult.results.size() + searchResult.offset}</strong> of <strong>${searchResult.total}</strong>
results for <strong>${params.q}</strong>
</g:if>
<g:else>
</g:else>
</span>
</div>
<g:if test="${haveQuery && !haveResults && !parseException}">
<p>Nothing matched your query - <strong>${params.q}</strong></p>
<g:if test="${!searchResult?.suggestedQuery}">
<p>Suggestions:</p>
<ul>
<li>Try a suggested query: <g:link controller="searchable" action="index" params="[q: params.q, suggestQuery: true]">Search again with the <strong>suggestQuery</strong> option</g:link><br />
<em>Note: Suggestions are only available when classes are mapped with <strong>spellCheck</strong> options, either at the class or property level.<br />
The simplest way to do this is add <strong>spellCheck "include"</strong> to the domain class searchable mapping closure.<br />
See the plugin/Compass documentation Mapping sections for details.</em>
</li>
</ul>
</g:if>
</g:if>
<g:if test="${searchResult?.suggestedQuery}">
<p>Did you mean <g:link controller="searchable" action="index" params="[q: searchResult.suggestedQuery]">${StringQueryUtils.highlightTermDiffs(params.q.trim(), searchResult.suggestedQuery)}</g:link>?</p>
</g:if>
<g:if test="${parseException}">
<p>Your query - <strong>${params.q}</strong> - is not valid.</p>
<p>Suggestions:</p>
<ul>
<li>Fix the query: see <a href="http://lucene.apache.org/java/docs/queryparsersyntax.html">Lucene query syntax</a> for examples</li>
<g:if test="${LuceneUtils.queryHasSpecialCharacters(params.q)}">
<li>Remove special characters like <strong>" - [ ]</strong>, before searching, eg, <em><strong>${LuceneUtils.cleanQuery(params.q)}</strong></em><br />
<em>Use the Searchable Plugin's <strong>LuceneUtils#cleanQuery</strong> helper method for this: <g:link controller="searchable" action="index" params="[q: LuceneUtils.cleanQuery(params.q)]">Search again with special characters removed</g:link></em>
</li>
<li>Escape special characters like <strong>" - [ ]</strong> with <strong>\</strong>, eg, <em><strong>${LuceneUtils.escapeQuery(params.q)}</strong></em><br />
<em>Use the Searchable Plugin's <strong>LuceneUtils#escapeQuery</strong> helper method for this: <g:link controller="searchable" action="index" params="[q: LuceneUtils.escapeQuery(params.q)]">Search again with special characters escaped</g:link></em><br />
<em>Or use the Searchable Plugin's <strong>escape</strong> option: <g:link controller="searchable" action="index" params="[q: params.q, escape: true]">Search again with the <strong>escape</strong> option enabled</g:link></em>
</li>
</g:if>
</ul>
</g:if>
<g:if test="${haveResults}">
<div class="results">
<g:each var="result" in="${searchResult.results}" status="index">
<div class="result">
<g:set var="className" value="${ClassUtils.getShortName(result.getClass())}" />
<g:set var="link" value="${createLink(controller: className[0].toLowerCase() + className[1..-1], action: 'show', id: result.id)}" />
<div class="name"><a href="${link}">${className} #${result.id}</a></div>
<g:set var="desc" value="${result.toString()}" />
<g:if test="${desc.size() > 120}"><g:set var="desc" value="${desc[0..120] + '...'}" /></g:if>
<div class="desc">${desc.encodeAsHTML()}</div>
<div class="displayLink">${link}</div>
</div>
</g:each>
</div>
<div>
<div class="paging">
<g:if test="${haveResults}">
Page:
<g:set var="totalPages" value="${Math.ceil(searchResult.total / searchResult.max)}" />
<g:if test="${totalPages == 1}"><span class="currentStep">1</span></g:if>
<g:else><g:paginate controller="searchable" action="index" params="[q: params.q]" total="${searchResult.total}" prev="< previous" next="next >"/></g:else>
</g:if>
</div>
</div>
</g:if>
</div>
</body>
</html>