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