This repository has been archived by the owner on May 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
advancedsearch.xml
382 lines (352 loc) · 12.7 KB
/
advancedsearch.xml
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<extension>
<title>Advanced Search Extension</title>
<label>Advanced Search</label>
<description>This extension contains functions for adding advanced search functionality.</description>
<uri.help>http://developer.mindtouch.com/App_Catalog/Advanced_Search</uri.help>
<namespace>advancedSearch</namespace>
<function>
<name>form</name>
<description>Embeds an advanced search form.</description>
<param name="request" type="map" optional="true">Instance of the __request.args map (default: nil)</param>
<param name="field" type="str" optional="true">Search query field name. (default: "search")</param>
<param name="path" type="str" optional="true">Sets the value of the "located under" field. (default: nil)</param>
<param name="publish" type="str" optional="true">Publish on channel or a URI. (default: "")</param>
<param name="useStyles" type="bool" optional="true">If set to "false" then no styles are inlined allowing custom styles. (default: "true")</param>
<return>
<html xmlns:eval="http://mindtouch.com/2007/dekiscript">
<head>
<script type="text/javascript" src="/skins/common/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="/skins/common/yui/connection/connection.js"></script>
<script type="text/javascript" src="/skins/common/yui/autocomplete/autocomplete.js"></script>
<script type="text/javascript">
var GS = GS ? GS : [];
GS.buildLuceneQuery = function()
{
// build the lucene search query
// hack hack hack: prefix, suffix
var prefix = '', suffix = '', val = '';
var rSplit = /\s|%20/;
// all words
val = GS.sanitize(this.all.value);
if (val)
{
prefix += val;
}
// any words
var any = '';
val = GS.sanitize(this.any1.value);
if (val != '')
{
any += ' OR "' + val + '"';
}
val = GS.sanitize(this.any2.value);
if (val != '')
{
any += ' OR "' + val + '"';
}
val = GS.sanitize(this.any3.value);
if (val != '')
{
any += ' OR "' + val + '"';
}
if (any != '')
{
prefix += " " + any.substring(4);
}
// tags
val = GS.sanitize(this.tags.value);
if (val != '')
{
var aTags = String(val).split(rSplit);
for (var i = 0, i_m = aTags.length; i < i_m; i++)
{
suffix += ' tag:"' + aTags[i] + '"';
}
}
// not
val = GS.sanitize(this.not.value);
if (val != '')
{
// split on spaces
var aWords = String(val).split(rSplit);
for (var i = 0, i_m = aWords.length; i < i_m; i++)
{
prefix += ' -"' + GS.sanitize(aWords[i]) + '"';
}
}
// path
val = this.path ? GS.sanitize(this.path.value) : '';
if (val != '')
{
val += (val[val.length-1] != '/') ? '/*' : '*';
suffix += ' path:' + val;
}
// author
val = GS.sanitize(this.author.value);
if (val != '')
{
suffix += ' author:"' + val + '"';
}
// type
val = GS.sanitize(this.type.value);
if (val != '')
{
suffix += ' type:"' + val + '"';
}
// set the form's search field
var fieldName = this.getAttribute('field') || 'search';
this.elements[fieldName].value = jQuery.trim(prefix + suffix);
// hack hack hack: prefix, suffix
this.elements['prefix'].value = jQuery.trim(prefix);
this.elements['suffix'].value = jQuery.trim(suffix);
return !GS.publish(this);
};
// helper method for cleaning up user input
GS.sanitize = function(s)
{
return escape(jQuery.trim(s));
};
// publishes form fields on channel defined by publish attribute
// fields are namespaced by the form name if it exists
GS.publish = function(o)
{
var channel = o.getAttribute('publish') || null;
if (channel)
{
var m = {};
var namespace = o.name ? o.name + '.' : '';
DekiWiki.$(o).find('input').each(function()
{
if (DekiWiki.hasValue(this.name))
{
m[namespace + this.name] = this.value;
}
});
DekiWiki.publish(channel, m);
return true;
}
return false;
};
GS.createAutoComplete = function(elInput, elResults)
{
var oDs = new YAHOO.widget.DS_XHR('/Special:Listusers', ['results', 'user']);
oDs.scriptQueryParam = 'matchuser';
var oAc = new YAHOO.widget.AutoComplete(elInput, elResults, oDs);
oAc.minQueryLength = 2;
oAc.animVert = false;
};
</script>
<eval:if test="args.useStyles ?? true">
<style type="text/css">
form.gs-advancedSearch table th {
font-weight: bold;
}
form.gs-advancedSearch table td {
padding-left: 10px;
}
form.gs-advancedSearch input.long {
width: 95%;
}
form.gs-advancedSearch input.short,
form.gs-advancedSearch select.short {
width: 28%;
}
form.gs-advancedSearch div.submit {
padding: 10px 0;
}
form.gs-advancedSearch .autocomplete div.yui-ac-content {
position: absolute;
background-color: #fff;
border: solid 1px #999;
font-size: 10pt;
}
form.gs-advancedSearch .yui-ac-highlight {
background-color: #EEEEFF;
}
#topic form.gs-advancedSearch .autocomplete div.yui-ac-bd ul {
list-style-type: none;
padding: 0;
margin: 0;
}
#topic form.gs-advancedSearch .autocomplete div.yui-ac-bd li {
list-style-type: none;
padding: 2px;
}
</style>
</eval:if>
</head>
<body block="let isuri=string.startswith(args.publish ?? '', 'http://', true) || string.startswith(args.publish ?? '', 'https://', true) || args.publish == _ || args.publish == '';">
<noscript>Advanced Search requires JavaScript to be enabled.</noscript>
<form
method="get"
class="gs-advancedSearch"
eval:id="@formId"
eval:action="if (isuri) { args.publish ?? ''; } else { ''; }"
eval:field="args.field ?? 'search'"
eval:publish="if (!isuri) { args.publish ?? ''; } else { ''; }"
>
<input type="hidden" eval:name="args.field ?? 'search'" value="" />
<!-- hack hack hack: prefix, suffix -->
<input type="hidden" name="prefix" value="" />
<input type="hidden" name="suffix" value="" />
<table width="100%">
<colgroup>
<col width="200" />
<col width="" />
</colgroup>
<tr>
<th colspan="2">Find results that have...</th>
</tr>
<tr>
<td>all these words:</td>
<td><input type="text" class="long" name="all" eval:value="args.request.all ?? ''" /></td>
</tr>
<!--
<tr>
<td>this exact phrase:</td>
<td><input type="text" class="long" name="exact" value="" /></td>
</tr>
-->
<tr>
<td>any of these words:</td>
<td>
<input type="text" class="short" name="any1" eval:value="args.request.any1 ?? ''" /> OR
<input type="text" class="short" name="any2" eval:value="args.request.any2 ?? ''" /> OR
<input type="text" class="short" name="any3" eval:value="args.request.any3 ?? ''" />
</td>
</tr>
<tr>
<td>been tagged with:</td>
<td><input type="text" class="long" name="tags" eval:value="args.request.tags ?? ''" /></td>
</tr>
</table>
<table width="100%">
<colgroup>
<col width="200" />
<col width="" />
</colgroup>
<tr>
<th colspan="2">But also...</th>
</tr>
<tr>
<td>don't have these words:</td>
<td><input type="text" class="long" name="not" eval:value="args.request.not ?? ''" /></td>
</tr>
<tr>
<td>is located under:</td>
<td><input type="text" class="long" name="path" eval:value="args.request.path ?? args.path ?? ''" /></td>
</tr>
<tr>
<td>was authored by:</td>
<td class="autocomplete">
<input eval:id="@acId" type="text" class="short" name="author" eval:value="args.request.author ?? ''" />
<div eval:id="@acResultsId" class="results"></div>
</td>
</tr>
<tr>
<td>are only:</td>
<td>
<select name="type" class="short">
<option value="" eval:selected="args.request.type == nil ? 'selected' : nil">any type</option>
<option value="wiki" eval:selected="args.request.type == 'wiki' ? 'selected' : nil">wiki pages</option>
<option value="document" eval:selected="args.request.type == 'document' ? 'selected' : nil">documents</option>
<option value="image" eval:selected="args.request.type == 'image' ? 'selected' : nil">images</option>
</select>
</td>
</tr>
</table>
<div class="submit">
<button type="submit">Advanced Search</button>
</div>
</form>
<script type="text/javascript">
DekiWiki.$(<eval:js>'#' .. @formId</eval:js>).submit(GS.buildLuceneQuery);
DekiWiki.$(document).ready(function()
{
GS.createAutoComplete(<eval:js>@acId</eval:js>, <eval:js>@acResultsId</eval:js>);
});
</script>
</body>
</html>
</return>
</function>
<function>
<name>results</name>
<description>Displays search results from the wiki.getSearch function. More functionality is enabled if inlined on a page.</description>
<param name="results" type="list">Search result map object returned from wiki.getSearch</param>
<return>
<html xmlns:eval="http://mindtouch.com/2007/dekiscript">
<body>
<eval:expr>
/* initialize searchResults with backward compat */
let searchResults = false;
/* check if this is inlined in a page */
let isExtension = __env.__request ? false : true;
/* sets the maximum number of search results to display when inlining code */
let numResults = 20;
/* sets the length of the content preview when inlining code */
let previewLength = 255;
if (isExtension)
{
let searchResults = args.results ?? false;
}
else
{
if (__request.args.prefix ?? false)
{
/* args.results should be generated by the following when invoking this code as a function */
let searchResults = wiki.getSearch(uri.decode(__request.args.prefix ?? ''), numResults, _, uri.decode(__request.args.suffix ?? ''));
}
}
let html = '';
let html ..= '<h3>Search Results</h3>';
let html ..= '<div id="searchResults">';
if (searchResults)
{
if (#searchResults > 0)
{
let html ..= '<ul>';
foreach (var object in searchResults)
{
let html ..= '<li>';
if (object.path)
{
let html ..= '<div class="title">';
let html ..= '<a href="' .. object.uri .. '">' .. object.title .. '</a>';
if (!isExtension && object.parent)
{
let html ..= ' in <a href="' .. object.parent.uri .. '">' .. object.parent.title .. '</a>';
}
let html ..= '</div>';
let html ..= '<div class="itemmatch">' .. object.date .. ' (' .. object.editsummary .. ')</div>';
if (!isExtension && object.text)
{
let html ..= '<div class="searchpreview">' .. string.substr(object.text, 0, previewLength) .. '</div>';
}
}
else
{
let html ..= '<div class="title"><a href="' .. object.uri .. '">' .. object.name .. '</a></div>';
let html ..= '<div class="itemmatch">' .. object.date .. ' (' .. object.description .. ')</div>';
}
let html ..= '</li>';
}
let html ..= '</ul>';
}
else
{
let html ..= '<p>No Results found for your search.</p>';
}
}
else
{
let html ..= '<p>Please enter a search above.</p>';
}
let html ..= '</div>';
web.html(html);
</eval:expr>
</body>
</html>
</return>
</function>
</extension>