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

removing category names from search results

Quote Reply
removing category names from search results
How can I remove a cateogory name from the
search results, so it just lists the links.

Instead of looking like this:

Quote:
Top : Entertainment

Title1 - Description1

Top : Arts

Title2 - Description2
i would like it to read:
Quote:
Title1 - Description1

Title2 - Description2

Any help would be appreciated.


Quote Reply
Re: removing category names from search results In reply to
This is one that I keep changing, and then having to re-do. I've removed them from my NEW and COOL pages, but here is the clue for doing it with search.

I can't guarantee my search has not already been modified, so the lines may not be _exactly_ like yours, but the idea is what's important.

Code:
# 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}};
}
}

replace it with:

Code:
# 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 .= &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}};
# }
}

It works on my test site.



------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/








Quote Reply
Re: removing category names from search results In reply to
Thanks pugdog, it works perfectly.

Just in case if anyone else needs this mod, you need to make the changes that pugdog said above, which must be done in search.cgi at about line number 127



------------------
Robert Blackstone
Webmaster of Scato Search
www.scato.com
Quote Reply
Re: removing category names from search results In reply to
It's the little things that get away from me <G>
Quote Reply
Re: removing category names from search results In reply to
Thanks pugdog for the solution for modifying search.cgi in order to remove the category names in the search results. I've tried and tried, and I can't figure out how to make search-ni.cgi do the same thing. I need to order my search results by a priority field and from everything I've seen it looks like I'm stuck using search-ni.cgi to preserve the sort order, although as you duly note it is much more resource intensive than the indexed search.

Ideally, I would like to have the search results be ordered by the priority field, and then have them list out as follows:

Link 1 - description
Category Name & Link

Link 2 - description
Category Name & Link

Link 3 - description
Category Name & Link

But if anyone knows how to modify the search-ni.cgi so that it just doesn't print out the category names like pugdog did for search.cgi that would still be a huge help and solution for us.

Any help would be greatly appreciated...

-jwm

Quote Reply
Re: removing category names from search results In reply to
As long as you don't use alt-links, the sort order is not affected, and I'm pretty sure you'd have the same problem with the search-ni.cgi as well -- since the alt-links force a merge of two searches.



http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: removing category names from search results In reply to
Thanks, I'm not using the alt categories so that's good to know that the sort order will be preserved.

-jwm

Quote Reply
Re: removing category names from search results In reply to
Pugdog,

Just tried this with the numbered link mod and the result was that on every page the links were 1 to 10 and not 1 to 10, 11 to 20, 21 to 30 etc.

Here is the code I am using with both mods.


my $links_count=0;
# 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}};
# }
}



What's going wrong? It worked fine before I removed the category names from appearing with the search results.

JeffB.

Quote Reply
Re: removing category names from search results In reply to
Make sure you only initialize the $links_count variable ONCE before you start the whole process.

If the numbers are incrementing, but resetting each page, you need to put the initialization up higher, outside of the loop.

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

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 );
}


Quote Reply
Re: removing category names from search results In reply to
Replace my $links_count = 0; with the following codes:

Code:

my $links_count = '0';


Then later on in the sub search routine, add the following codes:

Code:

$links_count = 0;


BEFORE the following codes:

Code:

if ($link_hits) {


Then add the following codes:

Code:

$hit-> {'$links_count'}= $links_count+1;


BEFORE the following codes:

Code:

$hit->{'links_count'} = ++$links_count;


Regards,

Eliot

Quote Reply
Re: removing category names from search results In reply to
I did that and it still has 1 to 10 on each of the search results page - is there still something that needs changing? This is a nightmare!

JeffB

Updated Code...


# ==============================================================

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.
$links_count = 0;
if ($link_hits) {
my (%link_results, %displayed, $name);
foreach my $hit (@$link_hits) {
$hit = $linkdb->array_to_hash ($hit);
$hit-> {'$links_count'}= $links_count+1;
$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 );
}


Quote Reply
Re: removing category names from search results In reply to
You do not need to define $link_count as a global variable twice (with my). Delete the first $link_count in the first my line of codes.

Regards,

Eliot

Quote Reply
Re: removing category names from search results In reply to
Ok I deleted that and got this error message!:

Software error:

Execution of search.pl aborted due to compilation errors.


Here is the code at the moment:


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)};

# 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.
$links_count = 0;
if ($link_hits) {
my (%link_results, %displayed, $name);
foreach my $hit (@$link_hits) {
$hit = $linkdb->array_to_hash ($hit);
$hit-> {'$links_count'}= $links_count+1;
$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 );
}


Can you help Eliot?


Quote Reply
Re: removing category names from search results In reply to
You defined "my (... $link_count,...);" then deleted the line "my $links_count='0';"

You use $links_count in the routines below, but it's not defined.

Make sure you are not using both $link_count and $links_count.


http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: removing category names from search results In reply to
What do you mean?! $link_count was already set up in the original LinksSQL code. In the numbered link mod it tells you to use links_count;

How can I not use both. If I remove all the s, i.e. change everything to link_count it still doesn't work.

What did you mean? I think you guys are missing the fact one ends with a 's' and one doesn't (i.e. link_count and links_count)

Please paste code from above with the changes in it below.

JeffB.

(this must be a tricky one!)

Quote Reply
Re: removing category names from search results In reply to
Jeff,

You need to define BOTH $links_count and $link_count. Just don't define either one twice.

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: [pugdog] removing category names from search results In reply to
Is this thread still valid with GLinks 3.x?

I simply want to *not* include category names in search results.

Where is the checkbox/radio button in the admin for this option?
I can't seem to find it in my install. <g>

Thanks,
Chris
RGB World, Inc. - Development and Web hosting.
Support Center | Links SQL Plugins | Luna Templates | RGB World, Inc.
Quote Reply
Re: [rgbworld] removing category names from search results In reply to
rgbworld - in Admin, go to Setup, then Search Options.

Look for "build_search_gb" and select "No".

Hope this helps.