Gossamer Forum
Quote Reply
priority search results
Im trying to find a way to show priority links seprately on a search results page. Ive seen globals that does priorty links which is fine, but what I need is a global that displays say 4 priorty links that are matches to keywords used away from the normal link results.

Ive found a global that does something similar:


-----

sub {

my $tags = shift;
my $query = $tags->{query};
my $sth = $DB->table('Links')->select ( { Keyword => $query } );
my $output; while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link_sponsor_search', $link);
}
return $output;
}
-----

The global does a search on a column called Keyword.

What I would need is a global like above but that does a search as normal, however only displays priorty links,
in my database I indicate priority links with a simple Yes or No column. So basically would need a global that displays search results where this column, priorty = Yes

Can this be done? Anyone knows how to do it???

Thanks
Quote Reply
Re: [demon] priority search results In reply to
Hi,

There many ways to do that. One of them is below


sub {

my $tags = shift;
my $query = $tags->{query};
my $sth = $DB->table('Links')->select ( { Keyword => $query, Priority => 'Yes' } );
my $output; while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link_sponsor_search', $link);
}
return $output;
}

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] priority search results In reply to
Thanks,

Yes I was guessing it was done that way.. But my question and problem is that I want it to do a normal search, i.e. on all columns. The global above, only does it on a field called Keywords. I want it do do a search on all fields but only show results that have Priority = Yes.

Above global does not work very well, since it has to be an exact keyword match.. so it very very often will not give any match..

Any ideas?

Thanks
Quote Reply
Re: [demon] priority search results In reply to
In that case, we can do this

sub {

my $tags = shift;
my $query = $tags->{query};
my $sth = $DB->table('Links')->query_sth ( { query => $query,ma => 1 } );
my $output; while (my $link = $sth->fetchrow_hashref) {
next unless($link->{Priority} eq 'Yes');
$output .= Links::SiteHTML::display('link_sponsor_search', $link);
}
return $output;
}

It works

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] priority search results In reply to
Wow, yes that works perfect! Just what I needed..

One last thing.. how do I limit it to say 5 links?

I tried adding db select but doesnt work.. Im not that great with globals!

Any idea?

Thank you very much!!
Quote Reply
Re: [demon] priority search results In reply to
That is just adding mh and nh to the query_sth.

query_sth ( { query => $query,ma => 1 ,mh => 5,nh=>1}

That should work!

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] priority search results In reply to
Yes that works!

Thank you so much, works great!!
Quote Reply
Re: [demon] priority search results In reply to
You're welcome.

Actually, you need to add two more parameters to make sure the results are 5 links with Priority = 'Yes'

That's is query_sth({query=> $query,nh=>1,ma=>1,mh=>5,sb=>'Priority',so =>'Desc'})

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog