]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/result_common.js
added zero/low hits stuff to the search result code
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / result_common.js
1
2 var recordsHandled = 0;
3 var recordsCache = [];
4 var lowHitCount = 4;
5
6 /* set up the event handlers */
7 G.evt.result.hitCountReceived.push(resultSetHitInfo);
8 G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
9 G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
10 G.evt.result.allRecordsReceived.push(resultBuildCaches, resultDrawSubjects, resultDrawAuthors, resultDrawSeries);
11
12 attachEvt('result','lowHits',resultLowHits);
13 attachEvt('result','zeroHits',resultZeroHits);
14
15 attachEvt( "common", "locationUpdated", resultSBSubmit );
16 function resultSBSubmit(){searchBarSubmit();}
17
18 /* do this after we have ID's so the rank for mr pages will be correct */
19 attachEvt("result", "preCollectRecords", resultPaginate);
20
21 /* returns the last 'index' postion ocurring in this page */
22 function resultFinalPageIndex() {
23         if(getHitCount() < (getOffset() + getDisplayCount())) 
24                 return getHitCount() - 1;
25         return getOffset() + getDisplayCount() - 1;
26 }
27
28 /* set the search result info, number of hits, which results we're 
29         displaying, links to the next/prev pages, etc. */
30 function resultSetHitInfo() { 
31         if(getHitCount() <= lowHitCount)
32                 runEvt('result', 'lowHits');
33         if(getHitCount() == 0) {
34                 runEvt('result', 'zeroHits');
35                 return;
36         }
37
38         var c;  
39         if( getDisplayCount() > (getHitCount() - getOffset()))  c = getHitCount();
40         else c = getDisplayCount() + getOffset();
41
42         var pages = getHitCount() / getDisplayCount();
43         if(pages % 1) pages = parseInt(pages) + 1;
44
45         G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
46         G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
47
48         G.ui.result.offset_start.appendChild(text(getOffset() + 1));
49         G.ui.result.offset_end.appendChild(text(c));
50         G.ui.result.result_count.appendChild(text(getHitCount()));
51         unHideMe(G.ui.result.info);
52 }
53
54 function resultLowHits() {
55         try{searchTimer.stop()}catch(e){}
56         showCanvas();
57         unHideMe($('result_low_hits'));
58         if(getHitCount() > 0)
59                 unHideMe($('result_low_hits_msg'));
60
61         var sreq = new Request(CHECK_SPELL, getTerm());
62         sreq.callback(resultSuggestSpelling);
63         sreq.send();
64
65         var words = getTerm().split(' ');
66         var word;
67         while( word = words.shift() ) {
68                 var areq = new Request(FETCH_CROSSREF, getStype(), getTerm() );
69                 areq.callback(resultLowHitXRef);
70                 areq.send();
71         }
72
73         if( !(getForm() == null || getForm() == 'all' || getForm == "") ) {
74                 var a = {};
75                 a[PARAM_FORM] = "all";
76                 $('low_hits_remove_format_link').setAttribute('href',buildOPACLink(a));
77                 unHideMe($('low_hits_remove_format'));
78         }
79 }
80
81 var lowHitsXRefLink;
82 var lowHitsXRefLinkParent;
83 function resultLowHitXRef(r) {
84         if(!lowHitsXRefLink){
85                 lowHitsXRefLinkParent = $('low_hits_xref_link').parentNode;
86                 lowHitsXRefLink = lowHitsXRefLinkParent.removeChild($('low_hits_xref_link'));
87         }
88         var res = r.getResultObject();
89         var arr = res.from;
90         arr.concat(res.also);
91         if(arr && arr.length > 0) {
92                 unHideMe($('low_hits_cross_ref'));
93                 var word;
94                 var c = 0;
95                 while( word = arr.shift() ) {
96                         if(c++ > 20) break;
97                         var a = {};
98                         a[PARAM_TERM] = word;
99                         var template = lowHitsXRefLink.cloneNode(true);
100                         template.setAttribute('href',buildOPACLink(a));
101                         template.appendChild(text(word));
102                         lowHitsXRefLinkParent.appendChild(template);
103                         lowHitsXRefLinkParent.appendChild(text(' '));
104                 }
105         }
106 }
107
108 function resultZeroHits() {
109         unHideMe($('result_zero_hits_msg'));
110         resultExpandSearch();
111         resultSuggestSearchClass();
112 }
113
114 function resultExpandSearch() {
115         var top = findOrgDepth(globalOrgTree);
116         if(getDepth() == top) return;
117         unHideMe($('low_hits_expand_range'));
118         var par = $('low_hits_expand_link').parentNode;
119         var template = par.removeChild($('low_hits_expand_link'));
120
121         var bottom = getDepth();
122         while( top < bottom ) {
123                 var a = {};
124                 a[PARAM_DEPTH] = top;
125                 var temp = template.cloneNode(true);
126                 temp.appendChild(text(findOrgTypeFromDepth(top).opac_label()))
127                 temp.setAttribute('href',buildOPACLink(a));
128                 par.appendChild(temp);
129                 top++;
130         }
131 }
132
133 function resultSuggestSearchClass() {
134         var stype = getStype();
135         if(stype == STYPE_KEYWORD) return;
136         var a = {}; var ref;
137         unHideMe($('low_hits_search_type'));
138         if(stype != STYPE_TITLE) {
139                 ref = $('low_hits_title_search');
140                 unHideMe(ref);
141                 a[PARAM_STYPE] = STYPE_TITLE;
142                 ref.setAttribute('href',buildOPACLink(a));
143         }
144         if(stype != STYPE_AUTHOR) {
145                 ref = $('low_hits_author_search');
146                 unHideMe(ref);
147                 a[PARAM_STYPE] = STYPE_AUTHOR;
148                 ref.setAttribute('href',buildOPACLink(a));
149         }
150         if(stype != STYPE_SUBJECT) {
151                 ref = $('low_hits_subject_search');
152                 unHideMe(ref);
153                 a[PARAM_STYPE] = STYPE_SUBJECT;
154                 ref.setAttribute('href',buildOPACLink(a));
155         }
156         if(stype != STYPE_KEYWORD) {
157                 ref = $('low_hits_keyword_search');
158                 unHideMe(ref);
159                 a[PARAM_STYPE] = STYPE_KEYWORD;
160                 ref.setAttribute('href',buildOPACLink(a));
161         }
162         if(stype != STYPE_SERIES) {
163                 ref = $('low_hits_series_search');
164                 unHideMe(ref);
165                 a[PARAM_STYPE] = STYPE_SERIES;
166                 ref.setAttribute('href',buildOPACLink(a));
167         }
168 }
169
170 function resultSuggestSpelling(r) {
171         var res = r.getResultObject();
172         if(res) {
173                 unHideMe($('did_you_mean'));
174                 var arg = {};
175                 arg[PARAM_TERM] = res;
176                 $('spell_check_link').setAttribute(
177                         'href', buildOPACLink(arg) );
178                 $('spell_check_link').appendChild(text(res));
179         }
180 }
181
182
183 function resultPaginate() {
184         var o = getOffset();
185
186         if( !((o + getDisplayCount()) >= getHitCount()) ) {
187
188                 var args = {};
189                 args[PARAM_OFFSET] = o + getDisplayCount();
190                 G.ui.result.next_link.setAttribute("href", buildOPACLink(args)); 
191                 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
192
193                 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
194                 G.ui.result.end_link.setAttribute("href", buildOPACLink(args)); 
195                 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
196         }
197
198         if( o > 0 ) {
199
200                 var args = {};
201                 args[PARAM_OFFSET] = o - getDisplayCount();
202                 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args)); 
203                 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
204
205                 args[PARAM_OFFSET] = 0;
206                 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args)); 
207                 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
208         }
209         if(getDisplayCount() < getHitCount())
210                 unHideMe($('start_end_links_span'));
211
212         showCanvas();
213         try{searchTimer.stop()}catch(e){}
214 }
215
216
217 /* display the record info in the record display table 'pos' is the 
218                 zero based position the record should have in the display table */
219 function resultDisplayRecord(rec, pos, is_mr) {
220
221         if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
222         recordsHandled++;
223         recordsCache.push(rec);
224
225         var r = table.rows[pos + 1];
226         
227         try {
228                 var rank = parseFloat(ranks[pos + getOffset()]);
229                 rank = ( rank / getTopRank() ) * 100;
230                 rank = parseInt(rank) + "%";
231                 var relspan = $n(r, "relevancy_span");
232                 relspan.appendChild(text(rank));
233                 unHideMe(relspan.parentNode);
234         } catch(e){ }
235
236         var pic = $n(r, config.names.result.item_jacket);
237         pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
238
239         var title_link = $n(r, config.names.result.item_title);
240         var author_link = $n(r, config.names.result.item_author);
241
242         if( is_mr )  {
243                 var onlyrec = onlyrecord[ getOffset() + pos ];
244                 if(onlyrec) {
245                         var args = {};
246                         args.page = RDETAIL;
247                         args[PARAM_OFFSET] = 0;
248                         args[PARAM_RID] = onlyrec;
249                         args[PARAM_MRID] = rec.doc_id();
250                         pic.parentNode.setAttribute("href", buildOPACLink(args));
251                         title_link.setAttribute("href", buildOPACLink(args));
252                         title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
253                         
254                 } else {
255                         buildTitleLink(rec, title_link); 
256                         var args = {};
257                         args.page = RRESULT;
258                         args[PARAM_OFFSET] = 0;
259                         args[PARAM_MRID] = rec.doc_id();
260                         pic.parentNode.setAttribute("href", buildOPACLink(args));
261                 }
262
263         } else {
264                 buildTitleDetailLink(rec, title_link); 
265                 var args = {};
266                 args.page = RDETAIL;
267                 args[PARAM_OFFSET] = 0;
268                 args[PARAM_RID] = rec.doc_id();
269                 pic.parentNode.setAttribute("href", buildOPACLink(args));
270
271                 unHideMe($n(r,'place_hold_span'));
272                 $n(r,'place_hold_link').setAttribute(
273                         'href','javascript:holdsDrawWindow("'+rec.doc_id()+'");');
274         }
275
276         buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
277
278         if(! is_mr ) {
279         
280                 if(!isNull(rec.edition()))      {
281                         unHideMe( $n(r, "result_table_extra_span"));
282                         $n(r, "result_table_edition_span").appendChild( text( rec.edition()) );
283                 }
284                 if(!isNull(rec.pubdate())) {
285                         unHideMe( $n(r, "result_table_extra_span"));
286                         unHideMe($n(r, "result_table_pub_span"));
287                         $n(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
288                 }
289                 if(!isNull(rec.publisher()) ) {
290                         unHideMe( $n(r, "result_table_extra_span"));
291                         unHideMe($n(r, "result_table_pub_span"));
292                         $n(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
293                 }
294         }
295
296         resultBuildFormatIcons( r, rec );
297
298         unHideMe(r);
299         
300         runEvt("result", "recordDrawn", rec.doc_id(), title_link);
301
302         if(resultPageIsDone())  {
303                 //showCanvas();
304                 /* hide the 'now loading...' message */
305                 /*
306                 hideMe(G.ui.common.loading);
307                 */
308                 runEvt('result', 'allRecordsReceived', recordsCache);
309         }
310 }
311
312 function _resultFindRec(id) {
313         for( var i = 0; i != recordsCache.length; i++ ) {
314                 var rec = recordsCache[i];
315                 if( rec && rec.doc_id() == id )
316                         return rec;
317         }
318         return null;
319 }
320
321 /*
322 var currentHoldRecord;
323 var holdsOrgSelectorBuilt = false;
324 function resultDrawHoldsWindow(recid) {
325
326         if(recid == null) {
327                 recid = currentHoldRecord;
328                 if(recid == null) return;
329         }
330         currentHoldRecord = recid;
331
332         detachEvt('common','locationUpdated', resultSBSubmit );
333         attachEvt( "common", "locationUpdated", resultSBSubmit );
334
335         if(!(G.user && G.user.session)) {
336
337                 detachEvt('common','locationUpdated', resultSBSubmit );
338                 attachEvt('common','loggedIn', resultDrawHoldsWindow)
339                 //alert(G.evt['common']['locationUpdated']);
340                 initLogin();
341                 //attachEvt( "common", "locationUpdated", resultSBSubmit );
342                 return;
343         }
344         swapCanvas($('holds_box'));
345
346         var rec = _resultFindRec(recid);
347
348         if(!holdsOrgSelectorBuilt) {
349                 resultBuildHoldsSelector(null, 0);
350                 holdsOrgSelectorBuilt = true;
351         }
352
353         removeChildren($('holds_title'));
354         removeChildren($('holds_author'));
355         removeChildren($('holds_format'));
356         removeChildren($('holds_email'));
357         removeChildren($('holds_email'));
358
359         $('holds_title').appendChild(text(rec.title()));
360         $('holds_author').appendChild(text(rec.author()));
361
362         for( var i in rec.types_of_resource() ) {
363                 var res = rec.types_of_resource()[i];
364                 var img = elem("img");
365                 setResourcePic(img, res);
366                 $('holds_format').appendChild(text(' '+res+' '));
367                 $('holds_format').appendChild(img);
368                 $('holds_format').appendChild(text(' '));
369         }
370
371         $('holds_phone').appendChild(text(G.user.day_phone()));
372         $('holds_email').appendChild(text(G.user.email()));
373         $('holds_cancel').onclick = showCanvas;
374         $('holds_submit').onclick = resultPlaceHold; 
375 }
376
377
378 function resultBuildHoldsSelector(node, depth) {
379
380         if(!node) {
381                 node = globalOrgTree;
382                 depth = 0;
383         }
384
385         var selector = $('holds_org_selector');
386         var index = selector.options.length;
387
388         if(IE) {
389                 var pre = elem("pre");
390                 for(var x=2; x <= findOrgType(node.ou_type()).depth(); x++) {
391                         pre.appendChild(text("    "));
392                 }
393                 pre.appendChild(text(node.name()));
394                 var select = new Option("", node.id());
395                 selector.options[index] = select;
396                 select.appendChild(pre);
397         
398         } else {
399                 var pad = (findOrgType(node.ou_type()).depth() - 1) * 12;
400                 if(pad < 0) pad = 0;
401                 var select = new Option(node.name(), node.id());
402                 select.setAttribute("style", "padding-left: "+pad+'px;');
403                 selector.options[index] = select;
404         }       
405
406         if( node.id() == getLocation() ) {
407                 selector.selectedIndex = index;
408                 selector.options[index].selected = true;        
409         }
410
411         for( var i in node.children() ) {
412                 var child = node.children()[i];
413                 if(child) {
414                         resultBuildHoldsSelector(child, depth+1);
415                 }
416         }
417 }
418
419 function resultPlaceHold() {
420         var hold = new ahr();
421         hold.pickup_lib( 1 ); 
422         hold.requestor(G.user.id());
423         hold.usr(G.user.id());
424         hold.hold_type('T');
425         hold.email_notify(G.user.email());
426         hold.phone_notify(G.user.day_phone());
427         hold.target(currentHoldRecord);
428         
429         var req = new Request( CREATE_HOLD, G.user.session, hold );
430         req.send(true);
431         var res = req.result();
432
433         if( res == '1' ) {
434                 alert('ok');
435         } else {
436                 alert('hold failed');
437         }
438 }
439 */
440
441
442
443 function resultBuildFormatIcons( row, rec ) {
444
445         var ress = rec.types_of_resource();
446
447         for( var i in ress ) {
448
449                 var res = ress[i];
450                 var link = $n(row, res + "_link");
451                 link.title = res;
452                 var img = link.getElementsByTagName("img")[0];
453                 removeCSSClass( img, config.css.dim );
454
455                 var f = getForm();
456                 if( f != "all" ) {
457                         if( f == modsFormatToMARC(res) ) 
458                                 addCSSClass( img, "dim2_border");
459                 }
460
461                 var args = {};
462                 args.page = RRESULT;
463                 args[PARAM_OFFSET] = 0;
464                 args[PARAM_MRID] = rec.doc_id();
465                 args[PARAM_FORM] = modsFormatToMARC(res);
466
467                 link.setAttribute("href", buildOPACLink(args));
468
469         }
470 }
471
472
473 function resultPageIsDone(pos) {
474         return (recordsHandled == getDisplayCount() 
475                 || recordsHandled + getOffset() == getHitCount());
476 }
477
478 var resultCCHeaderApplied = false;
479
480 /* -------------------------------------------------------------------- */
481 /* dynamically add the copy count rows based on the org type 'countsrow' 
482         is the row into which we will add TD's to hold the copy counts 
483         This code generates copy count cells with an id of
484         'copy_count_cell_<depth>_<pagePosition>'  */
485 function resultAddCopyCounts(rec, pagePosition) {
486
487         var r = table.rows[pagePosition + 1];
488         var countsrow = $n(r, config.names.result.counts_row );
489         var ccell = $n(countsrow, config.names.result.count_cell);
490
491         var nodes = orgNodeTrail(findOrgUnit(getLocation()));
492         var node = nodes[0];
493         var type = findOrgType(node.ou_type());
494         ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
495         ccell.title = type.opac_label();
496         //addCSSClass(ccell, config.css.result.cc_cell_even);
497
498         var lastcell = ccell;
499         var lastheadcell = null;
500
501         var cchead = null;
502         var ccheadcell = null;
503         if(!resultCCHeaderApplied) {
504                 ccrow = $('result_thead_row');
505                 ccheadcell =  ccrow.removeChild($n(ccrow, "result_thead_ccell"));
506                 var t = ccheadcell.cloneNode(true);
507                 lastheadcell = t;
508                 t.appendChild(text(type.opac_label()));
509                 ccrow.appendChild(t);
510                 resultCCHeaderApplied = true;
511         }
512
513         if(nodes[1]) {
514
515                 var x = 1;
516                 var d = findOrgDepth(nodes[1]);
517                 var d2 = findOrgDepth(nodes[nodes.length -1]);
518
519                 for( var i = d; i <= d2 ; i++ ) {
520         
521                         ccell = ccell.cloneNode(true);
522
523                         //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
524                         //else addCSSClass(ccell, "copy_count_cell_even");
525
526                         var node = nodes[x++];
527                         var type = findOrgType(node.ou_type());
528         
529                         ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
530                         ccell.title = type.opac_label();
531                         countsrow.insertBefore(ccell, lastcell);
532                         lastcell = ccell;
533
534                         if(ccheadcell) {
535                                 var t = ccheadcell.cloneNode(true);
536                                 t.appendChild(text(type.opac_label()));
537                                 ccrow.insertBefore(t, lastheadcell);
538                                 lastheadcell = t;
539                         }
540                 }
541         }
542
543         unHideMe($("search_info_table"));
544 }
545
546 /* collect copy counts for a record using method 'methodName' */
547 function resultCollectCopyCounts(rec, pagePosition, methodName) {
548         if(rec == null || rec.doc_id() == null) return;
549         var req = new Request(methodName, getLocation(), rec.doc_id(), getForm() );
550         req.request.userdata = [ rec, pagePosition ];
551         req.callback(resultHandleCopyCounts);
552         req.send();
553 }
554
555 function resultHandleCopyCounts(r) {
556         runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject()); 
557 }
558
559
560 /* display the collected copy counts */
561 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
562         if(copy_counts == null || rec == null) return;
563         var i = 0;
564         while(copy_counts[i] != null) {
565                 var cell = $("copy_count_cell_" + i +"_" + pagePosition);
566                 /*
567                 var span = cell.getElementsByTagName("div")[0];
568                 */
569                 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
570
571                 i++;
572         }
573 }
574
575
576 /* captures extraneous info from each record */
577
578 var subjectCache = {};
579 var authorCache = {};
580 var seriesCache = {};
581
582 function resultBuildCaches(records) {
583         for( var r in records ) {
584                 var rec = records[r];
585                 for( var s in rec.subject() ) 
586                         subjectCache[s] == null ? subjectCache[s] = 1 : subjectCache[s]++;
587                 authorCache[rec.author()] = 1;
588                 for( var s in rec.series() ) seriesCache[rec.series()[s]] = 1;
589         }
590 }
591
592 function resultSortSubjects(a, b) { return -(a.count - b.count); } /* sort in reverse */
593 function resultDrawSubjects() {
594
595         var subjs = [];
596         for( var s in subjectCache )
597                 subjs.push( { sub : s, count : subjectCache[s] } );
598         subjs.sort(resultSortSubjects);
599
600         var ss = [];
601         for( var s in subjs ) ss.push(subjs[s].sub);
602
603         resultDrawSidebarTrees( 
604                 STYPE_SUBJECT, 
605                 "subjectSidebarTree", ss, 
606                 $("subject_tree_sidebar"), 
607                 $("subject_sidebar_tree_div") );
608 }
609
610 function resultDrawAuthors() {
611         var auths = new Array();
612         for( var s in authorCache ) auths.push(s);
613
614         resultDrawSidebarTrees( 
615                 STYPE_AUTHOR, 
616                 "authorSidebarTree", auths.sort(), 
617                 $("author_tree_sidebar"), 
618                 $("author_sidebar_tree_div") );
619 }
620
621 function resultDrawSeries() {
622         var sers = new Array();
623         for( var s in seriesCache ) sers.push(s);
624         resultDrawSidebarTrees( 
625                 STYPE_SERIES, 
626                 "seriesSidebarTree", sers.sort(), 
627                 $("series_tree_sidebar"), 
628                 $("series_sidebar_tree_div") );
629 }
630
631 function resultDrawSidebarTrees( stype, treeName, items, wrapperNode, destNode ) {
632         var tree;
633         eval("tree = " + treeName);
634
635         var found = false;
636         var x = 0;
637         for( var i in items ) {
638
639                 if(isNull(items[i])) continue;
640                 if(x++ > 7) break;
641                 found = true;
642
643                 var item = normalize(truncate(items[i], 65));
644                 var trunc = 65;
645                 var args = {};
646                 var href = resultQuickLink( items[i], stype );
647                 tree.addNode( stype + "_" + items[i], treeName + 'Root', item, href );
648
649                 /*
650                 if(!IE)
651                         setTimeout('resultFireXRefReq("'+treeName+'","'+stype+'","'+item+'");',200);
652                         */
653                 if(!IE) resultFireXRefReq(treeName, stype, items[i]);
654         }
655
656         if(found) {
657                 unHideMe(wrapperNode);
658                 //tree.close(tree.rootid);
659         }
660 }
661
662 function resultFireXRefReq( treeName, stype, item ) {
663         var tree;
664         eval('tree=' + treeName);
665         var req = new Request(FETCH_CROSSREF, stype, item);
666         req.request._tree = tree;
667         req.request._item = item;
668         req.request._stype = stype;
669         req.callback(resultAppendCrossRef);
670         req.send();
671 }
672
673
674 function resultQuickLink( term, type ) {
675         var args = {};
676         args.page = MRESULT;
677         args[PARAM_OFFSET] = 0;
678         args[PARAM_TERM] = term;
679         args[PARAM_STYPE] = type;
680         return buildOPACLink(args);
681 }
682
683
684 function resultAppendCrossRef(r) {
685         var tree                = r._tree
686         var item                = r._item
687         var stype       = r._stype;
688         var result      = r.getResultObject();
689         if(!result) return;
690         var froms       = result['from'];
691         var alsos       = result['also'];
692
693         var total = 0;
694
695         for( var i = 0; (total++ < 5 && i < froms.length); i++ ) {
696                 var string = normalize(truncate(froms[i], 45));
697                 if($(stype + '_' + froms[i])) continue;
698                 tree.addNode(stype + '_' + froms[i], 
699                         stype + '_' + item, string, resultQuickLink(froms[i],stype));
700         }
701         for( var i = 0; (total++ < 10 && i < alsos.length); i++ ) {
702                 var string = normalize(truncate(alsos[i], 45));
703                 if($(stype + '_' + alsos[i])) continue;
704                 tree.addNode(stype + '_' + alsos[i], 
705                         stype + '_' + item, string, resultQuickLink(alsos[i],stype));
706         }
707 }
708
709
710
711
712