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 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>SWISH-Enhanced: swish.cgi -- Example Perl script for searching with the SWISH-E search engine. </title>
<link href="./style.css" rel=stylesheet type="text/css" title="refstyle">
</head>
<body>
<h1 class="banner">
<a href="http://swish-e.org"><img border=0 src="images/swish.gif" alt="Swish-E Logo"></a><br>
<img src="images/swishbanner1.gif"><br>
<img src="images/dotrule1.gif"><br>
swish.cgi -- Example Perl script for searching with the SWISH-E search engine.
</h1>
<hr>
<p>
<div class="navbar">
<a href="./API.html">Prev</a> |
<a href="./index.html">Contents</a> |
<a href="./search.html">Next</a>
</div>
<p>
<div class="toc">
<A NAME="toc"></A>
<P><B>Table of Contents:</B></P>
<UL>
<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
<LI><A HREF="#REQUIREMENTS">REQUIREMENTS</A>
<LI><A HREF="#INSTALLATION">INSTALLATION</A>
<LI><A HREF="#CONFIGURATION">CONFIGURATION</A>
<LI><A HREF="#DEBUGGING">DEBUGGING</A>
<LI><A HREF="#Frequently_Asked_Questions">Frequently Asked Questions</A>
<UL>
<LI><A HREF="#How_do_I_change_the_way_the_output_looks_">How do I change the way the output looks?</A>
<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><A HREF="#Why_are_there_three_different_highlighting_modules_">Why are there three different highlighting modules?</A>
<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><A HREF="#Why_does_the_output_show_NULL_">Why does the output show (NULL)?</A>
<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><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>
</UL>
<LI><A HREF="#MOD_PERL">MOD_PERL</A>
<LI><A HREF="#SpeedyCGI">SpeedyCGI</A>
<LI><A HREF="#Spidering">Spidering</A>
<LI><A HREF="#Stemmed_Indexes">Stemmed Indexes</A>
<LI><A HREF="#DISCLAIMER">DISCLAIMER</A>
<LI><A HREF="#SUPPORT">SUPPORT</A>
<LI><A HREF="#LICENSE">LICENSE</A>
<LI><A HREF="#AUTHOR">AUTHOR</A>
</UL>
</div>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<P>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></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>
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>
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>
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>
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>
The script is modular in design. Both the highlighting code and output
generation is handled by modules, which are included in the
<EM>example/modules</EM> distribution directory and installed in the $libexecdir/perl directory.
This allows for easy customization of the output without changing the main
CGI script.
<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 (http://search.cpan.org).
<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>
Please read the rest of the documentation. There's a <CODE>DEBUGGING</CODE>
section, and a <CODE>FAQ</CODE> section.
<P>
This script should work on Windows, but security may be an issue.
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="REQUIREMENTS">REQUIREMENTS</A></H1>
<P>
A reasonably current version of Perl. 5.00503 or above is recommended
(anything older will not be supported).
<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>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="INSTALLATION">INSTALLATION</A></H1>
<P>
Here's an example installation session under Linux. It should be similar
for other operating systems.
<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 <EM>.htaccess</EM>).
<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>
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>
For <EM>security</EM> 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 <EM>.htaccess</EM>). An example of using <EM>.htaccess</EM> on Apache is given below.
<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>
Example Installation:
<OL>
<P><LI><STRONG><A NAME="item_Symlink_or_copy_the_swish_cgi_">Symlink or copy the swish.cgi.</A></STRONG>
<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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~$ mkdir swishdir
~$ cd swishdir
~/swishdir$ ln -s /usr/local/lib/swish-e/swish.cgi</pre>
</td>
</tr>
</table>
<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><STRONG><A NAME="item_Create_an_index">Create an index</A></STRONG>
<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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishdir$ cat swish.conf
IndexDir /usr/local/apache/htdocs
IndexOnly .html .htm
DefaultContents HTML*
StoreDescription HTML* <body> 200000
MetaNames swishdocpath swishtitle
ReplaceRules remove /usr/local/apache/</pre>
</td>
</tr>
</table>
<P>
If you do not have the Apache docs installed then pick another directory to
index such as /usr/share/doc.
<P>
Create the index.
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/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>
</td>
</tr>
</table>
<P>
Now, verify that the index can be searched:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/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>
</td>
</tr>
</table>
<P>
Let's see what files we have in our directory now:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishdir$ ls -1
index.swish-e
index.swish-e.prop
swish.cgi
swish.conf</pre>
</td>
</tr>
</table>
<P><LI><STRONG><A NAME="item_Test_the_CGI_script">Test the CGI script</A></STRONG>
<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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishdir$ ./swish.cgi | head
Content-Type: text/html; charset=ISO-8859-1</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
Search our site
</title>
</head>
<body></pre>
</td>
</tr>
</table>
<P>
The above shows that the script can be run directly, and generates a
correct HTTP header and HTML.
<P>
If you run the above and see something like this:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishdir >./swish.cgi
bash: ./swish.cgi: No such file or directory</pre>
</td>
</tr>
</table>
<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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishdir$ which perl
/usr/local/bin/perl</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishdir$ /usr/local/bin/perl -v
This is perl, v5.6.0 built for i586-linux
...</pre>
</td>
</tr>
</table>
<P>
Good! We are using a reasonably current version of perl.
<P>
Now that we know perl is at <EM>/usr/local/bin/perl</EM> we can adjust the "shebang" line in the perl script (e.g. the
first line of the script):
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishdir$ pico swish.cgi
(edit the #! line)
~/swishdir$ head -1 swish.cgi
#!/usr/local/bin/perl -w</pre>
</td>
</tr>
</table>
<P><LI><STRONG><A NAME="item_Test_with_the_web_server">Test with the web server</A></STRONG>
<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>
This example shows creating a <EM>symlink</EM> 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>
This operation requires root access:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishdir$ su -c "ln -s $HOME/swishdir /usr/local/apache/htdocs/swishdir"
Password: *********</pre>
</td>
</tr>
</table>
<P>
If your account is on an ISP and your web directory is <EM>~/public_html</EM> the you might just move the entire directory:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> mv ~/swishdir ~/public_html</pre>
</td>
</tr>
</table>
<P>
Now, let's make a real HTTP request:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishdir$ GET <A HREF="http://localhost/swishdir/swish.cgi">http://localhost/swishdir/swish.cgi</A> | head -3
#!/usr/local/bin/perl -w
package SwishSearch;
use strict;</pre>
</td>
</tr>
</table>
<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>
<EM>.htaccess</EM> comes to the rescue:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishdir$ cat .htaccess</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> # Deny everything by default
Deny From All</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> # But allow just CGI script
<files swish.cgi>
Options ExecCGI
Allow From All
SetHandler cgi-script
</files></pre>
</td>
</tr>
</table>
<P>
That "Deny From All" prevents access to all files (such as config
and index files), and only access is allowed to the
<EM>swish.cgi</EM> script.
<P>
Let's try the request one more time:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishdir >GET <A HREF="http://localhost/swishdir/swish.cgi">http://localhost/swishdir/swish.cgi</A> | head
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
Search our site
</title>
</head>
<body>
<h2>
<a href="<A HREF="http://swish-e.org">">http://swish-e.org"></A></pre>
</td>
</tr>
</table>
<P>
That looks better! Now use your web browser to test.
<P>
Now, you may note that the links are not valid on the search results page.
The swish config file contained the line:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ReplaceRules remove /usr/local/apache/</pre>
</td>
</tr>
</table>
<P>
To make those links works (and assuming your web server will follow
symbolic links):
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest$ ln -s /usr/local/apache/htdocs</pre>
</td>
</tr>
</table>
<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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> wget -O - <A HREF="http://localhost/swishdir/swish.cgi">http://localhost/swishdir/swish.cgi</A> | head</pre>
</td>
</tr>
</table>
<P>
and if nothing else, you can always telnet to the web server and make a
basic request.
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /swishtest/swish.cgi http/1.0</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> 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</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
Search our site
</title>
</head>
<body></pre>
</td>
</tr>
</table>
<P>
This may seem like a lot of work compared to using a browser, but browsers
are a poor tool for basic CGI debugging.
</OL>
<P>
If you have problems check the <CODE>DEBUGGING</CODE> section below.
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="CONFIGURATION">CONFIGURATION</A></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>
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>
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>
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>
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>
By the way, Perl has a number of quote operators. For example, to quote a
string you might write:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> title => 'Search My Site',</pre>
</td>
</tr>
</table>
<P>
Some options take more than one parameter, where each parameter must be
quoted. For example:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> metanames => [ 'swishdefault', 'swishtitle', 'swishdocpath' ],</pre>
</td>
</tr>
</table>
<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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> metanames => [ qw/ swishdefault swishtitle swishdocpath / ],</pre>
</td>
</tr>
</table>
<P>
or to use the parenthesis as the quote character (you can pick any):
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> metanames => [ qw( swishdefault swishtitle swishdocpath ) ],</pre>
</td>
</tr>
</table>
<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>
Using a configuration file is described below, but contains the same hash
structure.
<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>
A very basic configuration setup might look like:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> return {
title => 'Search the Swish-e list', # Title of your choice.
swish_binary => 'swish-e', # Location of swish-e binary
swish_index => 'index.swish-e', # Location of your index file
};</pre>
</td>
</tr>
</table>
<P>
Or if searching more than one index:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> return {
title => 'Search the Swish-e list',
swish_binary => 'swish-e',
swish_index => ['index.swish-e', 'index2'],
};</pre>
</td>
</tr>
</table>
<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>
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>
The script can also use the SWISH::API perl module (included with the
swish-e distribution in the <EM>perl</EM> 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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> return {
title => 'Search the Swish-e list',
swish_index => ['index.swish-e', 'index2'],
use_library => 1, # enable use of the SWISH::API module
};</pre>
</td>
</tr>
</table>
<P>
The module must be available via the <CODE>@INC</CODE> array, like all Perl
modules.
<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>
<STRONG>Using A Configuration File</STRONG>
<P>
As mentioned above, configuration settings can be either set in the
<EM>swish.cgi</EM> script, or set in a separate configuration file. Settings in a
configuration file will override the settings in the script.
<P>
By default, the <EM>swish.cgi</EM> script will attempt to read settings from the file <EM>.swishcgi.conf</EM>. For example, you might only wish to change the title used in the script.
Simply create a file called <EM>.swishcgi.conf</EM> in the same directory as the CGI script:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> > cat .swishcgi.conf
# Example swish.cgi configuration script.
return {
title => 'Search Our Mailing List Archive',
};</pre>
</td>
</tr>
</table>
<P>
The settings you use will depend on the index you create with swish:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> return {
title => 'Search the Apache documentation',
swish_binary => 'swish-e',
swish_index => 'index.swish-e',
metanames => [qw/swishdefault swishdocpath swishtitle/],
display_props => [qw/swishtitle swishlastmodified swishdocsize swishdocpath/],
title_property => 'swishdocpath',
prepend_path => '<A HREF="http://myhost/apachedocs">http://myhost/apachedocs</A>',</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> name_labels => {
swishdefault => 'Search All',
swishtitle => 'Title',
swishrank => 'Rank',
swishlastmodified => 'Last Modified Date',
swishdocpath => 'Document Path',
swishdocsize => 'Document Size',
},</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> };</pre>
</td>
</tr>
</table>
<P>
The above configuration defines metanames to use on the form. Searches can
be limited to these metanames.
<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>
The parameter "name_labels" is a hash (reference) that is used to
give friendly names to the metanames.
<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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> return {
title => 'Search the Apache Documentation',
date_ranges => 0,
swish_index => [ qw/ index.apache index.apache2 / ],
select_indexes => {
method => 'checkbox_group',
labels => [ '1.3.23 docs', '2.0 docs' ], # Must match up one-to-one to swish_index
description => 'Select: ',
},</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> };</pre>
</td>
</tr>
</table>
<P>
Now you can select either or both sets of documentation while searching.
<P>
All the possible settings are included in the default configuration located
near the top of the <EM>swish.cgi</EM>
script. Open the <EM>swish.cgi</EM> script with an editor to look at the various settings. Contact the Swish-e
Discussion list for help in configuring the script.
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="DEBUGGING">DEBUGGING</A></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>
The key to debugging CGI scripts is to run them from the command line, not
with a browser.
<P>
First, make sure the program compiles correctly:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> $ perl -c swish.cgi
swish.cgi syntax OK</pre>
</td>
</tr>
</table>
<P>
Next, simply try running the program:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> $ ./swish.cgi | head
Content-Type: text/html; charset=ISO-8859-1</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
Search our site
</title>
</head>
<body></pre>
</td>
</tr>
</table>
<P>
Under Windows you will need to run the script as:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> C:\wwwroot\swishtest> perl swish.cgi</pre>
</td>
</tr>
</table>
<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>
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>
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>
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>
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>
Note: You can also use the "debug_options" configuration setting,
but the recommended method is to set the environment variable.
<P>
You can list the available debugging options like this:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> $ SWISH_DEBUG=help ./swish.cgi >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>
</td>
</tr>
</table>
<P>
Debugging options may be combined:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> $ SWISH_DEBUG=command,headers,summary ./swish.cgi >outfile</pre>
</td>
</tr>
</table>
<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>
Here are some examples:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest$ SWISH_DEBUG=basic ./swish.cgi >outfile
Debug level set to: 1
Enter a query [all]:
Using 'not asdfghjklzxcv' to match all records
Enter max results to display [1]:</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ------ Can't use DateRanges feature ------------</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> 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, <STDIN> line 2.
BEGIN failed--compilation aborted at modules/DateRanges.pm line 107, <STDIN> line 2.
Compilation failed in require at ./swish.cgi line 971, <STDIN> line 2.</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> --------------
Can't exec "./swish-e": No such file or directory at ./swish.cgi line 1245, <STDIN> line 2.
Child process Failed to exec './swish-e' Error: No such file or directory at ./swish.cgi line 1246, <STDIN> line 2.
Failed to find any results</pre>
</td>
</tr>
</table>
<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>
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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest$ cat .swishcgi.conf
return {
title => 'Search the Apache Documentation',
swish_binary => '/usr/local/bin/swish-e',
date_ranges => 0,
};</pre>
</td>
</tr>
</table>
<P>
Now, let's try again:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest$ SWISH_DEBUG=basic ./swish.cgi >outfile
Debug level set to: 1</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ---------- Read config parameters from '.swishcgi.conf' ------
$VAR1 = {
'date_ranges' => 0,
'title' => '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>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> 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>
</td>
</tr>
</table>
<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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest$ cat .swishcgi.conf
use lib '/home/bill/local/lib/perl';</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> return {
title => 'Search the Apache Documentation',
date_ranges => 0,
};</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest$ SWISH_DEBUG=basic ./swish.cgi >outfile
Debug level set to: 1</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ---------- Read config parameters from '.swishcgi.conf' ------
$VAR1 = {
'date_ranges' => 0,
'title' => '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>
</td>
</tr>
</table>
<P>
That is much better!
<P>
The "use lib" statement tells Perl where to look for modules by
adding the path supplied to an array called @INC.
<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 <EM>SWISH/TemplateDefault.pm</EM>. If the "use lib" statement is set as:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> use lib '/home/bill/local/lib/perl';</pre>
</td>
</tr>
</table>
<P>
then Perl will look (among other places) for the file
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> /home/bill/local/lib/perl/SWISH/TemplateDefault.pm</pre>
</td>
</tr>
</table>
<P>
when attempting to load the SWISH::TemplateDefault module. Relative paths
may also be used.
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> use lib 'modules';</pre>
</td>
</tr>
</table>
<P>
will cause Perl to look for the file:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ./modules/SWISH/TemplateDefault.pm</pre>
</td>
</tr>
</table>
<P>
relative to where the swish.cgi script is running. (This is not true when
running under mod_perl).
<P>
Here's another common problem. Everything checks out, but when you run the
script you see the message:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> Swish returned unknown output</pre>
</td>
</tr>
</table>
<P>
Ok, let's find out what output it is returning:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest$ SWISH_DEBUG=headers,output ./swish.cgi >outfile
Debug level set to: 13</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ---------- Read config parameters from '.swishcgi.conf' ------
$VAR1 = {
'swish_binary' => '/usr/local/bin/swish-e',
'date_ranges' => 0,
'title' => '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: <A HREF="http://sunsite.berkeley.edu/SWISH-E/">http://sunsite.berkeley.edu/SWISH-E/</A></pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> *** 9872 Failed to run swish: 'Swish returned unknown output' ***
Failed to find any results</pre>
</td>
</tr>
</table>
<P>
Oh, looks like /usr/local/bin/swish-e is version 2.0 of swish. We need
2.1-dev and above!
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="Frequently_Asked_Questions">Frequently Asked Questions</A></H1>
<P>
Here's some common questions and answers.
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H2><A NAME="How_do_I_change_the_way_the_output_looks_">How do I change the way the output looks?</A></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>
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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> $ cp TemplateDefault.pm MyTemplateDefault.pm</pre>
</td>
</tr>
</table>
<P>
Then at the top of the module adjust the "package" line to:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> package SWISH::MyTemplateDefault;</pre>
</td>
</tr>
</table>
<P>
To use this modules you need to adjust the configuration settings (either
at the top of <EM>swish.cgi</EM> or in a configuration file:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> template => {
package => 'SWISH::MyTemplateDefault',
},</pre>
</td>
</tr>
</table>
<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 <CODE>@INC</CODE>
array (i.e. modify the "use lib" statement in swish.cgi if
needed).
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H2><A NAME="How_do_I_use_a_templating_system_with_swish_cgi_">How do I use a templating system with swish.cgi?</A></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>
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>
Two basic templates are provided as examples for generating output using
these templating systems. The example templates are located in the <EM>example</EM> directory. The module <EM>SWISH::TemplateHTMLTemplate</EM> uses the file <EM>swish.tmpl</EM> to generate its output, while the module <EM>SWISH::TemplateToolkit</EM> uses the <EM>swish.tt</EM> file. (Note: swish.tt was renamed from search.tt Jun 03, 2004.)
<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 <EM>swish.cgi</EM> program.
<P>
Use of these modules is an advanced usage of <EM>swish.cgi</EM> and are provided as examples only.
<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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest >cat .swishcgi.conf
return {
title => 'Search the Apache Documentation',
template => {
package => 'SWISH::TemplateDumper',
},
};</pre>
</td>
</tr>
</table>
<P>
And run a query. For example:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> <A HREF="http://localhost/swishtest/swish.cgi?query=install">http://localhost/swishtest/swish.cgi?query=install</A></pre>
</td>
</tr>
</table>
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H2><A NAME="Why_are_there_three_different_highlighting_modules_">Why are there three different highlighting modules?</A></H2>
<P>
Three are three highlighting modules included with the swish-e
distribution. Each is a trade-off of speed vs. accuracy:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> 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>
</td>
</tr>
</table>
<P>
Eh, the default is actually "PhraseHighlight". Oh well.
<P>
All of the highlighting modules slow down the script. Optimizations to
these modules are welcome!
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H2><A NAME="My_ISP_doesn_t_provide_access_to_the_web_server_logs">My ISP doesn't provide access to the web server logs</A></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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> use Carp;
# Or use this instead -- PLEASE see perldoc CGI::Carp for details
# use CGI::Carp qw(fatalsToBrowser warningsToBrowser);</pre>
</td>
</tr>
</table>
<P>
And change it to look like:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> #use Carp;
# Or use this instead -- PLEASE see perldoc CGI::Carp for details
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);</pre>
</td>
</tr>
</table>
<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>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H2><A NAME="Why_does_the_output_show_NULL_">Why does the output show (NULL)?</A></H2>
<P>
Swish-e displays (NULL) when attempting to display a property that does not
exist in the index.
<P>
The most common reason for this message is that you did not use
StoreDescription in your config file while indexing.
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> StoreDescription HTML* <body> 200000</pre>
</td>
</tr>
</table>
<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>
The index must be recreated after changing the swish-e configuration.
<P>
Running:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest > ./swish-e -T index_metanames</pre>
</td>
</tr>
</table>
<P>
will display the properties defined in your index file.
<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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest > ./swish-e -w install -m 1 -p foo
# SWISH format: 2.1-dev-25
# Search words: install
err: Unknown Display property name "foo"
.</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest > ./swish-e -w install -m 1 -x 'Property foo=<foo>\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>
</td>
</tr>
</table>
<P>
To check that a property exists in your index you can run:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest > ./swish-e -w not dkdk -T index_metanames | grep foo
foo : id=10 type=70 META_PROP:STRING(case:ignore) *presorted*</pre>
</td>
</tr>
</table>
<P>
Ok, in this case we see that "foo" is really defined as a
property. Now let's make sure <EM>swish.cgi</EM>
is asking for "foo" (sorry for the long lines):
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> ~/swishtest > SWISH_DEBUG=command ./swish.cgi > /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 \
'<swishreccount>\t<swishtitle>\t<swishdescription>\t<swishlastmodified>\t<swishdocsize>\t<swishdocpath>\t<fos>\t<swishrank>\t<swishdocpath>\n' \
-H \
9</pre>
</td>
</tr>
</table>
<P>
If you look carefully you will see that the -x parameter has
"fos" instead of "foo", so there's our problem.
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H2><A NAME="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></H2>
<P>
Use the <CODE>use_library</CODE> configuration directive:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> use_library => 1,</pre>
</td>
</tr>
</table>
<P>
This will only provide improved performance when running under mod_perl or
other persistent environments.
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H2><A NAME="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></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>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="MOD_PERL">MOD_PERL</A></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>
You must have a mod_perl enabled Apache server to run this script under
mod_perl.
<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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> <perl>
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";
</perl></pre>
</td>
</tr>
</table>
<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>
The above loads the script into mod_perl. Then to configure the script to
run add this to your httpd.conf configuration file:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> <location /search>
PerlSetVar Swish_Conf_File /home/yourname/swish-e/myconfig.pl
allow from all
SetHandler perl-script
PerlHandler SwishSearch
</location></pre>
</td>
</tr>
</table>
<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>
<STRONG>Note</STRONG> 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 <CODE>stat()</CODE>
for every request.
<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>
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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> use_library => 1,</pre>
</td>
</tr>
</table>
<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>
Note that the highlighting code is slow. For the best search performance
turn off highlighting. In your config file you can add:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> highlighting => 0, # disable highlighting</pre>
</td>
</tr>
</table>
<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>
Experiement with different highlighting options when testing performance.
<P>
Please post to the swish-e discussion list if you have any questions about
running this script under mod_perl.
<P>
Here's some general request/second on an Athlon XP 1800+ with 1/2GB RAM,
Linux 2.4.20.
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> Highlighting Mode</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> None Phrase Default Simple
Using SWISH::API 45 1.5 2 12
----------------------------------------------------------------------------
Using swish-e 12 1.3 1.8 7.5
binary</pre>
</td>
</tr>
</table>
<P>
As you can see the highlighting code is a limiting factor.
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="SpeedyCGI">SpeedyCGI</A></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>
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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> #! /usr/bin/speedy -w -- -t60</pre>
</td>
</tr>
</table>
<P>
The -w option is passed to Perl, and all options following the double-dash
are SpeedyCGI options.
<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>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="Spidering">Spidering</A></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>
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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> # Define what to index
IndexDir <A HREF="http://www.myserver.name/index.html">http://www.myserver.name/index.html</A>
IndexOnly .html .htm</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> IndexContents HTML* .html .htm
DefaultContents HTML*
StoreDescription HTML* <body> 200000
MetaNames swishdocpath swishtitle</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> # Define http method specific settings -- see swish-e documentation
SpiderDirectory ../swish-e/src/
Delay 0</pre>
</td>
</tr>
</table>
<P>
You index with the command:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> swish-e -S http -c spider.conf</pre>
</td>
</tr>
</table>
<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>
Here's an example configuration file for using the "prog" input
method:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> # Define the location of the spider helper program
IndexDir ../swish-e/prog-bin/spider.pl</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> # Tell the spider what to index.
SwishProgParameters default <A HREF="http://www.myserver.name/index.html">http://www.myserver.name/index.html</A></pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> IndexContents HTML* .html .htm
DefaultContents HTML*
StoreDescription HTML* <body> 200000
MetaNames swishdocpath swishtitle</pre>
</td>
</tr>
</table>
<P>
Then to index you use the command:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> swish-e -c prog.conf -S prog -v 0</pre>
</td>
</tr>
</table>
<P>
Spidering with this method took nine seconds.
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="Stemmed_Indexes">Stemmed Indexes</A></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>
To enable a stemmed index you simply add to your configuration file:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> UseStemming yes</pre>
</td>
</tr>
</table>
<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>
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>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> SWISH-Stemmer-0.05.tar.gz</pre>
</td>
</tr>
</table>
<P>
The module should also be available on CPAN (http://search.cpan.org/).
<P>
Here's an example session for installing the module. (There will be quite a
bit of output when running make.)
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> % 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</pre>
</td>
</tr>
</table>
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> (perhaps su root at this point if you did not use a PREFIX)
% make install
% cd ..</pre>
</td>
</tr>
</table>
<P>
Use the <STRONG>PREFIX</STRONG> 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>
For example:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> 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>
</td>
</tr>
</table>
<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>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="DISCLAIMER">DISCLAIMER</A></H1>
<P>
Please use this CGI script at your own risk.
<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>
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>
Security on Windows questionable.
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="SUPPORT">SUPPORT</A></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>
Before posting please review:
<P>
<table>
<tr>
<td bgcolor="#eeeeee" width="1">
</td>
<td>
<pre> <A HREF="http://swish-e.org/2.2/docs/INSTALL.html#When_posting_please_provide_the_">http://swish-e.org/2.2/docs/INSTALL.html#When_posting_please_provide_the_</A></pre>
</td>
</tr>
</table>
<P>
Please do not contact the author or any of the swish-e developers directly.
<P>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="LICENSE">LICENSE</A></H1>
<P>
swish.cgi $Revision: 1.20 $ Copyright (C) 2001 Bill Moseley <A
HREF="mailto:search@hank.org">search@hank.org</A> Example CGI program for
searching with SWISH-E
<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>
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>
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<H1><A NAME="AUTHOR">AUTHOR</A></H1>
<P>
Bill Moseley
[ <B><FONT SIZE=-1><A HREF="#toc">TOC</A></FONT></B> ]
<HR>
<p>
<div class="navbar">
<a href="./API.html">Prev</a> |
<a href="./index.html">Contents</a> |
<a href="./search.html">Next</a>
</div>
<p>
<P ALIGN="CENTER">
<IMG ALT="" WIDTH="470" HEIGHT="10" SRC="images/dotrule1.gif"></P>
<P ALIGN="CENTER">
<div class="footer">
<BR>SWISH-E is distributed with <B>no warranty</B> under the terms of the
<A HREF="http://www.fsf.org/copyleft/gpl.html">GNU Public License</A>,<BR>
Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA<BR>
Public questions may be posted to
the <A HREF="http://swish-e.org/Discussion/">SWISH-E Discussion</A>.
</div>
</body>
</html>
|