9 jQuery.makeSearchSummary =
function(text, keywords, hlwords) {
10 var textLower = text.toLowerCase();
12 $.each(keywords,
function() {
13 var i = textLower.indexOf(this.toLowerCase());
17 start = Math.max(start - 120, 0);
18 var excerpt = ((start > 0) ?
'...' :
'') +
19 $.trim(text.substr(start, 240)) +
20 ((start + 240 - text.length) ?
'...' :
'');
21 var rv = $(
'<div class="context"></div>').text(excerpt);
22 $.each(hlwords,
function() {
23 rv = rv.highlightText(
this,
'highlight');
31 var PorterStemmer =
function() {
69 var C = c +
"[^aeiouy]*";
70 var V = v +
"[aeiou]*";
72 var mgr0 =
"^(" + C +
")?" + V + C;
73 var meq1 =
"^(" + C +
")?" + V + C +
"(" + V +
")?$";
74 var mgr1 =
"^(" + C +
")?" + V + C + V + C;
75 var s_v =
"^(" + C +
")?" + v;
77 this.stemWord =
function (w) {
91 firstch = w.substr(0,1);
93 w = firstch.toUpperCase() + w.substr(1);
96 re = /^(.+?)(ss|i)es$/;
97 re2 = /^(.+?)([^s])s$/;
100 w = w.replace(re,
"$1$2");
101 else if (re2.test(w))
102 w = w.replace(re2,
"$1$2");
106 re2 = /^(.+?)(ed|ing)$/;
109 re =
new RegExp(mgr0);
110 if (re.test(fp[1])) {
112 w = w.replace(re,
"");
115 else if (re2.test(w)) {
116 var fp = re2.exec(w);
118 re2 =
new RegExp(s_v);
119 if (re2.test(stem)) {
122 re3 =
new RegExp(
"([^aeiouylsz])\\1$");
123 re4 =
new RegExp(
"^" + C + v +
"[^aeiouwxy]$");
126 else if (re3.test(w)) {
128 w = w.replace(re,
"");
130 else if (re4.test(w))
140 re =
new RegExp(s_v);
146 re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;
151 re =
new RegExp(mgr0);
153 w = stem + step2list[suffix];
157 re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
162 re =
new RegExp(mgr0);
164 w = stem + step3list[suffix];
168 re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
169 re2 = /^(.+?)(s|t)(ion)$/;
173 re =
new RegExp(mgr1);
177 else if (re2.test(w)) {
178 var fp = re2.exec(w);
179 stem = fp[1] + fp[2];
180 re2 =
new RegExp(mgr1);
190 re =
new RegExp(mgr1);
191 re2 =
new RegExp(meq1);
192 re3 =
new RegExp(
"^" + C + v +
"[^aeiouwxy]$");
193 if (re.test(stem) || (re2.test(stem) && !(re3.test(stem))))
197 re2 =
new RegExp(mgr1);
198 if (re.test(w) && re2.test(w)) {
200 w = w.replace(re,
"");
205 w = firstch.toLowerCase() + w.substr(1);
217 _queued_query : null,
221 var params = $.getQueryParameters();
223 var query = params.q[0];
224 $(
'input[name="q"]')[0].value = query;
225 this.performSearch(query);
232 setIndex :
function(index) {
235 if ((q = this._queued_query) !== null) {
236 this._queued_query = null;
241 hasIndex :
function() {
242 return this._index !== null;
245 deferQuery :
function(query) {
246 this._queued_query = query;
249 stopPulse :
function() {
250 this._pulse_status = 0;
253 startPulse :
function() {
254 if (this._pulse_status >= 0)
257 Search._pulse_status = (Search._pulse_status + 1) % 4;
259 for (var i = 0; i < Search._pulse_status; i++)
261 Search.dots.text(dotString);
262 if (Search._pulse_status > -1)
263 window.setTimeout(pulse, 500);
271 performSearch :
function(query) {
273 this.out = $(
'#search-results');
274 this.title = $(
'<h2>' + _(
'Searching') +
'</h2>').appendTo(this.out);
275 this.dots = $(
'<span></span>').appendTo(this.title);
276 this.status = $(
'<p style="display: none"></p>').appendTo(this.out);
277 this.output = $(
'<ul class="search"/>').appendTo(this.out);
279 $(
'#search-progress').text(_(
'Preparing search...'));
286 this.deferQuery(query);
289 query :
function(query) {
292 var stemmer =
new PorterStemmer();
293 var searchterms = [];
296 var tmp = query.split(/\s+/);
297 var
object = (tmp.length == 1) ? tmp[0].toLowerCase() : null;
298 for (var i = 0; i < tmp.length; i++) {
300 var word = stemmer.stemWord(tmp[i]).toLowerCase();
302 if (word[0] ==
'-') {
303 var toAppend = excluded;
304 word = word.substr(1);
307 var toAppend = searchterms;
308 hlterms.push(tmp[i].toLowerCase());
311 if (!$.contains(toAppend, word))
314 var highlightstring =
'?highlight=' + $.urlencode(hlterms.join(
" "));
316 console.debug(
'SEARCH: searching for:');
317 console.info(
'required: ', searchterms);
318 console.info(
'excluded: ', excluded);
321 var filenames = this._index.filenames;
322 var titles = this._index.titles;
323 var terms = this._index.terms;
324 var descrefs = this._index.descrefs;
325 var modules = this._index.modules;
326 var desctypes = this._index.desctypes;
329 var objectResults = [];
330 var regularResults = [];
331 $(
'#search-progress').empty();
334 if (
object != null) {
335 for (var module in modules) {
336 if (module.indexOf(
object) > -1) {
337 fn = modules[module];
338 descr = _(
'module, in ') + titles[fn];
339 objectResults.push([filenames[fn], module,
'#module-'+module, descr]);
342 for (var prefix in descrefs) {
343 for (var name in descrefs[prefix]) {
344 if (name.toLowerCase().indexOf(
object) > -1) {
345 match = descrefs[prefix][name];
346 fullname = (prefix ? prefix +
'.' :
'') + name;
347 descr = desctypes[match[1]] + _(
', in ') + titles[match[0]];
348 objectResults.push([filenames[match[0]], fullname,
'#'+fullname, descr]);
355 objectResults.sort(
function(
a, b) {
356 return (
a[1] > b[1]) ? -1 : ((
a[1] < b[1]) ? 1 : 0);
361 for (var i = 0; i < searchterms.length; i++) {
362 var word = searchterms[i];
364 if ((files = terms[word]) == null)
366 if (files.length == undefined) {
370 for (var j = 0; j < files.length; j++) {
373 fileMap[file].push(word);
375 fileMap[file] = [word];
380 for (var file in fileMap) {
384 if (fileMap[file].length != searchterms.length)
389 for (var i = 0; i < excluded.length; i++) {
390 if (terms[excluded[i]] == file ||
391 $.contains(terms[excluded[i]] || [], file)) {
400 regularResults.push([filenames[file], titles[file],
'', null]);
405 delete filenames, titles, terms;
408 regularResults.sort(
function(
a, b) {
409 var left =
a[1].toLowerCase();
410 var right = b[1].toLowerCase();
411 return (left > right) ? -1 : ((left < right) ? 1 : 0);
415 var results = regularResults.concat(objectResults);
418 var resultCount = results.length;
419 function displayNextItem() {
421 if (results.length) {
422 var item = results.pop();
423 var listItem = $(
'<li style="display:none"></li>');
424 listItem.append($(
'<a/>').attr(
426 item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX +
427 highlightstring + item[2]).html(item[1]));
429 listItem.append($(
'<span> (' + item[3] +
')</span>'));
430 Search.output.append(listItem);
431 listItem.slideDown(5,
function() {
434 }
else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
435 $.get(
'_sources/' + item[0] +
'.txt',
function(data) {
436 listItem.append($.makeSearchSummary(data, searchterms, hlterms));
437 Search.output.append(listItem);
438 listItem.slideDown(5,
function() {
444 Search.output.append(listItem);
445 listItem.slideDown(5,
function() {
453 Search.title.text(_(
'Search Results'));
455 Search.status.text(_(
'Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.'));
457 Search.status.text(_(
'Search finished, found %s page(s) matching the search query.').replace(
'%s', resultCount));
458 Search.status.fadeIn(500);
465 $(document).ready(
function() {
The namespace console contains no service. It is only used to launch a main loop for console applicat...