This file is indexed.

/usr/share/doc/swish-e/html/swish.cgi.html is in swish-e 2.4.7-4build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- 
    ***** GENERATED FILE *** DO NOT EDIT DIRECTLY - any changes will be LOST ******

    swish-e.org mockup based on http://www.oswd.org/design/1773/prosimii/index2.html 
-->


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-US">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" type="text/css" href="./swish.css" media="screen" title="swish css" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />

    
        <link rel="Last" href="./filter.html" />
    
        <link rel="Prev" href="./api.html" />
    
        <link rel="Up" href="./index.html" />
    
        <link rel="Next" href="./search.cgi.html" />
    
        <link rel="Start" href="./index.html" />
    
        <link rel="First" href="./readme.html" />
    

    <title>Swish-e :: swish.cgi -- Example Perl script for searching with the SWISH-E search engine.</title>


  </head>


<body>
    

    <!-- noindex -->

    <!-- For non-visual user agents: -->
      <div id="top"><a href="#main-copy" class="doNotDisplay doNotPrint">Skip to main content.</a></div>

    <!-- ##### Header ##### -->

    <div id="header">
      <div class="superHeader">
        <span>Related Sites:</span>
            <a href="http://swishewiki.org/" title="swishe wiki">swish-e wiki</a> |
            <a href="http://www.xmlsoft.org/" title="libxml2 home page">libxml2</a> |
            <a href="http://www.zlib.net/" title="zlib home page">zlib</a> |
            <a href="http://www.foolabs.com/xpdf/" title="xpdf home page">xpdf</a> |
            <a href="http://dev.swish-e.org/browser" title="browse source code">Subversion</a>
      </div>

      <div class="midHeader">
        <h1 class="headerTitle" lang="la">Swish-e</h1>
        <div class="headerSubTitle">Simple Web Indexing System for Humans - Enhanced</div>

        <br class="doNotDisplay doNotPrint" />

        <div class="headerLinks">
          <span class="doNotDisplay">Tools:</span>

              <!-- don't know what platform, so link to download page -->

              <a href="http://swish-e.org/download/index.html">download latest version</a>

        </div>
      </div>
    </div>
    <!-- index -->

<!-- noindex -->
<div class="subHeader">
    <table width='100%'>
        <tr>
            <td align='left'>
                <a href="http://swish-e.org/index.html">home</a> |
                <a href="http://swish-e.org/support.html">support</a> |
                <a href="http://swish-e.org/download/index.html">download</a>
            </td>


            
            <td align='right'>

                <form method="get"
                    action="http://swish-e.org/search/index.html"
                    enctype="application/x-www-form-urlencoded"
                    class="srchform">

                    <label for="searchfield">Search for</label>
                    <input maxlength="200" value="" id="searchfield" size="30" name="query" type="text" alt="Search input field" />
                    <input value="search swish-e.org" name="submit" type="submit" class='button' />
                </form>

            </td>
            
        </tr>
    </table>
</div>
<!-- index -->


<div id="body-area" class="clearfix">

    <div id="content-area">

        <div id="main-copy">
            
            
            
            
<h1>swish.cgi -- Example Perl script for searching with the SWISH-E search engine.</h1>
Swish-e version 2.4.7



    <!-- noindex -->

    
        <h2>Table of Contents</h2>
        <div class="toc">
            
    <ul class="toc">
        
            <li>
                <a href="#description">DESCRIPTION</a>
                
            </li>
        
            <li>
                <a href="#requirements">REQUIREMENTS</a>
                
            </li>
        
            <li>
                <a href="#installation">INSTALLATION</a>
                
            </li>
        
            <li>
                <a href="#configuration">CONFIGURATION</a>
                
            </li>
        
            <li>
                <a href="#debugging">DEBUGGING</a>
                
            </li>
        
            <li>
                <a href="#frequently_asked_questions">Frequently Asked Questions</a>
                
    <ul class="toc">
        
            <li>
                <a href="#how_do_i_change_the_way_the_output_looks_">How do I change the way the output looks?</a>
                
            </li>
        
            <li>
                <a href="#how_do_i_use_a_templating_system_with_swish_cgi_">How do I use a templating system with swish.cgi?</a>
                
            </li>
        
            <li>
                <a href="#why_are_there_three_different_highlighting_modules_">Why are there three different highlighting modules?</a>
                
            </li>
        
            <li>
                <a href="#my_isp_doesn_t_provide_access_to_the_web_server_logs">My ISP doesn't provide access to the web server logs</a>
                
            </li>
        
            <li>
                <a href="#why_does_the_output_show_null_">Why does the output show (NULL)?</a>
                
            </li>
        
            <li>
                <a href="#how_do_i_use_the_swish_api_perl_module_with_swish_cgi_">How do I use the SWISH::API perl module with swish.cgi?</a>
                
            </li>
        
            <li>
                <a href="#why_does_the_run_time_differ_when_using_the_swish_api_module">Why does the "Run time" differ when using the SWISH::API module</a>
                
            </li>
        
    </ul>

            </li>
        
            <li>
                <a href="#mod_perl">MOD_PERL</a>
                
            </li>
        
            <li>
                <a href="#speedycgi">SpeedyCGI</a>
                
            </li>
        
            <li>
                <a href="#spidering">Spidering</a>
                
            </li>
        
            <li>
                <a href="#stemmed_indexes">Stemmed Indexes</a>
                
            </li>
        
            <li>
                <a href="#disclaimer">DISCLAIMER</a>
                
            </li>
        
            <li>
                <a href="#support">SUPPORT</a>
                
            </li>
        
            <li>
                <a href="#license">LICENSE</a>
                
            </li>
        
            <li>
                <a href="#author">AUTHOR</a>
                
            </li>
        
    </ul>

        </div>
    
    <!-- index -->





<hr />


    <div class="sub-section">
        
<h1><a name="description"></a>DESCRIPTION</h1>

