| 1 | ############################################################################## | ||
| 2 | # The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. # | ||
| 3 | # # | ||
| 4 | # This program is free software; you can redistribute it and/or # | ||
| 5 | # modify it under the terms of the GNU General Public License # | ||
| 6 | # as published by the Free Software Foundation; either version 2 # | ||
| 7 | # of the License, or (at your option) any later version. # | ||
| 8 | # # | ||
| 9 | # This program is distributed in the hope that it will be useful, # | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
| 12 | # GNU General Public License for more details. # | ||
| 13 | # # | ||
| 14 | # You should have received a copy of the GNU General Public License # | ||
| 15 | # along with this program; if not, write to the Free Software # | ||
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.# | ||
| 17 | # # | ||
| 18 | # Jon Howell can be contacted at: # | ||
| 19 | # 6211 Sudikoff Lab, Dartmouth College # | ||
| 20 | # Hanover, NH 03755-3510 # | ||
| 21 | # jonh@cs.dartmouth.edu # | ||
| 22 | # # | ||
| 23 | # An electronic copy of the GPL is available at: # | ||
| 24 | # http://www.gnu.org/copyleft/gpl.html # | ||
| 25 | # # | ||
| 26 | ############################################################################## | ||
| 27 | |||
| 28 | use strict; | ||
| 29 | |||
| 30 | package FAQ::OMatic::search; | ||
| 31 | |||
| 32 | use CGI; | ||
| 33 | use FAQ::OMatic::Item; | ||
| 34 | use FAQ::OMatic; | ||
| 35 | use FAQ::OMatic::SearchMod; | ||
| 36 | use FAQ::OMatic::HelpMod; | ||
| 37 | use FAQ::OMatic::Appearance; | ||
| 38 | use FAQ::OMatic::I18N; | ||
| 39 | |||
| 40 | sub main { | ||
| 41 | my $cgi = FAQ::OMatic::dispatch::cgi(); | ||
| 42 | |||
| 43 | my $params = FAQ::OMatic::getParams($cgi); | ||
| 44 | |||
| 45 | # Convert user input into a set of searchable words | ||
| 46 | FAQ::OMatic::SearchMod::convertSearchParams($params); | ||
| 47 | |||
| 48 | if (scalar(@{$params->{_searchArray}})==0) { | ||
| 49 | my $url = FAQ::OMatic::makeAref('faq', {}, 'url'); | ||
| 50 | FAQ::OMatic::redirect($cgi, $url); | ||
| 51 | } | ||
| 52 | |||
| 53 | # Get the names of the matching files | ||
| 54 | my $matchset = FAQ::OMatic::SearchMod::getMatchesForSet($params); | ||
| 55 | |||
| 56 | # Filter out those in the trash | ||
| 57 | # THANKS: dschulte@facstaff.wisc.edu for the suggestion | ||
| 58 | # I have no idea why grep{} won't work here, but I couldn't get it to. | ||
| 59 | my @finalset = (); | ||
| 60 | my $file; | ||
| 61 | foreach $file (@{$matchset}) { | ||
| 62 | my $item = new FAQ::OMatic::Item($file); | ||
| 63 | if (not $item->hasParent('trash')) { | ||
| 64 | push @finalset, $item; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | my $rt = FAQ::OMatic::pageHeader($params, ['search', 'faq']); | ||
| 69 | if (scalar(@{$matchset})==0) { | ||
| 70 | if ($params->{'_minMatches'} eq 'all') | ||
| 71 | { | ||
| 72 | $rt .= gettext("No items matched all of these words"); | ||
| 73 | } | ||
| 74 | else | ||
| 75 | { | ||
| 76 | $rt .= gettexta("No items matched at least %0 of these words", | ||
| 77 | $params->{'_minMatches'}); | ||
| 78 | } | ||
| 79 | $rt.= ": <i>" | ||
| 80 | .join(", ", @{$params->{'_searchArray'}}) | ||
| 81 | ."</i>.\n<br>\n"; | ||
| 82 | } else { | ||
| 83 | if ($params->{'_minMatches'} eq 'all') | ||
| 84 | { | ||
| 85 | $rt .= gettext("Search results for all of these words"); | ||
| 86 | } | ||
| 87 | else | ||
| 88 | { | ||
| 89 | $rt .= gettexta("Search results for at least %0 of these words", | ||
| 90 | $params->{'_minMatches'}); | ||
| 91 | } | ||
| 92 | $rt .= ": <i>" | ||
| 93 | .join(", ", @{$params->{'_searchArray'}}) | ||
| 94 | ."</i>:<p>\n"; | ||
| 95 | |||
| 96 | my $item; | ||
| 97 | my $itemboxes = []; | ||
| 98 | foreach $item (@finalset) { | ||
| 99 | push @$itemboxes, $item->displaySearchContext($params); | ||
| 100 | } | ||
| 101 | $rt .= FAQ::OMatic::Appearance::itemRender($params, $itemboxes); | ||
| 102 | } | ||
| 103 | |||
| 104 | if (not -f "$FAQ::OMatic::Config::metaDir/freshSearchDBHint") { | ||
| 105 | $rt .= "<br>" | ||
| 106 | . FAQ::OMatic::I18N::gettext("Results may be incomplete, because the search index has not been refreshed since the most recent change to the database.") | ||
| 107 | . "<p>\n"; | ||
| 108 | } | ||
| 109 | |||
| 110 | $rt.=FAQ::OMatic::HelpMod::helpFor($params, | ||
| 111 | 'Search Tips', "<br>"); | ||
| 112 | |||
| 113 | # $rt.=FAQ::OMatic::button( | ||
| 114 | # FAQ::OMatic::makeAref('faq', {'_minMatches'=>'','search'=>''}), | ||
| 115 | # 'Return to the FAQ'); | ||
| 116 | |||
| 117 | $rt .= FAQ::OMatic::pageFooter($params, ['search', 'faq']); | ||
| 118 | |||
| 119 | print $rt; | ||
| 120 | |||
| 121 | FAQ::OMatic::SearchMod::closeWordDB(); | ||
| 122 | } | ||
| 123 | |||
| 124 | 1; | ||
| 125 | |||
| 126 | |||
| 127 | |||
| 128 |