Eliot my site is at www.ohiobiz.com.
Also, here is my search.cgi file:
#!/usr/local/bin/perl
#!/usr/local/bin/perl
# ==============================================================
# -------------
# Links SQL
# -------------
# Links Manager
#
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 1.13
#
# COPYRIGHT NOTICE:
#
# Copyright 1999
Gossamer Threads Inc. All Rights Reserved.
# No redistribution of this script may be made without prior
# written consent.
#
# By using this program you agree to indemnify
Gossamer Threads # Inc. from any liability.
#
# Please see the README for full license details.
#
# ==============================================================
# Load required modules.
# ---------------------------------------------------
use CGI ();
use CGI::Carp qw/fatalsToBrowser/;
use lib 'admin';
use Links;
use Links::DBSQL;
use Links::DB_Utils;
use Links::HTML_Templates;
use strict;
$|++;
&main();
sub main {
# ---------------------------------------------------
# Determine what to do.
#
my $in = new CGI;
my $dynamic = $in->param('d') ? $in : undef;
print $in->header();
if ($in->param('query')) {
&search ($in, $dynamic);
}
else {
&site_html_search_form ( { query => '' }, $dynamic );
}
}
# ==============================================================
sub search {
# ---------------------------------------------------
# Performs the actual search.
#
my ($in, $dynamic) = @_;
my ($mh, $bool, $nh, $ww, $order, $query, $ignored, %seen, $next, $catid, $sub_list, $cat_name,
$catdb, $cat_hits, $category_results, $cat_count, $cat_errors, $linkdb, $link_hits, $link_results, $link_count, $link_errors);
my %in = %{&cgi_to_hash($in)};
# Get/Set the search options.
($in->param('mh') =~ /^(10|25|50|100)$/) ? ($mh = $1) : ($mh = 25);
($in->param('bool') =~ /^(and|or)$/i) ? ($bool = uc $1) : ($bool = 'OR');
($in->param('nh') =~ /^(\d+)$/) ? ($nh = $1) : ($nh = 1);
($in->param('substring')) ? ($ww = 0) : ($ww = 1);
($in->param('order') =~ /^(score|category)$/i) ? ($order = uc $1) : ($order = 'CATEGORY');
$catid = $in->param('catid');
# Get a list of catgeory ID's for 'only this cat' type of search
if ($catid eq ""){$cat_name=""} else {
# Get Category Name
$cat_name = &get_category_name ($catid);
# Get a list of category IDs where the name starts with $cat_name
$sub_list = &get_category_id_list ($cat_name);
chop($sub_list);
$in->param ( 'CategoryID' => $sub_list );
}
# Split up the search term.
$query = $in->param('query');
$query or &site_html_search_failure ( { error => "No search term entered.", %in }, $dynamic) and return;
$in{'term'} = $in->escape ($query);
# Search the category listings.
my %catfilter = ();
%catfilter->{'ID'}=$sub_list;
$catdb = new Links::DBSQL "$LINKS{admin_root_path}/defs/Category.def";
$cat_hits = $catdb->query ( { query => $query, mh => $mh, nh => $nh, ww => $ww, filter => \%catfilter} );
$cat_count = $catdb->hits || 0;
$cat_errors = $catdb->query_errors;
# Now let's search the links table, but first figure out any filters.
$linkdb = new Links::DBSQL "$LINKS{admin_root_path}/defs/Links.def";
my %filter = ();
foreach my $col (@{$linkdb->{db_cols}}) {
if ($in->param($col)) {
$filter{$col} = $in->param($col);
}
}
$link_hits = $linkdb->query ( { query => $query, mh => $mh, nh => $nh, filter => \%filter, ww => $ww, bool => $bool } );
$link_count = $linkdb->hits || 0;
$link_errors = $linkdb->query_errors;
# Format the errors (if any)
if (ref $link_errors eq 'HASH') {
foreach my $word (keys %$link_errors) {
next if ($seen{$word}++);
$ignored .= "<li>$word - " . $link_errors->{$word};
}
}
if (ref $cat_errors eq 'HASH') {
foreach my $word (keys %$cat_errors) {
next if ($seen{$word}++);
$ignored .= "<li>$word - " . $cat_errors->{$word};
}
}
# Return if we don't have any matches.
unless ($link_count or $cat_count) {
&log_query ($in->param('query'), 0);
&site_html_search_failure ({ error => "No matching links.", ignored => $ignored, %in }, $dynamic);
return;
}
# Only display the category output on the first page.
if ($nh == 1) {
if ($cat_hits) {
foreach my $hit (@$cat_hits) {
$hit = $catdb->array_to_hash($hit);
$category_results .= "<li>" . &search_build_linked_title ($hit->{Name}) . "\n";
}
}
}
# Build the list of link results.
if ($link_hits) {
my (%link_results, %displayed, $name);
foreach my $hit (@$link_hits) {
$hit = $linkdb->array_to_hash ($hit);
$link_results{$hit->{CategoryID}} .= &site_html_link ($hit, $dynamic);
}
foreach my $hit (@$link_hits) {
next if ($displayed{$hit->{CategoryID}}++);
$name = &get_category_name ($hit->{CategoryID});
$link_results .= "<p>" . &search_build_linked_title ($name) . "</p>";
$link_results .= $link_results{$hit->{CategoryID}};
}
}
# Log the search results.
&log_query ($in->param('query'), $link_count + $cat_count);
# If we want to bold the search terms...
if ($LINKS{search_bold}) {
my $tempquery = $query;
$tempquery =~ s/[+\-"']//g;
my @terms = split /\s/, $tempquery;
foreach (@terms) {
if (s/(.+)\*(.*)/$1/) {
push @terms, $2 if ($2);
$link_results =~ s,(<[^>]+>)|(\Q$_\E),defined($1) ? $1 : "<B>$2</B>",gie;
$category_results =~ s,(<[^>]+>)|(\Q$_\E),defined($1) ? $1 : "<B>$2</B>",gie;
}
else {
$link_results =~ s,(<[^>]+>)|(\Q$_\E),defined($1) ? $1 : "<B>$2</B>",gie;
$category_results =~ s,(<[^>]+>)|(\Q$_\E),defined($1) ? $1 : "<B>$2</B>",gie;
}
}
}
# Search toolbar.
($link_count > $mh) and ($next = $linkdb->toolbar());
# Print out the HTML results.
&site_html_search_results ( { link_results => $link_results, category_results => $category_results,
link_hits => $link_count, cat_hits => $cat_count, next => $next, ignored => $ignored, %in }, $dynamic );
}
sub search_build_linked_title {
# --------------------------------------------------------
# Returns a string of the current category broken up
# by section, with each part linked to the respective section.
#
my $input = shift;
my (@dirs, $dir, $output, $path);
@dirs = split (/\//, $input);
$output = qq| <A HREF="$LINKS{build_root_url}/">Top</A> :|;
for (0 .. $#dirs) {
$path = "/" . &build_clean_name( join "/", @dirs[0 .. $_] );
$output .= qq| <A HREF="$LINKS{build_root_url}$path/">$dirs[$_]</A> :|;
}
chop $output;
return $output;
}
sub log_query {
# --------------------------------------------------------
# Logs the search term.
#
my ($query, $results) = @_;
my $db = new Links::DBSQL "$LINKS{admin_root_path}/defs/Search_Log.def";
$query =~ s/^\s*//g; $query =~ s/\s*$//g;
$query = lc $query;
$query = substr ($query, 0, 24);
my $hit = $db->get_record ( $query, 'HASH' );
my $time = $db->get_date . " " . $db->get_time;
if ($hit) {
$hit->{Count}++;
$hit->{Last_Hit} = $time;
$hit->{Results} = $results;
$db->modify_record ($hit);
}
else {
$db->add_record ( { Term => $query, Count => 1, Last_Hit => $time, Results => $results } );
}
}
Thanks.
Mark G.