Gossamer Forum
Quote Reply
Additional Search Data
I am looking for a global that will do the following:

If I add feilds to my links database for "color" and "size" I want to be able to bring the following back in searches:

Color:
_______________________________________
Red (8)
Green (14)
Blue (2)
Yellow (5)

Size:
_______________________________________
XXL (7)
XL (3)
L (1)
M (13)
S (10)

So, if I click on Red, only those 8 listings will show. If there are no "red" listings, then I would like red to not show up at all.
I would also like the regular search listings to be returned also.
Any help would be appreciated!

George
Quote Reply
Re: [macbethgr] Additional Search Data In reply to
You could acomplish this quite easily. Something like a link;

search.cgi?query=&color=red&d=1

.... or you could create a dropdown box on the search page, with these different options in.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Additional Search Data In reply to
Thanks Andy,

Thanks for your reply. That would be very simple and has already been covered in this forum, What I am looking for is a little more complex..... I want the number of links with "Red" "Green" "Blue" or "Yellow" to be displayed. And I only want them to be displayed if there is a match... Since there may be 30 or 40 different colors, I don't want them all listed if the only match is red... Also, "Color" may not apply to the search results, in that case, I don't want any color listed at all. The plugin would have to "look" at what is listed in that field, so if "Yellow" is found, the plugin would have to count how often "Yellow" is listed and return that number. It would be preferable to not have to list each color in the plugin, since there may be many, but to have the plugin "read" the field and to determine how often each color is listed. That way, if a new color is added, the plugin would not have to be changed. This would also work great not only for search results, but in the directory also as a person drills down through different categories.

Thanks
George
Quote Reply
Re: [macbethgr] Additional Search Data In reply to
Would a global like the following do what you require?

Code:
sub {
my $tags = {};

my $links = $Links::DB->table( "Links" );
foreach my $colour ( qw( red green blue white brown black periwinkle ) ) { # periwinkle is my favourite colour ;)
$tags->{$colour} = $links->count({
colour => $colour,
# more conditions here as required
}) || 0;
}

return $tags;
}

Then in the HTML you could use something like:

Code:
<%makesuretocalltheglobalbeforehand()%>
<%if red%><span class=red>RED (<%red%>)<%endif%>
Quote Reply
Re: [Aki] Additional Search Data In reply to
Thanks!
I think it would work.... One question, is there a way to use the global to "read" the entries in the column so I would'nt have to enter each color? There may be over 100 entries in that field.
George
Quote Reply
Re: [macbethgr] Additional Search Data In reply to
I believe if you do the following:

Code:
my $links = $Links::DB->table( "Links" );

my $cols = $links->cols;

$cols is a hashreference that describes the columns in the Links database. The utility in this case would be that if you have a special prefix for each of the colours, it should be easy enough to create an array of colours by iterating through each of the keys and doing a simple regular expression match.

What are the names of your columns in your case? Do they have a format like:

item_colour_blue
item_colour_white
item_colour_purple

Then you can amend the code with something like:

Code:
my $cols = $links->cols;
my @colours;
foreach my $k ( keys %$cols ) {
next unless $k =~ /^item_colour/;
push @colours, $k;
}

foreach my $colour ( @colours ) {
# ... and so on.


or are they straight out the colournames like?

blue
white
purple

If it is the second, I believe you'll probably have to enter in each the colours by hand.
Quote Reply
Re: [Aki] Additional Search Data In reply to
Thanks,
They would be just the color names... however, there would be no other data in that column.... The column name would be "item_color" and the field would have the color (Red, Green, Blue, etc.) or will be blank if it does not apply. Another column might be "item_size" and the fields would have the size (S,M,L,XL,XXL,One Size, Etc.) or will be blank if it does not apply. It would be great to be able to "pre-format" the results in the global, that way, if there are result matches for 30 different colors it can be formatted in 3 columns of 10..... but I may be getting ahead of myself.
George