Added advanced search to site search mechanism.
This commit is contained in:
parent
bb226a6bc9
commit
22df79bdf4
2 changed files with 23 additions and 50 deletions
|
|
@ -22,7 +22,7 @@ sub process {
|
|||
$output = $_[0];
|
||||
$f = WebGUI::HTMLForm->new(1);
|
||||
$f->hidden("op","search");
|
||||
$f->text("keywords",'',$session{form}{keywords});
|
||||
$f->text("atLeastOne",'',$session{form}{atLeastOne});
|
||||
$f->submit(WebGUI::International::get(364));
|
||||
$temp = $f->print;
|
||||
$output =~ s/\^\?\;/$temp/g;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use strict;
|
|||
use WebGUI::HTMLForm;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Paginator;
|
||||
use WebGUI::Search;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::URL;
|
||||
|
|
@ -24,55 +25,27 @@ our @EXPORT = qw(&www_search);
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_search {
|
||||
my ($f, $p, $output, %page, @keyword, $pageId, $term, %result, $sth, @row, $i);
|
||||
$f = WebGUI::HTMLForm->new(1);
|
||||
$f->hidden("op","search");
|
||||
$f->text("keywords",'',$session{form}{keywords});
|
||||
$f->submit(WebGUI::International::get(364));
|
||||
$output = $f->print;
|
||||
if ($session{form}{keywords} ne "") {
|
||||
@keyword = split(" ",$session{form}{keywords});
|
||||
foreach $term (@keyword) {
|
||||
$sth = WebGUI::SQL->read("select pageId from page where title like '%".$term."%' and pageId > 25");
|
||||
while (($pageId) = $sth->array) {
|
||||
$result{$pageId} += 5;
|
||||
}
|
||||
$sth->finish;
|
||||
$sth = WebGUI::SQL->read("select pageId from page where metaTags like '%".$term."%' and pageId > 25");
|
||||
while (($pageId) = $sth->array) {
|
||||
$result{$pageId} += 1;
|
||||
}
|
||||
$sth->finish;
|
||||
$sth = WebGUI::SQL->read("select pageId from page where synopsis like '%".$term."%' and pageId > 25");
|
||||
while (($pageId) = $sth->array) {
|
||||
$result{$pageId} += 4;
|
||||
}
|
||||
$sth->finish;
|
||||
$sth = WebGUI::SQL->read("select pageId from wobject where title like '%".$term."%' and pageId > 25");
|
||||
while (($pageId) = $sth->array) {
|
||||
$result{$pageId} += 5;
|
||||
}
|
||||
$sth->finish;
|
||||
$sth = WebGUI::SQL->read("select pageId from wobject where description like '%".$term."%' and pageId > 25");
|
||||
while (($pageId) = $sth->array) {
|
||||
$result{$pageId} += 2;
|
||||
}
|
||||
$sth->finish;
|
||||
foreach $pageId (sort{$result{$a} <=> $result{$b}} keys %result) {
|
||||
%page = WebGUI::SQL->quickHash("select pageId, title, urlizedTitle from page where pageId=$pageId");
|
||||
$row[$i] = '<li><a href="'.WebGUI::URL::gateway($page{urlizedTitle}).'">'.$page{title}.'</a>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
if ($row[0] ne "") {
|
||||
$p = WebGUI::Paginator->new(WebGUI::URL::page('op=search'),\@row,20);
|
||||
$output .= WebGUI::International::get(365).'<p><ol>';
|
||||
$output .= $p->getPage($session{form}{pn});
|
||||
$output .= '</ol>'.$p->getBarTraditional($session{form}{pn});
|
||||
$output .= $f->print;
|
||||
} else {
|
||||
$output .= WebGUI::International::get(366);
|
||||
}
|
||||
my ($constraints, $p, $output, %page, $sth, @row, $i);
|
||||
$output = WebGUI::Search::form({op=>'search'});
|
||||
$constraints = WebGUI::Search::buildConstraints([qw(page.synopsis page.title page.menuTitle page.metaTags
|
||||
page.urlizedTitle wobject.description wobject.title wobject.namespace)]);
|
||||
if ($constraints ne "") {
|
||||
tie %page, 'Tie::CPHash';
|
||||
$sth = WebGUI::SQL->read("select page.urlizedTitle,page.title,wobject.wobjectId from page,wobject where $constraints
|
||||
and page.pageId=wobject.pageId and (page.pageId > 25 or page.pageId=1) and page.pageId<>$session{page}{pageId} order by lastEdited");
|
||||
while (%page = $sth->hash) {
|
||||
$row[$i] = '<li><a href="'.WebGUI::URL::gateway($page{urlizedTitle}).'#'.$page{wobjectId}.'">'.$page{title}.'</a>';
|
||||
$i++;
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
if ($row[0] ne "") {
|
||||
$p = WebGUI::Paginator->new(WebGUI::URL::page('op=search'),\@row,$session{form}{numResults});
|
||||
$output .= '<p/>'.WebGUI::International::get(365).'<p><ol>';
|
||||
$output .= $p->getPage($session{form}{pn});
|
||||
$output .= '</ol>'.$p->getBarTraditional($session{form}{pn});
|
||||
} elsif ($session{form}{exactPhrase} ne "" || $session{form}{all} ne "" || $session{form}{without} ne "" || $session{form}{atLeastOne} ne "") {
|
||||
$output .= '<p/>'.WebGUI::International::get(366).'<p/>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue