Changeset 1287

Show
Ignore:
Timestamp:
07/04/03 23:51:07 (5 years ago)
Author:
augur
Message:

Changed SwishCtl::Init(IndexFiles?) so the IndexFiles? parameter works as documented.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/swishctl/example/queryframe.htm

    r1232 r1287  
    11<html> 
     2 
    23<head> 
     4 
    35<title>ACC Index</title> 
     6 
    47<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
     8 
    59<link rel="stylesheet" href="styles/searchform.css"> 
     10 
    611<script language="JavaScript1.1"> 
     12 
    713<!-- 
    814 
     15 
     16 
    917// if we find ourself outside the frameset, reload index.htm 
     18 
    1019if (top.location.href == self.location.href) { 
     20 
    1121        top.location.href = "Index.htm"; 
    12 
     22 
     23
     24 
     25 
    1326 
    1427//--> 
     28 
    1529</script> 
     30 
    1631</head> 
     32 
    1733<body bgcolor="#ffffff" onload="return LoadPage()"><!-- 
     34 
    1835--><form method="post" action="" name="ObjectForm" ><!-- 
     36 
    1937   --><OBJECT id=swishctl height=0 width=0  
     38 
    2039        classid=CLSID:9E204F2E-4F04-11D7-858F-8CA08FF5860C  
     40 
    2141        name=swish-e></OBJECT><!-- 
     42 
    2243--></form><!-- 
     44 
    2345--><form method="post" action="" name="QueryForm"  
     46 
    2447          onsubmit="return MM_callJS('DoQuery()')" 
     48 
    2549          onreset="return MM_callJS('ResetForm()')"> 
     50 
    2651    Query: <!-- 
     52 
    2753   --><input name="textfield" >&nbsp; 
     54 
    2855   <!-- 
     56 
    2957      from:&nbsp; 
     58 
    3059   <input id="startyear" name="start year" size="4" maxlength="4"> 
     60 
    3161      to:&nbsp; 
     62 
    3263   <input id="stopyear"  name="stop year"  size="4" maxlength="4"> 
     64 
    3365   sort by:&nbsp; 
     66 
    3467   <select name="sortorder"> 
     68 
    3569        <option value="decisionid desc" selected>Year (most recent first)</option> 
     70 
    3671        <option value="decisionid asc">Year (oldest first)</option> 
     72 
    3773        <option value="swishrank desc">Best match first</option> 
     74 
    3875      </select> 
     76 
    3977   --> 
     78 
    4079      <input type=hidden name="sortorder" value="swishrank desc"> 
     80 
    4181      <input type=submit value=Search name=Submit> 
     82 
    4283      <input type="reset" value="Reset"> 
     84 
    4385      <input id="previousresults" name="previousresults" type="image"  
     86 
    4487        onclick="return MM_callJS('DoPrevious()')" 
     88 
    4589        onmouseover="this.src='images/left-sel.gif';"   
     90 
    4691        onmouseout="this.src='images/left.gif';"  
     92 
    4793        src="images/left.gif" width="30" height="17">&nbsp;      
     94 
    4895   <input id="moreresults" name="moreresults" type="image"  
     96 
    4997        onclick="return MM_callJS('DoMore()')"  
     98 
    5099        onmouseover="this.src='images/right-sel.gif';"   
     100 
    51101        onmouseout="this.src='images/right.gif';" 
     102 
    52103        src="images/right.gif" width="30" height="17">&nbsp;<!-- 
     104 
    53105   --><input id="helppage" name="helppage" type="image"  
     106 
    54107        onclick="return MM_callJS('DoHelp()')"  
     108 
    55109        onmouseover="this.src='images/help-sel.gif';"   
     110 
    56111        onmouseout="this.src='images/help.gif';" 
     112 
    57113        src="images/help.gif" width="18" height="18">   <!-- 
     114 
    58115--></form> 
     116 
    59117<script language="JavaScript"> 
     118 
    60119<!-- 
    61120 
     121 
     122 
    62123var swishctl; 
     124 
    63125var firstresult; 
     126 
    64127var lastresult; 
     128 
    65129var resultcount; 
     130 
    66131var years;  
    67132 
     133 
     134 
    68135// change this to change the number of results per page  
     136 
    69137var resultsperpage = 10; 
    70138 
     139 
     140 
    71141function MM_callJS(jsStr) { //v2.0 
     142 
    72143  return eval(jsStr) 
    73 
     144 
     145
     146 
     147 
    74148 
    75149function ResetForm() 
    76 
     150 
     151
     152 
    77153    // called when form is reset - reloads globals 
     154 
    78155    // which as script is apprently reinitialised?? 
     156 
    79157        swishctl.Close(); 
    80         swishctl.Init("docs.idx"); 
     158 
     159        swishctl.Init("IndexFiles"); 
     160 
    81161        firstresult = 0; 
     162 
    82163        lastresult = 0; 
     164 
    83165        resultcount = 0; 
     166 
    84167        parent.BodyFrame.navigate( "bodyframe.htm" ); 
     168 
    85169        document.QueryForm.textfield.focus(); 
     170 
    86171        return true; 
    87 
     172 
     173
     174 
     175 
    88176 
    89177function LoadPage() 
    90 
     178 
     179
     180 
    91181    // loads global variables... 
     182 
    92183        swishctl = document.ObjectForm.swishctl; 
     184 
    93185        swishctl.Init("IndexFiles"); 
     186 
    94187        firstresult = 0; 
     188 
    95189        lastresult = 0; 
     190 
    96191        resultcount = 0; 
     192 
    97193        years = ""; 
     194 
    98195        return true; 
    99 
     196 
     197
     198 
     199 
    100200 
    101201function ShowRank( rank ) 
    102 
     202 
     203
     204 
    103205        // returns HTML img tag with n stars  
     206 
    104207        // where n depends on rank (somehow)  
     208 
    105209    return "&nbsp;"; 
     210 
    106211    var starcount=0; 
     212 
    107213    if ( rank > 950 ){ 
     214 
    108215        starcount=5; 
     216 
    109217    } else if ( rank > 900 ) { 
     218 
    110219        starcount=4; 
     220 
    111221    } else if ( rank > 800 ) { 
     222 
    112223        starcount=3; 
     224 
    113225    } else if ( rank > 500 ) { 
     226 
    114227        starcount=2; 
     228 
    115229    } else if ( rank > 100 ) { 
     230 
    116231        starcount=1; 
     232 
    117233    } else { 
     234 
    118235        starcount=0; 
     236 
    119237    } 
     238 
    120239    return "&nbsp;<img src=\"images/" + starcount  
     240 
    121241                + "stars.gif\" alt=\"" + rank + "*\">&nbsp;"; 
    122 
     242 
     243
     244 
     245 
     246 
    123247 
    124248 
    125249function ShowResults( startresult, lastresult, resultcount, comments ) 
    126 
     250 
     251
     252 
    127253        // generates results from swishctl and writes html to BodyFrame 
     254 
    128255        // inserts startresult, lastresult... in appropriate places  
     256 
    129257        var bodyFrame = parent.BodyFrame.document 
     258 
    130259        var querystring = document.QueryForm.textfield.value; 
    131260 
     261 
     262 
    132263        bodyFrame.open(); 
     264 
    133265        bodyFrame.writeln( 
     266 
    134267                "<html>\n<head>\n<title>Search Results</title>\n" 
     268 
    135269                + "<link rel=\"stylesheet\" href=\"styles/results.css\" media=\"screen\">"  
     270 
    136271                + "</head>\n<body>\n" 
     272 
    137273                + "<p class=\"swquery\">Query [<b>" + querystring + "</b>] "  
     274 
    138275                + comments + "\n returned: <b>" + resultcount   
     276 
    139277                + "</b> hits.</p>\n<p class=\"swrescount\">Results <b>"  
     278 
    140279                + startresult + "</b> to <b>" + lastresult  + "</b></p>"); 
    141280 
     281 
     282 
    142283        swishctl.SeekResult( startresult - 1 ); 
     284 
    143285  
     286 
    144287        for ( i = startresult; i <= lastresult; i++) 
     288 
    145289        { 
     290 
    146291                if (swishctl.NextResult()) { 
     292 
    147293                        bodyFrame.writeln( 
     294 
    148295                                "<p class=\"swres\">" + i  
     296 
    149297                                // uncomment the following to get **** showing rank of result 
     298 
    150299                                //+ ShowRank( swishctl.ResultPropertyString(  
     300 
    151301                                //      "swishrank" ))  
     302 
    152303                                + "&nbsp;<a href=\"" +  
     304 
    153305                                swishctl.ResultPropertyString( "swishdocpath" )  
     306 
    154307                                + "\" class=\"swref\">" 
     308 
    155309                                + swishctl.ResultPropertyString( "swishtitle" )  
     310 
    156311                                + "...</a><br>\n<span class=\"swdesc\">"  
     312 
    157313                                + swishctl.ResultPropertyString( "description" )   
     314 
    158315                                + "</span></p>\n" ); 
     316 
    159317                } else { 
     318 
    160319                        //alert("an error"); 
    161                 } 
    162         } 
     320 
     321                } 
     322 
     323        } 
     324 
    163325        bodyFrame.writeln("</body>\n"); 
     326 
    164327        bodyFrame.close(); 
     328 
    165329        document.QueryForm.textfield.focus(); 
    166330 
     331 
     332 
    167333        return true; 
    168 
     334 
     335
     336 
     337 
    169338 
    170339function ShowNoResults(comment) 
    171 
     340 
     341
     342 
    172343        // Writes "no results found" to BodyFrame in HTML  
     344 
    173345        var bodyFrame = parent.BodyFrame.document; 
     346 
    174347        var querystring = document.QueryForm.textfield.value; 
    175348 
     349 
     350 
    176351        bodyFrame.open(); 
     352 
    177353        bodyFrame.writeln( 
     354 
    178355                "<html><head><title>Search Results</title>\n" 
     356 
    179357                + "<link rel=\"stylesheet\" href=\"styles/results.css\" media=\"screen\">\n"  
     358 
    180359                + "</head>\n<p class=\"swquery\">Query [<b>"  
     360 
    181361                + querystring + "</b>] " + comment  
     362 
    182363                + " returned no results</p></body></html>"); 
     364 
    183365        bodyFrame.close(); 
    184 
     366 
     367
     368 
     369 
    185370 
    186371function LTrim( strval ) // like VB LTRIM 
    187 
     372 
     373
     374 
    188375        while ( strval.charAt(0) == " " ) { 
     376 
    189377                strval = strval.substring( 1, strval.length ); 
    190         } 
     378 
     379        } 
     380 
    191381        return (strval); 
    192 
     382 
     383
     384 
     385 
    193386 
    194387function CheckYear( yr )  
    195 
     388 
     389
     390 
    196391        // returns 4 digit year, or null if yr is bogus  
     392 
    197393        var intYear = parseInt( yr ); 
    198394 
     395 
     396 
    199397        if (isNaN(intYear)) return null; 
    200398 
     399 
     400 
    201401        if ( intYear >= 1000 ) { 
     402 
    202403                return yr; 
     404 
    203405        } else if ( intYear >= 100 ) { 
     406 
    204407                return null; // don't allow 3 digit years  
     408 
    205409        } else if ( intYear >= 10 ) { 
     410 
    206411                return "19" + intYear; 
     412 
    207413        } else if ( intYear >= 0 ) { 
     414 
    208415                return "200" + intYear; 
    209         } 
     416 
     417        } 
     418 
    210419        return null; 
    211 
     420 
     421
     422 
     423 
    212424 
    213425function DoQuery()  
    214 
     426 
     427
     428 
    215429        // called when form is submitted  
     430 
    216431        // gets variables from form, sets query parameters on swishctl  
     432 
    217433        // runs query and calls ShowResults... 
     434 
    218435/* Sample code for limit handling requires 4 digit year meta-tag in documents 
     436 
    219437        var startyr = document.QueryForm.startyear.value;  
     438 
    220439        var stopyr = document.QueryForm.stopyear.value; 
     440 
    221441        years = " (in the years"; 
     442 
    222443        if ( startyr ) { 
     444 
    223445                if ( !stopyr ) { 
     446 
    224447                        stopyr = "9999"; 
    225                 } 
     448 
     449                } 
     450 
    226451                startyr = CheckYear( startyr ); 
     452 
    227453                if ( startyr ) { 
     454 
    228455                        document.QueryForm.startyear.value = startyr;            
     456 
    229457                        years = years + " from " + startyr; 
     458 
    230459                } else { 
     460 
    231461                        alert( '"From" field should be the year as a number (e.g. 1995).' ); 
     462 
    232463                        document.QueryForm.startyear.focus();    
     464 
    233465                        return false; 
    234                 } 
    235         } 
     466 
     467                } 
     468 
     469        } 
     470 
    236471        if ( stopyr ) { 
     472 
    237473                if (!startyr) { 
     474 
    238475                        startyr = "0000"; 
    239                 } 
     476 
     477                } 
     478 
    240479                stopyr = CheckYear( stopyr ); 
     480 
    241481                if ( stopyr ) { 
     482 
    242483                        document.QueryForm.stopyear.value = stopyr;              
     484 
    243485                        years = years + " to " + stopyr; 
     486 
    244487                } else { 
     488 
    245489                        alert( '"To" field should be the year as a number (e.g. 2003).' ); 
     490 
    246491                        document.QueryForm.stopyear.focus(); 
     492 
    247493                        return false;    
    248                 } 
    249         } 
     494 
     495                } 
     496 
     497        } 
     498 
    250499        years = years + ") "; 
    251500 
     501 
     502 
    252503        if ( stopyr < startyr ) { 
     504 
    253505                alert( 'The "To:" field should be greater than "From:"' ); 
     506 
    254507                document.QueryForm.stopyear.focus(); 
     508 
    255509                return false;    
    256         } 
     510 
     511        } 
     512 
    257513*/       
     514 
    258515        var querystring = document.QueryForm.textfield.value; 
     516 
    259517         
     518 
    260519        //alert( querystring ); 
     520 
    261521        var res = swishctl.NewSearch( querystring ); 
    262522 
     523 
     524 
    263525        var sort = document.QueryForm.sortorder.value; 
     526 
    264527        swishctl.SetSort( sort ); 
    265528 
     529 
     530 
    266531        if ( swishctl.Error() != 0 ) { 
     532 
    267533                alert( "Swish-e returned error: " + swishctl.Error()); 
    268         } 
     534 
     535        } 
     536 
    269537/* Sample code for setting search limits  
     538 
    270539        if ( startyr && stopyr ) { 
     540 
    271541                swishctl.SetSearchLimit( "year", startyr, stopyr ); 
     542 
    272543        } else { 
     544 
    273545                years = ""; 
     546 
    274547        }        
     548 
    275549*/               
     550 
    276551        swishctl.Execute( querystring ); 
     552 
    277553        var i =1; 
     554 
    278555         
     556 
    279557        if ( swishctl.Hits() > 0 )  
     558 
    280559        { 
     560 
    281561                resultcount = swishctl.Hits(); 
     562 
    282563                firstresult = 1; 
     564 
    283565                if ( resultcount > resultsperpage ) { 
     566 
    284567                        lastresult = resultsperpage; 
     568 
    285569                } else { 
     570 
    286571                        lastresult = resultcount; 
    287                 } 
     572 
     573                } 
     574 
    288575                ShowResults( firstresult, lastresult, resultcount, years ); 
    289576 
     577 
     578 
    290579        } else { 
     580 
    291581                resultcount = 0; 
     582 
    292583                ShowNoResults(years); 
    293         } 
     584 
     585        } 
     586 
    294587        return false; 
    295 
     588 
     589
     590 
     591 
    296592 
    297593function DoMore()  
    298 
     594 
     595
     596 
    299597        // goes to next set of ten records  
     598 
    300599        // (increment globals and call ShowResults 
     600 
    301601        if ( resultcount == 0 ) { 
     602 
    302603                ShowNoResults(years); 
     604 
    303605                return false; 
     606 
    304607        }  
    305608 
     609 
     610 
    306611        if ( lastresult < resultcount ) { 
     612 
    307613                lastresult = lastresult + resultsperpage; 
     614 
    308615                firstresult = firstresult + resultsperpage; 
     616 
    309617                if ( lastresult > resultcount ) { 
     618 
    310619                        lastresult = resultcount; 
    311                 } 
     620 
     621                } 
     622 
    312623                //alert ("Do more " + firstresult + " / " + lastresult + " / " + resultcount); 
     624 
    313625                ShowResults( firstresult, lastresult, resultcount, years ); 
    314         } 
     626 
     627        } 
     628 
    315629        return false; 
    316 
     630 
     631
     632 
     633 
    317634 
    318635function DoPrevious() 
    319 
     636 
     637
     638 
    320639        // goes to previous set of ten records  
     640 
    321641        // (decrement globals and call ShowResults 
     642 
    322643        if ( resultcount == 0 ) { 
     644 
    323645                ShowNoResults(years); 
     646 
    324647                return false; 
     648 
    325649        }  
    326650 
     651 
     652 
    327653        if ( firstresult > 0  ) { 
     654 
    328655                firstresult = firstresult - resultsperpage; 
     656 
    329657                if ( firstresult < 0 ) { 
     658 
    330659                        firstresult = 1; 
    331                 } 
     660 
     661                } 
     662 
    332663                lastresult = firstresult + resultsperpage - 1; 
    333664 
     665 
     666 
    334667                if ( lastresult > resultcount ) { 
     668 
    335669                        lastresult = resultcount; 
    336                 } 
     670 
     671                } 
     672 
    337673                //alert ("Do previous " + firstresult + " / " + lastresult + " / " + resultcount); 
    338674 
     675 
     676 
    339677                ShowResults( firstresult, lastresult, resultcount, years ); 
    340         } 
     678 
     679        } 
     680 
    341681        return false; 
    342 
     682 
     683
     684 
     685 
    343686 
    344687function DoHelp() 
    345 
     688 
     689
     690 
    346691        // called when help button is clicked  
     692 
    347693        parent.BodyFrame.navigate( "srchhelp.htm" ); 
     694 
    348695        return false; 
    349 
     696 
     697
     698 
    350699//--> 
     700 
    351701</script> 
     702 
    352703</body> 
     704 
    353705</html> 
     706 
  • trunk/swishctl/src/CSwishCtl.cpp

    r1286 r1287  
    116116 
    117117{ 
    118  
    119118        // In order to claim "safe for scripting",  
    120  
    121119        // don't allow location of resources to be specified  
    122  
    123120        // as a parameter - for this application, the dll must 
    124  
    125121        // and the index files must reside in the same folder 
    126  
    127  
    128  
    129122        // So now the IndexFiles parameter is the name of a  
    130  
    131123        // registry value in the options key for this app 
    132  
    133  
    134  
    135         //BstrConverter bstr_indexfiles(IndexFiles); 
    136  
    137  
     124    CAnsiStr bstr_indexfiles(IndexFiles); 
    138125 
    139126        const char registrykey[] = "Software\\SWISH-E Team\\SwishCtl\\Options"; 
    140127 
    141128 
    142  
    143         CAnsiStr bstr_indexfiles(IndexFiles); 
    144  
    145  
    146  
    147129        RegKey hkcu(HKEY_LOCAL_MACHINE) ; 
    148130 
    149131 
    150  
    151  
    152  
    153132        string indexfilepath;  
    154133 
     
    163142                indexfilepath = hkcu.QueryValue( "IndexLocation"  ); 
    164143 
    165                 indexfilename = hkcu.QueryValue( "IndexFiles" ); 
     144                indexfilename = hkcu.QueryValue( bstr_indexfiles.c_str() ); 
    166145 
    167146        }