<p><code>swish.cgi</code> is a CGI script for searching with the SWISH-E search
engine version 2.1-dev and above.  It returns results a page at a
time, with matching words from the source document highlighted,
showing a few words of content on either side of the highlighted word.</p>
<p>The script is highly configurable.  Features include searching
multiple (or selectable) indexes, limiting searches to a subset of documents,
sorting by a number of different properties, and limiting results to
a date range.</p>
<p>On unix type systems the swish.cgi script is installed in the directory
$prefix/lib/swish-e, which is typically /usr/local/lib/swish-e.  This
can be overridden by the configure options --prefix or --libexecdir.</p>
<p>The standard configuration (i.e. not using a config file) should work
with most swish index files.  Customization of the parameters will be
needed if you are indexing special meta data and want to search and/or
display the meta data.  The configuration can be modified by editing
this script directly, or by using a configuration file (.swishcgi.conf
by default).  The script's configuration file is described below.</p>
<p>You are strongly encouraged to get the default configuration working
before making changes.  Most problems using this script are the result
of configuration modifications.</p>
<p>The script is modular in design.  Both the highlighting code and
output generation is handled by modules, which are included in the
<i>example/modules</i> distribution directory and installed in the
$libexecdir/perl directory.
This allows for easy customization of
the output without changing the main CGI script.</p>
<p>Included with the Swish-e distribution is a module to generate standard HTML
output.  There's also modules and template examples to use with the popular
Perl templating systems HTML::Template and Template-Toolkit.  This is very
useful if your site already uses one of these templating systems The
HTML::Template and Template-Toolkit packages are not distributed with
Swish-e.  They are available from the CPAN (<a href="http://search.cpan.org">http://search.cpan.org</a>).</p>
<p>This scipt can also run basically unmodified as a mod_perl handler,
providing much better performance than running as a CGI script.  Usage
under mod_perl is described below.</p>
<p>Please read the rest of the documentation.  There's a <code>DEBUGGING</code>
section, and a <code>FAQ</code> section.</p>
<p>This script should work on Windows, but security may be an issue.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="requirements"></a>REQUIREMENTS</h1>

<p>A reasonably current version of Perl.  5.00503
or above is recommended (anything older will not be supported).</p>
<p>The Date::Calc module is required to use the date range feature of the script.
The Date::Calc module is also available from CPAN.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="installation"></a>INSTALLATION</h1>

<p>Here's an example installation session under Linux.  It should be
similar for other operating systems.</p>
<p>For the sake of simplicity in this installation example all files are
placed in web server space, including files such as swish-e index and
configuration files that would normally not be made available via the
web server.  Access to these files should be limited once the script
is running.  Either move the files to other locations (and adjust the
script's configuration) or use features of the web server to limit
access (such as with <i>.htaccess</i>).</p>
<p>Please get a simple installation working before modifying the
configuration file.  Most problems reported for using this script have
been due to improper configuration.</p>
<p>The script's default settings are setup for initial testing.  By default the settings expect
to find most files and the swish-e binary in the same directory as the script.</p>
<p>For <i>security</i> reasons, once you have tested the script you will want to change settings to
limit access to some of these files by the web server (either by moving them out of web
space, or using access control such as <i>.htaccess</i>). An example of using <i>.htaccess</i> on
Apache is given below.</p>
<p>It's expected that swish-e has already been unpacked and the swish-e binary has be compiled
from source and "make install" has been run. If swish-e was installed from a vendor package
(such as from a RPM or Debian package) see that pakage's documentation for where files are
installed.</p>
<p>Example Installation:</p>
<ol>
<li><a name="item_1"></a><a name="1"></a><b>1 Symlink or copy the swish.cgi.</b>
<p>Symlink (or copy if your platform or webserver does not allow symlinks)
the swish.cgi script from the installation directory to a local directory.
Typically, this would be the cgi-bin directory or a location where CGI script
are located.  In this example a new directory is created and the script is
symlinked.</p>
<pre class="pre-section">    ~$ mkdir swishdir
    ~$ cd swishdir
    ~/swishdir$ ln -s /usr/local/lib/swish-e/swish.cgi</pre>
<p>The installation directory is set at configure time with the --prefix or
--libexecdir options, but by default is in /usr/local/lib/swish-e.</p>
</li>
<li><a name="item_2"></a><a name="2"></a><b>2 Create an index</b>
<p>Use an editor and create a simple configuration file for indexing your
files.  In this example the Apache documentation is indexed.  Last we
run a simple query to test that the index works correctly.</p>
<pre class="pre-section">    ~/swishdir$ cat swish.conf
    IndexDir /usr/local/apache/htdocs
    IndexOnly .html .htm
    DefaultContents HTML*
    StoreDescription HTML* &lt;body&gt; 200000
    MetaNames swishdocpath swishtitle
    ReplaceRules remove /usr/local/apache/</pre>
<p>If you do not have the Apache docs installed then pick another directory to index
such as /usr/share/doc.</p>
<p>Create the index.</p>
<pre class="pre-section">    ~/swishdir$ swish-e -c swish.conf
    Indexing Data Source: "File-System"
    Indexing "/usr/local/apache/htdocs"
    Removing very common words...
    no words removed.
    Writing main index...
    Sorting words ...
    Sorting 7005 words alphabetically
    Writing header ...
    Writing index entries ...
      Writing word text: Complete
      Writing word hash: Complete
      Writing word data: Complete
    7005 unique words indexed.
    5 properties sorted.
    124 files indexed.  1485844 total bytes.  171704 total words.
    Elapsed time: 00:00:02 CPU time: 00:00:02
    Indexing done!</pre>
<p>Now, verify that the index can be searched:</p>
<pre class="pre-section">    ~/swishdir$ swish-e -w install -m 1
    # SWISH format: 2.1-dev-25
    # Search words: install
    # Number of hits: 14
    # Search time: 0.001 seconds
    # Run time: 0.040 seconds
    1000 htdocs/manual/dso.html "Apache 1.3 Dynamic Shared Object (DSO) support" 17341
    .</pre>
<p>Let's see what files we have in our directory now:</p>
<pre class="pre-section">    ~/swishdir$ ls -1
    index.swish-e
    index.swish-e.prop
    swish.cgi
    swish.conf</pre>
</li>
<li><a name="item_3"></a><a name="3"></a><b>3 Test the CGI script</b>
<p>This is a simple step, but often overlooked.  You should test from the command line instead of jumping
ahead and testing with the web server.  See the <code>DEBUGGING</code> section below for more information.</p>
<pre class="pre-section">    ~/swishdir$ ./swish.cgi | head
    Content-Type: text/html; charset=ISO-8859-1

    &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
    &lt;html&gt;
        &lt;head&gt;
           &lt;title&gt;
              Search our site
           &lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;</pre>
<p>The above shows that the script can be run directly, and generates a correct HTTP header and HTML.</p>
<p>If you run the above and see something like this:</p>
<pre class="pre-section">    ~/swishdir &gt;./swish.cgi
    bash: ./swish.cgi: No such file or directory</pre>
<p>then you probably need to edit the script to point to the correct location of your perl program.
Here's one way to find out where perl is located (again, on unix):</p>
<pre class="pre-section">    ~/swishdir$ which perl
    /usr/local/bin/perl

    ~/swishdir$ /usr/local/bin/perl -v
    This is perl, v5.6.0 built for i586-linux
    ...</pre>
<p>Good! We are using a reasonably current version of perl.</p>
<p>Now that we know perl is at <i>/usr/local/bin/perl</i> we can adjust the "shebang" line
in the perl script (e.g. the first line of the script):</p>
<pre class="pre-section">    ~/swishdir$ pico swish.cgi
    (edit the #! line)
    ~/swishdir$ head -1 swish.cgi
    #!/usr/local/bin/perl -w</pre>
</li>
<li><a name="item_4"></a><a name="4"></a><b>4 Test with the web server</b>
<p>How you do this is completely dependent on your web server, and you may need to talk to your web
server admin to get this working.  Often files with the .cgi extension are automatically set up to
run as CGI scripts, but not always.  In other words, this step is really up to you to figure out!</p>
<p>This example shows creating a <i>symlink</i> from the web server space to the directory used above.
This will only work if the web server is configured to follow symbolic links (the default for Apache).</p>
<p>This operation requires root access:</p>
<pre class="pre-section">    ~/swishdir$ su -c "ln -s $HOME/swishdir /usr/local/apache/htdocs/swishdir"
    Password: *********</pre>
<p>If your account is on an ISP and your web directory is <i>~/public_html</i> the you might just move the entire
directory:</p>
<pre class="pre-section">    mv ~/swishdir ~/public_html</pre>
<p>Now, let's make a real HTTP request:</p>
<pre class="pre-section">    ~/swishdir$ GET http://localhost/swishdir/swish.cgi | head -3
    #!/usr/local/bin/perl -w
    package SwishSearch;
    use strict;</pre>
<p>Oh, darn. It looks like Apache is not running the script and instead returning it as a
static page.  Apache needs to be told that swish.cgi is a CGI script.</p>
<p><i>.htaccess</i> comes to the rescue:</p>
<pre class="pre-section">    ~/swishdir$ cat .htaccess

    # Deny everything by default
    Deny From All

    # But allow just CGI script
    &lt;files swish.cgi&gt;
        Options ExecCGI
        Allow From All
        SetHandler cgi-script
    &lt;/files&gt;</pre>
<p>That "Deny From All" prevents access to all files (such as config and index files), and only access is allowed to the
<i>swish.cgi</i> script.</p>
<p>Let's try the request one more time:</p>
<pre class="pre-section">    ~/swishdir &gt;GET http://localhost/swishdir/swish.cgi | head
    &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
    &lt;html&gt;
        &lt;head&gt;
           &lt;title&gt;
              Search our site
           &lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;
            &lt;h2&gt;
            &lt;a href="http://swish-e.org"&gt;</pre>
<p>That looks better!  Now use your web browser to test.</p>
<p>Now, you may note that the links are not valid on the search results page.  The swish config file
contained the line:</p>
<pre class="pre-section">     ReplaceRules remove /usr/local/apache/</pre>
<p>To make those links works (and assuming your web server will follow symbolic links):</p>
<pre class="pre-section">    ~/swishtest$ ln -s /usr/local/apache/htdocs</pre>
<p>BTW - "GET" used above is a program included with Perl's LWP library.  If you do no have this you might
try something like:</p>
<pre class="pre-section">    wget -O - http://localhost/swishdir/swish.cgi | head</pre>
<p>and if nothing else, you can always telnet to the web server and make a basic request.</p>
<pre class="pre-section">    ~/swishtest$ telnet localhost 80
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    GET /swishtest/swish.cgi http/1.0

    HTTP/1.1 200 OK
    Date: Wed, 13 Feb 2002 20:14:31 GMT
    Server: Apache/1.3.20 (Unix) mod_perl/1.25_01
    Connection: close
    Content-Type: text/html; charset=ISO-8859-1

    &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
    &lt;html&gt;
        &lt;head&gt;
           &lt;title&gt;
              Search our site
           &lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;</pre>
<p>This may seem like a lot of work compared to using a browser, but browsers
are a poor tool for basic CGI debugging.</p>
</li>
</ol>
<p>If you have problems check the <code>DEBUGGING</code> section below.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="configuration"></a>CONFIGURATION</h1>

<p>If you want to change the location of the swish-e binary or the index
file, use multiple indexes, add additional metanames and properties,
change the default highlighting behavior, etc., you will need to
adjust the script's configuration settings.</p>
<p>Again, please get a test setup working with the default parameters before
making changes to any configuration settings.  Better to debug one
thing at a time...</p>
<p>In general, you will need to adjust the script's settings to match the
index file you are searching.  For example, if you are indexing a
hypermail list archive you may want to make the script use
metanames/properties of Subject, Author, and, Email address.  Or you
may wish to provide a way to limit searches to subsets of documents
(e.g. parts of your directory tree).</p>
<p>To make things somewhat "simple", the configuration parameters are
included near the top of the swish.cgi program.  That is the only
place that the individual parameters are defined and explained, so you
will need to open up the swish.cgi script in an editor to view the
options.  Further questions about individual settings should be
referred to the swish-e discussion list.</p>
<p>The parameters are all part of a perl <code>hash</code> structure, and the
comments at the top of the program should get you going.  The perl
hash structure may seem a bit confusing, but it makes it easy to
create nested and complex parameters.  Syntax is important, so
cut-n-paste should be your best defense if you are not a perl
programmer.</p>
<p>By the way, Perl has a number of quote operators.  For example, to
quote a string you might write:</p>
<pre class="pre-section">    title =&gt; 'Search My Site',</pre>
<p>Some options take more than one parameter, where each parameter must
be quoted.  For example:</p>
<pre class="pre-section">    metanames =&gt; [ 'swishdefault', 'swishtitle',  'swishdocpath' ],</pre>
<p>which assigns an array ( [...] ) of three strings to the "metanames"
variable.  Lists of quoted strings are so common in perl that there's
a special operator called "qw" (quote word) to save typing all those quotes:</p>
<pre class="pre-section">    metanames =&gt; [ qw/ swishdefault swishtitle swishdocpath / ],</pre>
<p>or to use the parenthesis as the quote character (you can pick any):</p>
<pre class="pre-section">    metanames =&gt; [ qw( swishdefault swishtitle swishdocpath ) ],</pre>
<p>There are two options for changing the configuration settings from
their default values: One way is to edit the script directly, or the
other was is to use a separate configuration file.  In either case,
the configuration settings are a basic perl hash reference.</p>
<p>Using a configuration file is described below, but contains the same hash structure.</p>
<p>There are many configuration settings, and some of them are commented out either by using
a "#" symbol, or by simply renaming the configuration directive (e.g. by adding an "x" to the parameter
name).</p>
<p>A very basic configuration setup might look like:</p>
<pre class="pre-section">    return {
        title           =&gt; 'Search the Swish-e list',   # Title of your choice.
        swish_binary    =&gt; 'swish-e',                   # Location of swish-e binary
        swish_index     =&gt; 'index.swish-e',             # Location of your index file
    };</pre>
<p>Or if searching more than one index:</p>
<pre class="pre-section">    return {
        title           =&gt; 'Search the Swish-e list',
        swish_binary    =&gt; 'swish-e',
        swish_index     =&gt; ['index.swish-e', 'index2'],
    };</pre>
<p>Both of these examples return a reference to a perl hash ( <code>return
{...}</code> ).  In the second example, the multiple index files are set as
an array reference.</p>
<p>Note that in the example above the swish-e binary file is relative to
the current directory.  If running under mod_perl you will need to use
absolute paths.</p>
<p>The script can also use the SWISH::API perl module (included with the
swish-e distribution in the <i>perl</i> directory) to access the swish-e
index.  The <code>use_library</code> option is used to enable the use of the
SWISH::API module:</p>
<pre class="pre-section">    return {
        title           =&gt; 'Search the Swish-e list',
        swish_index     =&gt; ['index.swish-e', 'index2'],
        use_library     =&gt; 1, # enable use of the SWISH::API module
    };</pre>
<p>The module must be available via the @INC array, like all Perl modules.</p>
<p>Using the SWISH::API module avoids the need to fork and execute a
the swish-e program.  Under mod_perl you will may see a significant
performance improvement when using the SWISH::API module.  Under
normal CGI usage you will probably not see any speed improvements.</p>
<p><b>Using A Configuration File</b></p>
<p>As mentioned above, configuration settings can be either set in the
<i>swish.cgi</i> script, or set in a separate configuration file.
Settings in a configuration file will override the settings in the
script.</p>
<p>By default, the <i>swish.cgi</i> script will attempt to read settings from the file <i>.swishcgi.conf</i>.
For example, you might only wish to change the title used
in the script.  Simply create a file called <i>.swishcgi.conf</i> in the same directory as the CGI script:</p>
<pre class="pre-section">    &gt; cat .swishcgi.conf
    # Example swish.cgi configuration script.
    return {
       title =&gt; 'Search Our Mailing List Archive',
    };</pre>
<p>The settings you use will depend on the index you create with swish:</p>
<pre class="pre-section">   return {
        title           =&gt; 'Search the Apache documentation',
        swish_binary    =&gt; 'swish-e',
        swish_index     =&gt; 'index.swish-e',
        metanames       =&gt; [qw/swishdefault swishdocpath swishtitle/],
        display_props   =&gt; [qw/swishtitle swishlastmodified swishdocsize swishdocpath/],
        title_property  =&gt; 'swishdocpath',
        prepend_path    =&gt; 'http://myhost/apachedocs',

        name_labels =&gt; {
            swishdefault        =&gt; 'Search All',
            swishtitle          =&gt; 'Title',
            swishrank           =&gt; 'Rank',
            swishlastmodified   =&gt; 'Last Modified Date',
            swishdocpath        =&gt; 'Document Path',
            swishdocsize        =&gt; 'Document Size',
        },

    };</pre>
<p>The above configuration defines metanames to use on the form.
Searches can be limited to these metanames.</p>
<p>"display_props" tells the script to display the property "swishlastmodified" (the last modified
date of the file), the document size, and path with the search results.</p>
<p>The parameter "name_labels" is a hash (reference)
that is used to give friendly names to the metanames.</p>
<p>Here's another example.  Say you want to search either (or both) the Apache 1.3 documentation and the
Apache 2.0 documentation indexed seperately.</p>
<pre class="pre-section">    return {
       title       =&gt; 'Search the Apache Documentation',
       date_ranges =&gt; 0,
       swish_index =&gt; [ qw/ index.apache index.apache2 / ],
       select_indexes  =&gt; {
            method  =&gt; 'checkbox_group',
            labels  =&gt; [ '1.3.23 docs', '2.0 docs' ],  # Must match up one-to-one to swish_index
            description =&gt; 'Select: ',
        },

    };</pre>
<p>Now you can select either or both sets of documentation while searching.</p>
<p>All the possible settings are included in the default configuration located near the top of the <i>swish.cgi</i>
script.  Open the <i>swish.cgi</i> script with an editor to look at the various settings.  Contact the Swish-e Discussion list
for help in configuring the script.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="debugging"></a>DEBUGGING</h1>

<p>Most problems with using this script have been a result of improper configuration.  Please
get the script working with default settings before adjusting the configuration settings.</p>
<p>The key to debugging CGI scripts is to run them from the command line, not with a browser.</p>
<p>First, make sure the program compiles correctly:</p>
<pre class="pre-section">    $ perl -c swish.cgi
    swish.cgi syntax OK</pre>
<p>Next, simply try running the program:</p>
<pre class="pre-section">    $ ./swish.cgi | head
    Content-Type: text/html; charset=ISO-8859-1

    &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
    &lt;html&gt;
        &lt;head&gt;
           &lt;title&gt;
              Search our site
           &lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;</pre>
<p>Under Windows you will need to run the script as:</p>
<pre class="pre-section">   C:\wwwroot\swishtest&gt; perl swish.cgi</pre>
<p>Now, you know that the program compiles and will run from the command line.
Next, try accessing the script from a web browser.</p>
<p>If you see the contents of the CGI script instead of its output then
your web server is not configured to run the script.  With Apache look
at settings like ScriptAlias, SetHandler, and Options.</p>
<p>If an error is reported (such as Internal Server Error or Forbidden)
you need to locate your web server's error_log file and carefully read
what the problem is.  Contact your web administrator for help locating
the web server's error log.</p>
<p>If you don't have access to the web server's error_log file, you can
modify the script to report errors to the browser screen.  Open the
script and search for "CGI::Carp".  (Author's suggestion is to debug
from the command line -- adding the browser and web server into the
equation only complicates debugging.)</p>
<p>The script does offer some basic debugging options that allow
debugging from the command line.  The debugging options are enabled by
setting an environment variable "SWISH_DEBUG".  How that is set
depends on your operating system and the shell you are using.  These
examples are using the "bash" shell syntax.</p>
<p>Note: You can also use the "debug_options" configuration setting, but
the recommended method is to set the environment variable.</p>
<p>You can list the available debugging options like this:</p>
<pre class="pre-section">    $ SWISH_DEBUG=help ./swish.cgi &gt;outfile
    Unknown debug option 'help'.  Must be one of:
           basic: Basic debugging
         command: Show command used to run swish
         headers: Show headers returned from swish
          output: Show output from swish
         summary: Show summary of results
            dump: Show all data available to templates</pre>
<p>Debugging options may be combined:</p>
<pre class="pre-section">    $ SWISH_DEBUG=command,headers,summary ./swish.cgi &gt;outfile</pre>
<p>You will be asked for an input query and the max number of results to return.  You can use the defaults
in most cases.  It's a good idea to redirect output to a file.  Any error messages are sent to stderr, so
those will still be displayed (unless you redirect stderr, too).</p>
<p>Here are some examples:</p>
<pre class="pre-section">    ~/swishtest$ SWISH_DEBUG=basic ./swish.cgi &gt;outfile
    Debug level set to: 1
    Enter a query [all]:
    Using 'not asdfghjklzxcv' to match all records
    Enter max results to display [1]:

    ------ Can't use DateRanges feature ------------

    Script will run, but you can't use the date range feature
    Can't locate Date/Calc.pm in @INC (@INC contains: modules /usr/local/lib/perl5/5.6.0/i586-linux /usr/local/lib/perl5/5.6.0 /usr/local/lib/perl5/site_perl/5.6.0/i586-linux /usr/local/lib/perl5/site_perl/5.6.0 /usr/local/lib/perl5/site_perl/5.005/i586-linux /usr/local/lib/perl5/site_perl/5.005 /usr/local/lib/perl5/site_perl .) at modules/DateRanges.pm line 107, &lt;STDIN&gt; line 2.
    BEGIN failed--compilation aborted at modules/DateRanges.pm line 107, &lt;STDIN&gt; line 2.
    Compilation failed in require at ./swish.cgi line 971, &lt;STDIN&gt; line 2.

    --------------
    Can't exec "./swish-e": No such file or directory at ./swish.cgi line 1245, &lt;STDIN&gt; line 2.
    Child process Failed to exec './swish-e' Error: No such file or directory at ./swish.cgi line 1246, &lt;STDIN&gt; line 2.
    Failed to find any results</pre>
<p>The above indicates two problems.  First problem is that the Date::Calc module is not installed.
The Date::Calc module is needed to use the date limiting feature of the script.</p>
<p>The second problem is a bit more serious.  It's saying that the script can't find the
swish-e binary file. In this example it's specified as being in the current directory.
Either correct the path to the swish-e binary, or make a local copy or symlink to the
swish-e binary.</p>
<pre class="pre-section">    ~/swishtest$ cat .swishcgi.conf
        return {
           title       =&gt; 'Search the Apache Documentation',
           swish_binary =&gt; '/usr/local/bin/swish-e',
           date_ranges =&gt; 0,
        };</pre>
<p>Now, let's try again:</p>
<pre class="pre-section">    ~/swishtest$ SWISH_DEBUG=basic ./swish.cgi &gt;outfile
    Debug level set to: 1

    ---------- Read config parameters from '.swishcgi.conf' ------
    $VAR1 = {
              'date_ranges' =&gt; 0,
              'title' =&gt; 'Search the Apache Documentation'
            };
    -------------------------
    Enter a query [all]:
    Using 'not asdfghjklzxcv' to match all records
    Enter max results to display [1]:
    Found 1 results

    Can't locate SWISH::TemplateDefault.pm in @INC (@INC contains: modules /usr/local/lib/perl5/5.6.0/i586-linux /usr/local/lib/perl5/5.6.0 /usr/local/lib/perl5/site_perl/5.6.0/i586-linux /usr/local/lib/perl5/site_perl/5.6.0 /usr/local/lib/perl5/site_perl/5.005/i586-linux /usr/local/lib/perl5/site_perl/5.005 /usr/local/lib/perl5/site_perl .) at ./swish.cgi line 608.</pre>
<p>This means that the swish.cgi script could not locate a required module.  To correct this
locate where the SWISH::Template module is installed and add a "use lib" line to
your configuration file (or to the swish.cgi script):</p>
<pre class="pre-section">    ~/swishtest$ cat .swishcgi.conf
    use lib '/home/bill/local/lib/perl';

    return {
       title       =&gt; 'Search the Apache Documentation',
       date_ranges =&gt; 0,
    };

    ~/swishtest$ SWISH_DEBUG=basic ./swish.cgi &gt;outfile
    Debug level set to: 1

    ---------- Read config parameters from '.swishcgi.conf' ------
    $VAR1 = {
              'date_ranges' =&gt; 0,
              'title' =&gt; 'Search the Apache Documentation'
            };
    -------------------------
    Enter a query [all]:
    Using 'not asdfghjklzxcv' to match all records
    Enter max results to display [1]:
    Found 1 results</pre>
<p>That is much better!</p>
<p>The "use lib" statement tells Perl where to look for modules by adding the path supplied
to an array called @INC.</p>
<p>Note that most modules are in the SWISH namespace.  For example, the default output
module is called SWISH::TemplateDefault.  When Perl is looking for that module it is looking for
the file <i>SWISH/TemplateDefault.pm</i>.  If the "use lib" statement is set as:</p>
<pre class="pre-section">    use lib '/home/bill/local/lib/perl';</pre>
<p>then Perl will look (among other places) for the file</p>
<pre class="pre-section">    /home/bill/local/lib/perl/SWISH/TemplateDefault.pm</pre>
<p>when attempting to load the SWISH::TemplateDefault module.  Relative paths may also be used.</p>
<pre class="pre-section">    use lib 'modules';</pre>
<p>will cause Perl to look for the file:</p>
<pre class="pre-section">    ./modules/SWISH/TemplateDefault.pm</pre>
<p>relative to where the swish.cgi script is running.  (This is not true when running under mod_perl).</p>
<p>Here's another common problem.  Everything checks out, but when you run the script you see
the message:</p>
<pre class="pre-section">    Swish returned unknown output</pre>
<p>Ok, let's find out what output it is returning:</p>
<pre class="pre-section">    ~/swishtest$ SWISH_DEBUG=headers,output ./swish.cgi &gt;outfile
    Debug level set to: 13

    ---------- Read config parameters from '.swishcgi.conf' ------
    $VAR1 = {
              'swish_binary' =&gt; '/usr/local/bin/swish-e',
              'date_ranges' =&gt; 0,
              'title' =&gt; 'Search the Apache Documentation'
            };
    -------------------------
    Enter a query [all]:
    Using 'not asdfghjklzxcv' to match all records
    Enter max results to display [1]:
      usage: swish [-i dir file ... ] [-S system] [-c file] [-f file] [-l] [-v (num)]
      ...
    version: 2.0
       docs: http://sunsite.berkeley.edu/SWISH-E/

    *** 9872 Failed to run swish: 'Swish returned unknown output' ***
    Failed to find any results</pre>
<p>Oh, looks like /usr/local/bin/swish-e is version 2.0 of swish.  We need 2.1-dev and above!</p>

    </div>

    <div class="sub-section">
        
<h1><a name="frequently_asked_questions"></a>Frequently Asked Questions</h1>

<p>Here's some common questions and answers.</p>

    </div>

    <div class="sub-section">
        
<h2><a name="how_do_i_change_the_way_the_output_looks_"></a>How do I change the way the output looks?</h2>

<p>The script uses a module to generate output.  By default it uses the
SWISH::TemplateDefault.pm module. The module used is selected in the
swish.cgi configuration file.  Modules are located in the
example/modules/SWISH directory in the distribution, but are installed in
the $prefix/lib/swish-e/perl/SWISH/ directory.</p>
<p>To make simple changes you can edit the installed SWISH::TemplatDefault
module directly, otherwise make a copy of the module and modify its package
name.  For example, change directories to the location of the installed
module and copy the module to a new name:</p>
<pre class="pre-section">    $ cp TemplateDefault.pm MyTemplateDefault.pm</pre>
<p>Then at the top of the module adjust the "package" line to:</p>
<pre class="pre-section">    package SWISH::MyTemplateDefault;</pre>
<p>To use this modules you need to adjust the configuration settings (either at
the top of <i>swish.cgi</i> or in a configuration file:</p>
<pre class="pre-section">        template =&gt; {
            package     =&gt; 'SWISH::MyTemplateDefault',
        },</pre>
<p>The module does not need to be in the SWISH namespace, and can be stored in
any location as long as the module can be found via the @INC array (i.e.
modify the "use lib" statement in swish.cgi if needed).</p>

    </div>

    <div class="sub-section">
        
<h2><a name="how_do_i_use_a_templating_system_with_swish_cgi_"></a>How do I use a templating system with swish.cgi?</h2>

<p>In addition to the TemplateDefault.pm module, the swish-e distribution includes two other Perl modules for
generating output using the templating systems HTML::Template and Template-Toolkit.</p>
<p>Templating systems use template files to generate the HTML, and make maintaining the look of a large (or small) site
much easier. HTML::Template and Template-Toolkit are separate packages and can be downloaded from the CPAN.
See <a href="http://search.cpan.org">http://search.cpan.org</a>.</p>
<p>Two basic templates are provided as examples for generating output using these templating systems.
The example templates are located in the <i>example</i> directory.
The module <i>SWISH::TemplateHTMLTemplate</i> uses the file <i>swish.tmpl</i> to generate its output, while the
module <i>SWISH::TemplateToolkit</i> uses the <i>swish.tt</i> file.
(Note: swish.tt was renamed from search.tt Jun 03, 2004.)</p>
<p>To use either of these modules you will need to adjust the "template" configuration setting.  Examples for
both templating systems are provided in the configuration settings near the top of the <i>swish.cgi</i> program.</p>
<p>Use of these modules is an advanced usage of <i>swish.cgi</i> and are provided as examples only.</p>
<p>All of the output generation modules are passed a hash with the results from the search, plus other data use to create the
output page.  You can see this hash by using the debugging option "dump" or by using the included SWISH::TemplateDumper
module:</p>
<pre class="pre-section">    ~/swishtest &gt;cat .swishcgi.conf
        return {
           title       =&gt; 'Search the Apache Documentation',
           template =&gt; {
                package     =&gt; 'SWISH::TemplateDumper',
            },
        };</pre>
<p>And run a query.  For example:</p>
<pre class="pre-section">    http://localhost/swishtest/swish.cgi?query=install</pre>

    </div>

    <div class="sub-section">
        
<h2><a name="why_are_there_three_different_highlighting_modules_"></a>Why are there three different highlighting modules?</h2>

<p>Three are three highlighting modules included with the swish-e distribution.
Each is a trade-off of speed vs. accuracy:</p>
<pre class="pre-section">    SWISH::DefaultHighlight - reasonably fast, but does not highlight phrases
    SWISH::PhraseHighlight  - reasonably slow, but is reasonably accurate
    SWISH::SimpleHighlight  - fast, some phrases, but least accurate</pre>
<p>Eh, the default is actually "PhraseHighlight".  Oh well.</p>
<p>All of the highlighting modules slow down the script.  Optimizations to these modules are welcome!</p>

    </div>

    <div class="sub-section">
        
<h2><a name="my_isp_doesn_t_provide_access_to_the_web_server_logs"></a>My ISP doesn't provide access to the web server logs</h2>

<p>There are a number of options.  One way it to use the CGI::Carp module.  Search in the
swish.cgi script for:</p>
<pre class="pre-section">    use Carp;
    # Or use this instead -- PLEASE see perldoc CGI::Carp for details
    # use CGI::Carp qw(fatalsToBrowser warningsToBrowser);</pre>
<p>And change it to look like:</p>
<pre class="pre-section">    #use Carp;
    # Or use this instead -- PLEASE see perldoc CGI::Carp for details
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);</pre>
<p>This should be only for debugging purposes, as if used in production you may end up sending
quite ugly and confusing messages to your browsers.</p>

    </div>

    <div class="sub-section">
        
<h2><a name="why_does_the_output_show_null_"></a>Why does the output show (NULL)?</h2>

<p>Swish-e displays (NULL) when attempting to display a property that does not exist in the index.</p>
<p>The most common reason for this message is that you did not use StoreDescription in your config file while indexing.</p>
<pre class="pre-section">    StoreDescription HTML* &lt;body&gt; 200000</pre>
<p>That tells swish to store the first 200,000 characters of text extracted from the body of each document parsed
by the HTML parser.  The text is stored as property "swishdescription".</p>
<p>The index must be recreated after changing the swish-e configuration.</p>
<p>Running:</p>
<pre class="pre-section">    ~/swishtest &gt; ./swish-e -T index_metanames</pre>
<p>will display the properties defined in your index file.</p>
<p>This can happen with other properties, too.
For example, this will happen when you are asking for a property to display that is not defined in swish.</p>
<pre class="pre-section">    ~/swishtest &gt; ./swish-e -w install -m 1 -p foo
    # SWISH format: 2.1-dev-25
    # Search words: install
    err: Unknown Display property name "foo"
    .

    ~/swishtest &gt; ./swish-e -w install -m 1 -x 'Property foo=&lt;foo&gt;\n'
    # SWISH format: 2.1-dev-25
    # Search words: install
    # Number of hits: 14
    # Search time: 0.000 seconds
    # Run time: 0.038 seconds
    Property foo=(NULL)
    .</pre>
<p>To check that a property exists in your index you can run:</p>
<pre class="pre-section">    ~/swishtest &gt; ./swish-e -w not dkdk -T index_metanames | grep foo
            foo : id=10 type=70  META_PROP:STRING(case:ignore) *presorted*</pre>
<p>Ok, in this case we see that "foo" is really defined as a property.  Now let's make sure <i>swish.cgi</i>
is asking for "foo" (sorry for the long lines):</p>
<pre class="pre-section">    ~/swishtest &gt; SWISH_DEBUG=command ./swish.cgi &gt; /dev/null
    Debug level set to: 3
    Enter a query [all]:
    Using 'not asdfghjklzxcv' to match all records
    Enter max results to display [1]:
    ---- Running swish with the following command and parameters ----
    ./swish-e  \
    -w  \
    'swishdefault=(not asdfghjklzxcv)'  \
    -b  \
    1  \
    -m  \
    1  \
    -f  \
    index.swish-e  \
    -s  \
    swishrank  \
    desc  \
    swishlastmodified  \
    desc  \
    -x  \
    '&lt;swishreccount&gt;\t&lt;swishtitle&gt;\t&lt;swishdescription&gt;\t&lt;swishlastmodified&gt;\t&lt;swishdocsize&gt;\t&lt;swishdocpath&gt;\t&lt;fos&gt;\t&lt;swishrank&gt;\t&lt;swishdocpath&gt;\n'  \
    -H  \
    9</pre>
<p>If you look carefully you will see that the -x parameter has "fos" instead of "foo", so there's our problem.</p>

    </div>

    <div class="sub-section">
        
<h2><a name="how_do_i_use_the_swish_api_perl_module_with_swish_cgi_"></a>How do I use the SWISH::API perl module with swish.cgi?</h2>

<p>Use the <code>use_library</code> configuration directive:</p>
<pre class="pre-section">    use_library =&gt; 1,</pre>
<p>This will only provide improved performance when running under mod_perl or other persistent
environments.</p>

    </div>

    <div class="sub-section">
        
<h2><a name="why_does_the_run_time_differ_when_using_the_swish_api_module"></a>Why does the &quot;Run time&quot; differ when using the SWISH::API module</h2>

<p>When using the SWISH::API module the run (and search) times are calculated
within the script.  When using the swish-e binary the swish-e program reports the
times.  The "Run time" may include the time required to load and compile the SWISH::API
module.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="mod_perl"></a>MOD_PERL</h1>

<p>This script can be run under mod_perl (see <a href="http://perl.apache.org">http://perl.apache.org</a>).
This will improve the response time of the script compared to running under CGI by loading the
swish.cgi script into the Apache web server.</p>
<p>You must have a mod_perl enabled Apache server to run this script under mod_perl.</p>
<p>Configuration is simple.  In your httpd.conf or your startup.pl file you need to
load the script.  For example, in httpd.conf you can use a perl section:</p>
<pre class="pre-section">    &lt;perl&gt;
        use lib '/usr/local/apache/cgi-bin';  # location of the swish.cgi file
        use lib '/home/yourname/swish-e/example/modules';  # modules required by swish.cgi
        require "swish.cgi";
    &lt;/perl&gt;</pre>
<p>Again, note that the paths used will depend on where you installed the script and the modules.
When running under mod_perl the swish.cgi script becomes a perl module, and therefore the script
does not need to be installed in the cgi-bin directory.  (But, you can actually use the same script as
both a CGI script and a mod_perl module at the same time, read from the same location.)</p>
<p>The above loads the script into mod_perl.  Then to configure the script to run add this to your httpd.conf
configuration file:</p>
<pre class="pre-section">    &lt;location /search&gt;
        PerlSetVar Swish_Conf_File /home/yourname/swish-e/myconfig.pl
        allow from all
        SetHandler perl-script
        PerlHandler SwishSearch
    &lt;/location&gt;</pre>
<p>Note that you use the "Swish_Conf_File" setting in httpd.conf to tell the script
which config file to use.  This means you can use the same script (and loaded modules)
for different search sites (running on the same Apache server).  You can just specify
differnt config files for each Location and they can search different indexes and
have a completely different look for each site, but all share the same code.</p>
<p><b>Note</b> that the config files are cached in the swish.cgi script.  Changes to the config file
will require restarting the Apache server before they will be reloaded into the swish.cgi
script.  This avoids calling stat() for every request.</p>
<p>Unlike CGI, mod_perl does not change the current directory to the location of the script, so
your settings for the swish binary and the path to your index files must be absolute
paths (or relative to the server root).</p>
<p>Using the SWISH::API module with mod_perl will provide the most performance improvements.
Use of the SWISH::API module can be enabled by the configuration setting <code>use_library</code>:</p>
<pre class="pre-section">    use_library     =&gt; 1,</pre>
<p>Without highlighting code enabled, using the SWISH::API module resulted in about 20 requests
per second, where running the swish-e binary slowed the script down to about 8 requests per second.</p>
<p>Note that the highlighting code is slow.  For the best search performance turn off highlighting.
In your config file you can add:</p>
<pre class="pre-section">    highlighting    =&gt; 0,  # disable highlighting</pre>
<p>and the script will show the first 500 chars of the description (or whatever you set for "max_chars").
Without highlight one test was processing about 20 request per second.
With The "PhraseHighlight" module that dropped to a little better than two requests per second,
"DefaultHighlight" was about 2.3 request per second, and "SimpleHighlight" was about 6 request per second.</p>
<p>Experiement with different highlighting options when testing performance.</p>
<p>Please post to the swish-e discussion list if you have any questions about running this
script under mod_perl.</p>
<p>Here's some general request/second on an Athlon XP 1800+ with 1/2GB RAM, Linux 2.4.20.</p>
<pre class="pre-section">                              Highlighting Mode

                      None     Phrase    Default     Simple
   Using SWISH::API   45        1.5        2          12
   ----------------------------------------------------------------------------
   Using swish-e      12        1.3       1.8         7.5
     binary</pre>
<p>As you can see the highlighting code is a limiting factor.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="speedycgi"></a>SpeedyCGI</h1>

<p>SpeedyCGI (also called PersistentPerl) is another way to run Perl scripts persistently.
SpeedyCGI is good if you do not have mod_perl available or do not have root access.
SpeedyCGI works on Unix systems by loading the script into a "back end" process and keeping
it in memory between requests.  New requests are passed to the back end processes which avoids
the startup time required by a Perl CGI script.</p>
<p>Install SpeedyCGI from <a href="http://daemoninc.com/">http://daemoninc.com/</a> (your OS may provide a packaged version of
SpeedyCGI) and then change the first line of swish.cgi.  For example, if the speedy binary is
installed in /usr/bin/speedy, use the line:</p>
<pre class="pre-section">    #! /usr/bin/speedy -w -- -t60</pre>
<p>The -w option is passed to Perl, and all options following the double-dash are SpeedyCGI options.</p>
<p>Note that when using SpeedyCGI configuration data is cached in memory.  If you change the swish.cgi
configuration file (.swishcgi.conf) then touch the main swish.cgi script to force reloading of
configuration data.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="spidering"></a>Spidering</h1>

<p>There are two ways to spider with swish-e.  One uses the "http" input method that uses code that's
part of swish.  The other way is to use the new "prog" method along with a perl helper program called
<code>spider.pl</code>.</p>
<p>Here's an example of a configuration file for spidering with the "http" input method.
You can see that the configuration is not much different than the file system input method.
(But, don't use the http input method -- use the -S prog method shown below.)</p>
<pre class="pre-section">    # Define what to index
    IndexDir http://www.myserver.name/index.html
    IndexOnly .html .htm

    IndexContents HTML* .html .htm
    DefaultContents HTML*
    StoreDescription HTML* &lt;body&gt; 200000
    MetaNames swishdocpath swishtitle

    # Define http method specific settings -- see swish-e documentation
    SpiderDirectory ../swish-e/src/
    Delay 0</pre>
<p>You index with the command:</p>
<pre class="pre-section">    swish-e -S http -c spider.conf</pre>
<p>Note that this does take longer.  For example, spidering the Apache documentation on
a local web server with this method took over a minute, where indexing with the
file system took less than two seconds.  Using the "prog" method can speed this up.</p>
<p>Here's an example configuration file for using the "prog" input method:</p>
<pre class="pre-section">    # Define the location of the spider helper program
    IndexDir ../swish-e/prog-bin/spider.pl

    # Tell the spider what to index.
    SwishProgParameters default http://www.myserver.name/index.html

    IndexContents HTML* .html .htm
    DefaultContents HTML*
    StoreDescription HTML* &lt;body&gt; 200000
    MetaNames swishdocpath swishtitle</pre>
<p>Then to index you use the command:</p>
<pre class="pre-section">    swish-e -c prog.conf -S prog -v 0</pre>
<p>Spidering with this method took nine seconds.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="stemmed_indexes"></a>Stemmed Indexes</h1>

<p>Many people enable a feature of swish called word stemming to provide
"fuzzy" search options to their users.  The stemming code does not
actually find the "stem" of word, rather removes and/or replaces
common endings on words.  Stemming is far from perfect, and many words
do not stem as you might expect.  Plus, currently only English is
supported.  But, it can be a helpful tool for searching your site.
You may wish to create both a stemmed and non-stemmed index, and
provide a checkbox for selecting the index file.</p>
<p>To enable a stemmed index you simply add to your configuration file:</p>
<pre class="pre-section">    UseStemming yes</pre>
<p>If you want to use a stemmed index with this program and continue to highlight search terms you will need
to install a perl module that will stem words.  This section explains how to do this.</p>
<p>The perl module is included with the swish-e distribution.  It can be found in the examples directory (where
you found this file) and called something like:</p>
<pre class="pre-section">    SWISH-Stemmer-0.05.tar.gz</pre>
<p>The module should also be available on CPAN (<a href="http://search.cpan.org/">http://search.cpan.org/</a>).</p>
<p>Here's an example session for installing the module.  (There will be quite a bit of output
when running make.)</p>
<pre class="pre-section">    % gzip -dc SWISH-Stemmer-0.05.tar.gz |tar xof -
    % cd SWISH-Stemmer-0.05
    % perl Makefile.PL
    or
    % perl Makefile.PL PREFIX=$HOME/perl_lib
    % make
    % make test

    (perhaps su root at this point if you did not use a PREFIX)
    % make install
    % cd ..</pre>
<p>Use the <b>PREFIX</b> if you do not have root access or you want to install the modules
in a local library.  If you do use a PREFIX setting, add a <code>use lib</code> statement to the top of this
swish.cgi program.</p>
<p>For example:</p>
<pre class="pre-section">    use lib qw(
        /home/bmoseley/perl_lib/lib/site_perl/5.6.0
        /home/bmoseley/perl_lib/lib/site_perl/5.6.0/i386-linux/
    );</pre>
<p>Once the stemmer module is installed, and you are using a stemmed index, the <code>swish.cgi</code> script will automatically
detect this and use the stemmer module.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="disclaimer"></a>DISCLAIMER</h1>

<p>Please use this CGI script at your own risk.</p>
<p>This script has been tested and used without problem, but you should still be aware that
any code running on your server represents a risk.  If you have any concerns please carefully
review the code.</p>
<p>See <a href="http://www.w3.org/Security/Faq/www-security-faq.html">http://www.w3.org/Security/Faq/www-security-faq.html</a></p>
<p>Security on Windows questionable.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="support"></a>SUPPORT</h1>

<p>The SWISH-E discussion list is the place to ask for any help regarding SWISH-E or this example
script. See <a href="http://swish-e.org">http://swish-e.org</a>.</p>
<p>Before posting please review:</p>
<pre class="pre-section">    http://swish-e.org/2.2/docs/INSTALL.html#When_posting_please_provide_the_</pre>
<p>Please do not contact the author or any of the swish-e developers directly.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="license"></a>LICENSE</h1>

<p>swish.cgi $Revision: 1830 $ Copyright (C) 2001 Bill Moseley search@hank.org
Example CGI program for searching with SWISH-E</p>
<p>This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version
2 of the License, or (at your option) any later version.</p>
<p>This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="author"></a>AUTHOR</h1>

<p>Bill Moseley</p>

    </div>















        </div><!-- /#main-copy  -->

    </div><!-- /#content-area -->


    <div id="side-bar">
        <!-- noindex -->
<ul class="menu"><li class="menuparent">

    <a class="menu" 
    href="./index.html"
    >Doc Overview</a>

<!-- noindex -->
<ul class="submenu"><li class="">

    <a class="submenu" 
    href="./readme.html"
     title="First time users">README</a>

</li><li class="">

    <a class="submenu" 
    href="./install.html"
     title="Installation and usage overview">Install</a>

</li><li class="">

    <a class="submenu" 
    href="./changes.html"
     title="Important changes from previous versions">Changes</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-config.html"
     title="Directives that go in your Swish-e configuration file">Configuration</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-run.html"
     title="Command line options for Swish-e binary">Running</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-search.html"
     title="Swish-e's search language">Searching</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-faq.html"
    >FAQ</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-bugs.html"
    >Known issues</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-3.0.html"
    >The Future</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-library.html"
     title="Swish-e C API">C API</a>

</li><li class="">

    <a class="submenu" 
    href="./api.html"
     title="Perl interface to the Swish-e library">Perl API</a>

</li><li class="">

    <a class="thisfile" 
    href="./swish.cgi.html"
     title="Example CGI/mod_perl script">Swish.cgi &#187;</a>

</li><li class="">

    <a class="submenu" 
    href="./search.cgi.html"
     title="Example Perl script using SWISH::API">Search.cgi</a>

</li><li class="">

    <a class="submenu" 
    href="./spider.html"
     title="The Swish-e HTTP spider">Spider.pl</a>

</li><li class="">

    <a class="submenu" 
    href="./filter.html"
     title="How to index non-text documents">Filters</a>

</li></ul>
<!-- index -->


</li></ul>
<!-- index -->



    </div><!-- /#side-bar -->


</div><!-- /#body-area -->



<div id="footer">
    <!-- noindex -->
<span class="doNotPrint">
    Swish-e is distributed with <strong>no warranty</strong> under the terms of the <br />
    <a href='http://swish-e.org/license.html'>Swish-e License</a>.<br />
    Questions may be posted to the 
    <a href="http://swish-e.org/discuss.html" title="email list and list archive">Swish-e Discussion list</a>.
</span>



<p>
    <strong>URI &raquo;</strong> http://swish-e.org/ 
    &bull;

    <strong>Updated &raquo;</strong>Sun, 05 Apr 2009 01:58:33 UTC</p>
<!-- index -->

</div><!-- /#footer -->


</body>
</html>