root/swishctl/example/query.htm

Revision 1302, 9.6 kB (checked in by augur, 5 years ago)

Removed last bits of Acc Index from HTML files, I think.
Removed all the various batch files. I'd rather the end-users RTFM a little.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <html>
2
3 <head>
4
5 <title>SwishCtl Query</title>
6
7 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
8
9 <link rel="stylesheet" href="styles/search.css">
10
11 <script language="JavaScript1.1">
12
13 <!--
14
15
16
17 // if we find ourself outside the frameset, reload index.htm
18
19 if (top.location.href == self.location.href) {
20
21         top.location.href = "index.htm";
22
23 }
24
25
26
27 //-->
28
29 </script>
30
31 </head>
32
33 <body bgcolor="#ffffff" onload="return LoadPage()"><!--
34
35 --><form method="post" action="" name="ObjectForm" ><!--
36
37    --><OBJECT id=swishctl height=0 width=0
38
39         classid=CLSID:9E204F2E-4F04-11D7-858F-8CA08FF5860C
40
41         name=swish-e></OBJECT><!--
42
43 --></form><!--
44
45 --><form method="post" action="" name="QueryForm"
46
47           onsubmit="return MM_callJS('DoQuery()')"
48
49           onreset="return MM_callJS('ResetForm()')">
50
51     Query: <!--
52
53    --><input name="textfield" >&nbsp;
54
55    <!--
56
57       from:&nbsp;
58
59    <input id="startyear" name="start year" size="4" maxlength="4">
60
61       to:&nbsp;
62
63    <input id="stopyear"  name="stop year"  size="4" maxlength="4">
64
65    sort by:&nbsp;
66
67    <select name="sortorder">
68
69         <option value="decisionid desc" selected>Year (most recent first)</option>
70
71         <option value="decisionid asc">Year (oldest first)</option>
72
73         <option value="swishrank desc">Best match first</option>
74
75       </select>
76
77    -->
78
79       <input type=hidden name="sortorder" value="swishrank desc">
80
81       <input type=submit value=Search name=Submit>
82
83       <input type="reset" value="Reset">
84
85       <input id="previousresults" name="previousresults" type="image"
86
87         onclick="return MM_callJS('DoPrevious()')"
88
89         onmouseover="this.src='images/left-sel.gif';" 
90
91         onmouseout="this.src='images/left.gif';"
92
93         src="images/left.gif" width="30" height="17">&nbsp;     
94
95    <input id="moreresults" name="moreresults" type="image"
96
97         onclick="return MM_callJS('DoMore()')"
98
99         onmouseover="this.src='images/right-sel.gif';" 
100
101         onmouseout="this.src='images/right.gif';"
102
103         src="images/right.gif" width="30" height="17">&nbsp;<!--
104
105    --><input id="helppage" name="helppage" type="image"
106
107         onclick="return MM_callJS('DoHelp()')"
108
109         onmouseover="this.src='images/help-sel.gif';" 
110
111         onmouseout="this.src='images/help.gif';"
112
113         src="images/help.gif" width="18" height="18">   <!--
114
115 --></form>
116
117 <script language="JavaScript">
118
119 <!--
120
121
122
123 var swishctl;
124
125 var firstresult;
126
127 var lastresult;
128
129 var resultcount;
130
131 var years;
132
133
134
135 // change this to change the number of results per page
136
137 var resultsperpage = 10;
138
139
140
141 function MM_callJS(jsStr) { //v2.0
142
143   return eval(jsStr)
144
145 }
146
147
148
149 function ResetForm()
150
151 {
152
153     // called when form is reset - reloads globals
154
155     // which as script is apprently reinitialised??
156
157         swishctl.Close();
158
159         swishctl.Init("swishdocs");
160
161         firstresult = 0;
162
163         lastresult = 0;
164
165         resultcount = 0;
166
167         parent.BodyFrame.navigate( "body.htm" );
168
169         document.QueryForm.textfield.focus();
170
171         return true;
172
173 }
174
175
176
177 function LoadPage()
178
179 {
180
181     // loads global variables...
182
183         swishctl = document.ObjectForm.swishctl;
184
185         swishctl.Init("swishdocs");
186
187         firstresult = 0;
188
189         lastresult = 0;
190
191         resultcount = 0;
192
193         years = "";
194
195         return true;
196
197 }
198
199
200
201 function ShowRank( rank )
202
203 {
204
205         // returns HTML img tag with n stars
206
207         // where n depends on rank (somehow)
208
209     return "&nbsp;";
210
211     var starcount=0;
212
213     if ( rank > 950 ){
214
215         starcount=5;
216
217     } else if ( rank > 900 ) {
218
219         starcount=4;
220
221     } else if ( rank > 800 ) {
222
223         starcount=3;
224
225     } else if ( rank > 500 ) {
226
227         starcount=2;
228
229     } else if ( rank > 100 ) {
230
231         starcount=1;
232
233     } else {
234
235         starcount=0;
236
237     }
238
239     return "&nbsp;<img src=\"images/" + starcount
240
241                 + "stars.gif\" alt=\"" + rank + "*\">&nbsp;";
242
243 }
244
245
246
247
248
249 function ShowResults( startresult, lastresult, resultcount, comments )
250
251 {
252
253         // generates results from swishctl and writes html to BodyFrame
254
255         // inserts startresult, lastresult... in appropriate places
256
257         var bodyFrame = parent.BodyFrame.document
258
259         var querystring = document.QueryForm.textfield.value;
260
261
262
263         bodyFrame.open();
264
265         bodyFrame.writeln(
266
267                 "<html>\n<head>\n<title>Search Results</title>\n"
268
269                 + "<link rel=\"stylesheet\" href=\"styles/results.css\" media=\"screen\">"
270
271                 + "</head>\n<body>\n"
272
273                 + "<p class=\"swquery\">Query [<b>" + querystring + "</b>] "
274
275                 + comments + "\n returned: <b>" + resultcount 
276
277                 + "</b> hits.</p>\n<p class=\"swrescount\">Results <b>"
278
279                 + startresult + "</b> to <b>" + lastresult  + "</b></p>");
280
281
282
283         swishctl.SeekResult( startresult - 1 );
284
285  
286
287         for ( i = startresult; i <= lastresult; i++)
288
289         {
290
291                 if (swishctl.NextResult()) {
292
293                         bodyFrame.writeln(
294
295                                 "<p class=\"swres\">" + i
296
297                                 // uncomment the following to get **** showing rank of result
298
299                                 //+ ShowRank( swishctl.ResultPropertyString(
300
301                                 //      "swishrank" ))
302
303                                 + "&nbsp;<a href=\"" +
304
305                                 swishctl.ResultPropertyString( "swishdocpath" )
306
307                                 + "\" class=\"swref\">"
308
309                                 + swishctl.ResultPropertyString( "swishtitle" )
310
311                                 + "...</a><br>\n<span class=\"swdesc\">"
312
313                                 + swishctl.ResultPropertyString( "description"
314
315                                 + "</span></p>\n" );
316
317                 } else {
318
319                         //alert("an error");
320
321                 }
322
323         }
324
325         bodyFrame.writeln("</body>\n");
326
327         bodyFrame.close();
328
329         document.QueryForm.textfield.focus();
330
331
332
333         return true;
334
335 }
336
337
338
339 function ShowNoResults(comment)
340
341 {
342
343         // Writes "no results found" to BodyFrame in HTML
344
345         var bodyFrame = parent.BodyFrame.document;
346
347         var querystring = document.QueryForm.textfield.value;
348
349
350
351         bodyFrame.open();
352
353         bodyFrame.writeln(
354
355                 "<html><head><title>Search Results</title>\n"
356
357                 + "<link rel=\"stylesheet\" href=\"styles/results.css\" media=\"screen\">\n"
358
359                 + "</head>\n<p class=\"swquery\">Query [<b>"
360
361                 + querystring + "</b>] " + comment
362
363                 + " returned no results</p></body></html>");
364
365         bodyFrame.close();
366
367 }
368
369
370
371 function LTrim( strval ) // like VB LTRIM
372
373 {
374
375         while ( strval.charAt(0) == " " ) {
376
377                 strval = strval.substring( 1, strval.length );
378
379         }
380
381         return (strval);
382
383 }
384
385
386
387 function CheckYear( yr )
388
389 {
390
391         // returns 4 digit year, or null if yr is bogus
392
393         var intYear = parseInt( yr );
394
395
396
397         if (isNaN(intYear)) return null;
398
399
400
401         if ( intYear >= 1000 ) {
402
403                 return yr;
404
405         } else if ( intYear >= 100 ) {
406
407                 return null; // don't allow 3 digit years
408
409         } else if ( intYear >= 10 ) {
410
411                 return "19" + intYear;
412
413         } else if ( intYear >= 0 ) {
414
415                 return "200" + intYear;
416
417         }
418
419         return null;
420
421 }
422
423
424
425 function DoQuery()
426
427 {
428
429         // called when form is submitted
430
431         // gets variables from form, sets query parameters on swishctl
432
433         // runs query and calls ShowResults...
434
435 /* Sample code for limit handling requires 4 digit year meta-tag in documents
436
437         var startyr = document.QueryForm.startyear.value;
438
439         var stopyr = document.QueryForm.stopyear.value;
440
441         years = " (in the years";
442
443         if ( startyr ) {
444
445                 if ( !stopyr ) {
446
447                         stopyr = "9999";
448
449                 }
450
451                 startyr = CheckYear( startyr );
452
453                 if ( startyr ) {
454
455                         document.QueryForm.startyear.value = startyr;           
456
457                         years = years + " from " + startyr;
458
459                 } else {
460
461                         alert( '"From" field should be the year as a number (e.g. 1995).' );
462
463                         document.QueryForm.startyear.focus();   
464
465                         return false;
466
467                 }
468
469         }
470
471         if ( stopyr ) {
472
473                 if (!startyr) {
474
475                         startyr = "0000";
476
477                 }
478
479                 stopyr = CheckYear( stopyr );
480
481                 if ( stopyr ) {
482
483                         document.QueryForm.stopyear.value = stopyr;             
484
485                         years = years + " to " + stopyr;
486
487                 } else {
488
489                         alert( '"To" field should be the year as a number (e.g. 2003).' );
490
491                         document.QueryForm.stopyear.focus();
492
493                         return false;   
494
495                 }
496
497         }
498
499         years = years + ") ";
500
501
502
503         if ( stopyr < startyr ) {
504
505                 alert( 'The "To:" field should be greater than "From:"' );
506
507                 document.QueryForm.stopyear.focus();
508
509                 return false;   
510
511         }
512
513 */      
514
515         var querystring = document.QueryForm.textfield.value;
516
517        
518
519         //alert( querystring );
520
521         var res = swishctl.NewSearch( querystring );
522
523
524
525         var sort = document.QueryForm.sortorder.value;
526
527         swishctl.SetSort( sort );
528
529
530
531         if ( swishctl.Error() != 0 ) {
532
533                 alert( "Swish-e returned error: " + swishctl.Error());
534
535         }
536
537 /* Sample code for setting search limits
538
539         if ( startyr && stopyr ) {
540
541                 swishctl.SetSearchLimit( "year", startyr, stopyr );
542
543         } else {
544
545                 years = "";
546
547         }       
548
549 */              
550
551         swishctl.Execute( querystring );
552
553         var i =1;
554
555        
556
557         if ( swishctl.Hits() > 0 )
558
559         {
560
561                 resultcount = swishctl.Hits();
562
563                 firstresult = 1;
564
565                 if ( resultcount > resultsperpage ) {
566
567                         lastresult = resultsperpage;
568
569                 } else {
570
571                         lastresult = resultcount;
572
573                 }
574
575                 ShowResults( firstresult, lastresult, resultcount, years );
576
577
578
579         } else {
580
581                 resultcount = 0;
582
583                 ShowNoResults(years);
584
585         }
586
587         return false;
588
589 }
590
591
592
593 function DoMore()
594
595 {
596
597         // goes to next set of ten records
598
599         // (increment globals and call ShowResults
600
601         if ( resultcount == 0 ) {
602
603                 ShowNoResults(years);
604
605                 return false;
606
607         }
608
609
610
611         if ( lastresult < resultcount ) {
612
613                 lastresult = lastresult + resultsperpage;
614
615                 firstresult = firstresult + resultsperpage;
616
617                 if ( lastresult > resultcount ) {
618
619                         lastresult = resultcount;
620
621                 }
622
623                 //alert ("Do more " + firstresult + " / " + lastresult + " / " + resultcount);
624
625                 ShowResults( firstresult, lastresult, resultcount, years );
626
627         }
628
629         return false;
630
631 }
632
633
634
635 function DoPrevious()
636
637 {
638
639         // goes to previous set of ten records
640
641         // (decrement globals and call ShowResults
642
643         if ( resultcount == 0 ) {
644
645                 ShowNoResults(years);
646
647                 return false;
648
649         }
650
651
652
653         if ( firstresult > 0  ) {
654
655                 firstresult = firstresult - resultsperpage;
656
657                 if ( firstresult < 0 ) {
658
659                         firstresult = 1;
660
661                 }
662
663                 lastresult = firstresult + resultsperpage - 1;
664
665
666
667                 if ( lastresult > resultcount ) {
668
669                         lastresult = resultcount;
670
671                 }
672
673                 //alert ("Do previous " + firstresult + " / " + lastresult + " / " + resultcount);
674
675
676
677                 ShowResults( firstresult, lastresult, resultcount, years );
678
679         }
680
681         return false;
682
683 }
684
685
686
687 function DoHelp()
688
689 {
690
691         // called when help button is clicked
692
693         parent.BodyFrame.navigate( "help.htm" );
694
695         return false;
696
697 }
698
699 //-->
700
701 </script>
702
703 </body>
704
705 </html>
706
Note: See TracBrowser for help on using the browser.