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
|
##############################################################################
# The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. #
# #
# 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. #
# #
# 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. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.#
# #
# Jon Howell can be contacted at: #
# 6211 Sudikoff Lab, Dartmouth College #
# Hanover, NH 03755-3510 #
# jonh@cs.dartmouth.edu #
# #
# An electronic copy of the GPL is available at: #
# http://www.gnu.org/copyleft/gpl.html #
# #
##############################################################################
use strict;
package FAQ::OMatic::search;
use CGI;
use FAQ::OMatic::Item;
use FAQ::OMatic;
use FAQ::OMatic::SearchMod;
use FAQ::OMatic::HelpMod;
use FAQ::OMatic::Appearance;
use FAQ::OMatic::I18N;
sub main {
my $cgi = FAQ::OMatic::dispatch::cgi();
my $params = FAQ::OMatic::getParams($cgi);
# Convert user input into a set of searchable words
FAQ::OMatic::SearchMod::convertSearchParams($params);
if (scalar(@{$params->{_searchArray}})==0) {
my $url = FAQ::OMatic::makeAref('faq', {}, 'url');
FAQ::OMatic::redirect($cgi, $url);
}
# Get the names of the matching files
my $matchset = FAQ::OMatic::SearchMod::getMatchesForSet($params);
# Filter out those in the trash
# THANKS: dschulte@facstaff.wisc.edu for the suggestion
# I have no idea why grep{} won't work here, but I couldn't get it to.
my @finalset = ();
my $file;
foreach $file (@{$matchset}) {
my $item = new FAQ::OMatic::Item($file);
if (not $item->hasParent('trash')) {
push @finalset, $item;
}
}
my $rt = FAQ::OMatic::pageHeader($params, ['search', 'faq']);
if (scalar(@{$matchset})==0) {
if ($params->{'_minMatches'} eq 'all')
{
$rt .= gettext("No items matched all of these words");
}
else
{
$rt .= gettexta("No items matched at least %0 of these words",
$params->{'_minMatches'});
}
$rt.= ": <i>"
.join(", ", @{$params->{'_searchArray'}})
."</i>.\n<br>\n";
} else {
if ($params->{'_minMatches'} eq 'all')
{
$rt .= gettext("Search results for all of these words");
}
else
{
$rt .= gettexta("Search results for at least %0 of these words",
$params->{'_minMatches'});
}
$rt .= ": <i>"
.join(", ", @{$params->{'_searchArray'}})
."</i>:<p>\n";
my $item;
my $itemboxes = [];
foreach $item (@finalset) {
push @$itemboxes, $item->displaySearchContext($params);
}
$rt .= FAQ::OMatic::Appearance::itemRender($params, $itemboxes);
}
if (not -f "$FAQ::OMatic::Config::metaDir/freshSearchDBHint") {
$rt .= "<br>"
. FAQ::OMatic::I18N::gettext("Results may be incomplete, because the search index has not been refreshed since the most recent change to the database.")
. "<p>\n";
}
$rt.=FAQ::OMatic::HelpMod::helpFor($params,
'Search Tips', "<br>");
# $rt.=FAQ::OMatic::button(
# FAQ::OMatic::makeAref('faq', {'_minMatches'=>'','search'=>''}),
# 'Return to the FAQ');
$rt .= FAQ::OMatic::pageFooter($params, ['search', 'faq']);
print $rt;
FAQ::OMatic::SearchMod::closeWordDB();
}
1;
|