Gossamer Forum
Quote Reply
ZipCodeSearch plugin
I am very close to having a plugin that will search for links within xx radius of a given zip code.
I need a little help understanding query wrt a search_results hook.

I am calling a barely modified copy of GTs subroutine "search" at the end of my hook.
I want to just change $IN->param('query'); so that it holds (and finds) an array of zip codes or link ids.
Q: Is it possible to have query be something like this: $IN->param('query', Zip = '54736,54720,78767');?
Q: Or does query have to be just a single word or phrase?

My reasoning for calling search() is that I want all the paging options, category groupings and mh options already built into the "search" subroutine.

The following code works, but is not completed. I have a variable called $zip_code_list which holds a value of say '5473654720787675472054720'. It could easily be an array of link ids.

I also have a variable @output, which is an array? of the matching links. So I have the matching links already. Again the reason for wanting to call "search()" is for all the additional options in there. Besides the fact that when I try to return \@output, I get an error (actually in SearchFeed results), but I am sure it is my fault :-)

Code:
sub search_results_hook {

GT::Plugins->action ( STOP );

my $query = $IN->param('query');
my $zipcode_db = $DB->table('ZipCodes') || return $GT::SQL::error;
my $osth = $zipcode_db->select( ['ZipCode','Latitude','Longitude','State'], { ZipCode => $query });

my $olat = $osth->{Latitude};
my $olong = $osth->{Longitude};
my $dist = '500';
my $zip_code_list;

my $table = $DB->table('Links');
my $sth = $table->select;

my @output;

while (my $link = $sth->fetchrow_hashref) {

my $lat = $link->{Latitude};
my $lon = $link->{Longitude};

if(distance($olat, $olong, $lat, $lon, "K") lt $dist && $link->{Zip} ne '00000')
{
$zip_code_list .= $link->{Zip};
push (@output, $link);
}
}

return search();
}

Any help in cleaning up this code and finishing this plugin is greatly appreciated.

I have one other question wrt the way I am doing all this...
When a link is added or modified, I grab the zipcode's longitude and latitude from a table of all US zip codes.
I put them into custom columns in lsql_Links.

Q: Would I be better off to *NOT* put the longitude/latitude in lsql_Links table?
And instead, when searching, grab ALL zip codes from the ZipCodes table that are within the radius and proceed to find links that match any of those zipcodes?

This method would be a 2 part search, but would keep redundent data out of lsql_links table. It would also probably be better for updates to the zipcode database.

I hope this makes sense :-)

Thanks again,
Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com