Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

search on custom table if no search results

Quote Reply
search on custom table if no search results
I have a custom table build in GLINKS called 'cars' and I want to do a search on a colum 'brand' of this table
if a normal search on the Links table doesn´t get any search results.

Is there a global or a little plugin which would help me?
I would be really happy if someone could help me.

Regards
Quote Reply
Re: [P-Man] search on custom table if no search results In reply to
I'm afraid its not that easy. First, in order for any links modules to read from any SQL table, it must have a matching definition file. This means that the table must be created with creator.

You can try creating a new one with my tables plugin:

http://www.gossamer-threads.com/...search_engine#293773

And you could insert a new global in your search results.html template like so:

Code:

sub {
my $tags = shift;
my $db= $DB->table('cars');
my $sth = $db->select({ brand => $tags->query });
while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('brand', $rec);
}
return $output;
}


This assumes that there will be more than one brand result. You could make a new template (i.e. brand.html) that you could customize to display the rest of your fields for the brand result. The idea is the same.

The problem is that these results will be separate from your link results.

Hope this gets you going,

- Jonathan
Quote Reply
Re: [jdgamble] search on custom table if no search results In reply to
Thank you...I´ve already used the creator to build the table, it´s ok.

But there have to be a way to integrate the results of this global in the search results from the links results and not only separate.

Maybe it could be done with a plugin hook into the search results?
I´ve found Andy´s free searchfeed plugin, it integrates search results into the glinks search results template from searchfeed.
http://www.gossamer-threads.com/...orum.cgi?post=267809

Is there a way to change your global to work in such kind of plugin?
Quote Reply
Re: [P-Man] search on custom table if no search results In reply to
There are 3 plugin hooks for search. Goto your admin developer guide:

admin.cgi?do=help&topic=help_guide_hooks.html

I don't see why or how you would integrate the results. Category results and link results are different. So wouldn't car brands be different too?





- Jonathan
Quote Reply
Re: [jdgamble] search on custom table if no search results In reply to
Jonathan you are right, it was my mistake there seems to be no way to integrate the results of the global in the links results.
But this is not necessary, because I only want to get results from the custom table if there are no results from the links table.
Code:
sub {
my $tags = shift;
my $db= $DB->table('cars');
my $sth = $db->select({ brand => $tags->query });
while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('brand', $rec);
}
return $output;
}




Now, I have an addidtional question about your global....how can I make this search global more sophisticated?

for example: if the value in 'brand' is "Mercedes Benz Cars"
and the user does a search query for Mercedes Benz the global should do a search for +Mercedes +Benz
and find the value 'Mercedes Benz Cars' as a result.

Thank you for your help
Quote Reply
Re: [P-Man] search on custom table if no search results In reply to
You can view GT::SQL::Search.pm and GT::SQL::Table.pm for details. Generally, you want to use <query> or <query_sth>:

Code:

my $results = $db->query($in);


where input is all of your search options.

Hope this helps,

- Jonathan