Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Trying to create search based on field

Quote Reply
Trying to create search based on field
Not a very good title for what I'm trying to do. Can't think of a short or clear version!

What I want to do is let visitors slice our links geographically as well as by the topic-based categories.
So we have a field "Address_Region" and a menu bar which links to 18 or so versions of:

catonlyresults is a flag for search_results.html to format results with:
<%loop link_results_loop%>
<%title_linked%><BR />
so we get just a list of categories that contain results from the region requested, without the links themselves.

But of course clicking on the linked title displays the entire category, not just the results for the region. I'd hoped I could modify title_linked so that the last part of the breadcrumb would be a search with both category and region specified. Although that might be doable it would require a cat name to catID translation and some complex regexp substitutions. Clumsy at best - is there an easier/more obvious way to achieve what I want (v2.2.1) ?


Quote Reply
Re: [CrazyGuy] Trying to create search based on field In reply to
Well I'm moderately proud with the fact that I've actually solved this myself so I'll share the solution here in the hope that it might help someone else - though I'm sure my code could be streamlined a lot.

Basically this sub takes the title_linked, splits the categories out, removes the link from each to make them plain text - except for the last level which it finds the catid for based on its name, and turns the link into a search link including the geographical region. Then it stitches back together a new title_linked.

So - for a "forced" set of search results which displays categories containing a specific match (in my case the region of the link) - this allows the category name to become a link to drill down into that category while maintaining the "must have" match.

Caveats -
the category name (last part, not full name) has to be unique - this wouldn't work if you had a structure:

It has to be:
rugby clubs
football clubs

but that's probably fixable (you could convert the title_linked to the full category name I guess and get the catid for that)

... and there may well be a better way to do the whole thing :)

sub {
my $vars = shift;
my $title_linked = $vars->{title_linked};
my $Address_Region = $vars->{Address_Region};
my @cats_array = split(/ : /, $title_linked);
my $last_cat = pop(@cats_array);
my $new_title_linked = "";
while (@cats_array)
my $temp_cat = shift(@cats_array);
$temp_cat =~ s/<\/a>//i;
$temp_cat =~ s/<a.*>//i;
$new_title_linked .= "$temp_cat : ";

$last_cat =~ s/<\/a>//i;
$last_cat =~ s/<a.*>//i;

my $query = $DB->table('Category');
my $results;
$results = $query->select ( ('ID'),{Name => $last_cat} )->fetchrow_array;

$last_cat = qq~<A HREF="/cgi-bin/directory/search.cgi?d=1&query=&catid=$results&Address_Region=$Address_Region">$last_cat</A>~;

$title_linked = "$new_title_linked$last_cat";
return $title_linked;