Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Re: removing category names from search results

Quote Reply
Re: removing category names from search results In reply to
I moved the my $links_count=0; to the top but it still produces the same results?! Here is the entire sub search routine.

Thanks Pugdog.



sub search {
# ---------------------------------------------------
# Performs the actual search.
#
my ($in, $dynamic) = @_;
my ($mh, $bool, $nh, $ww, $order, $query, $ignored, %seen, $next,
$catdb, $cat_hits, $category_results, $cat_count, $cat_errors, $linkdb, $link_hits, $link_results, $link_count, $link_errors);
my %in = %{&cgi_to_hash($in)};
my $links_count=0;

# Get/Set the search options.
($in->param('mh') =~ /^(10|25|50|100)$/) ? ($mh = $1) : ($mh = 10);
($in->param('bool') =~ /^(and|or)$/i) ? ($bool = uc $1) : ($bool = 'AND');
($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');

# 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.
$catdb = new Links::DBSQL "$LINKS{admin_root_path}/defs/Category.def";
$cat_hits = $catdb->query ( { query => $query, mh => $mh, nh => $nh } );
$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 } );
$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);
$hit->{'links_count'} = ++$links_count;
$link_results .= &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 );
}


Subject Author Views Date
Thread removing category names from search results Robert_B 22478 Apr 16, 2000, 12:42 PM
Post Re: removing category names from search results
pugdog 22231 Apr 16, 2000, 7:56 PM
Post Re: removing category names from search results
Robert_B 22192 Apr 17, 2000, 3:09 AM
Thread Re: removing category names from search results
pugdog 22187 Apr 17, 2000, 8:18 AM
Thread Re: removing category names from search results
jwm 22153 Jul 12, 2000, 5:40 PM
Thread Re: removing category names from search results
pugdog 22196 Jul 12, 2000, 7:39 PM
Post Re: removing category names from search results
jwm 22143 Jul 13, 2000, 9:45 AM
Thread Re: removing category names from search results
jeffb 22131 Jul 25, 2000, 8:26 AM
Thread Re: removing category names from search results
pugdog 22131 Jul 25, 2000, 10:12 AM
Thread Re: removing category names from search results
jeffb 22130 Jul 25, 2000, 12:52 PM
Thread Re: removing category names from search results
Stealth 22124 Jul 25, 2000, 1:09 PM
Thread Re: removing category names from search results
jeffb 22125 Jul 25, 2000, 3:14 PM
Thread Re: removing category names from search results
Stealth 22095 Jul 25, 2000, 3:48 PM
Thread Re: removing category names from search results
jeffb 22096 Jul 25, 2000, 4:11 PM
Thread Re: removing category names from search results
pugdog 22180 Jul 25, 2000, 6:29 PM
Thread Re: removing category names from search results
jeffb 22113 Jul 26, 2000, 1:32 AM
Thread Re: removing category names from search results
pugdog 22098 Jul 26, 2000, 9:45 PM
Thread Re: [pugdog] removing category names from search results
rgbworld 21772 Apr 30, 2006, 5:54 PM
Post Re: [rgbworld] removing category names from search results
phuketkit 21587 Jul 18, 2006, 3:15 AM