package WebGUI::Widget::SearchMnoGo; #------------------------------------------------------------------- # WebGUI is Copyright 2001 Plain Black Software. #------------------------------------------------------------------- # Please read the legal notices (docs/legal.txt) and the license # (docs/license.txt) that came with this distribution before using # this software. #------------------------------------------------------------------- # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- use DBI; use strict; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; use WebGUI::Utility; use WebGUI::Widget; #------------------------------------------------------------------- sub _mnogoSearch { my ($i, %match, $key, $sth, $dbh, $urlId, %data, $output, @keyword, $word, %result); %data = @_; @keyword = split(/ /,$session{form}{query}); if ($data{DSN} =~ /\DBI\:\w+\:\w+/) { $dbh = DBI->connect($data{DSN},$data{username},$data{identifier}); } else { $output .= 'Error: The DSN specified is of an improper format.
'; WebGUI::ErrorHandler::warn("Search (MnoGo) The DSN specified is of an improper format."); } if (defined $dbh) { foreach $word (@keyword) { $sth = WebGUI::SQL->read("select url_id from dict where soundex(word)=soundex(lcase('$word'))",$dbh); if (defined $sth) { while (($urlId) = $sth->array) { $result{$urlId}++; } $sth->finish; } else { $output .= 'Error: There was a problem with the query.
';
WebGUI::ErrorHandler::warn("Search (MnoGo) There was a problem with the query.");
}
}
foreach $key (sort {$result{$b} <=> $result{$a}} keys %result) {
if ($i < 50) {
%match = WebGUI::SQL->quickHash("select url,title,txt from url where rec_id=$key",$dbh);
$output .= ''.$match{title}.' ('.$result{$key}.')
'.$match{txt}.'
'.$match{url}.'
'; } $i++; } $dbh->disconnect(); } else { $output .= 'Error: Could not connect to remote database.
';
WebGUI::ErrorHandler::warn("Search (MnoGo) Could not connect to remote database.");
}
return $output;
}
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from SearchMnoGo where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "Search (MnoGo)";
}
#-------------------------------------------------------------------
sub www_add {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$output = '

'; } $output .= '
'; $output .= _mnogoSearch(%data); } return $output; } 1;