From 22df79bdf4cea3aab5c30c508f1b1b55d6209084 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sat, 1 Jun 2002 20:38:07 +0000 Subject: [PATCH] Added advanced search to site search mechanism. --- lib/WebGUI/Macro/Question_search.pm | 2 +- lib/WebGUI/Operation/Search.pm | 71 +++++++++-------------------- 2 files changed, 23 insertions(+), 50 deletions(-) diff --git a/lib/WebGUI/Macro/Question_search.pm b/lib/WebGUI/Macro/Question_search.pm index 65728db9f..b1f73b16c 100644 --- a/lib/WebGUI/Macro/Question_search.pm +++ b/lib/WebGUI/Macro/Question_search.pm @@ -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; diff --git a/lib/WebGUI/Operation/Search.pm b/lib/WebGUI/Operation/Search.pm index 777b0d48d..5ba1c9a2f 100644 --- a/lib/WebGUI/Operation/Search.pm +++ b/lib/WebGUI/Operation/Search.pm @@ -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] = '
  • '.$page{title}.''; - $i++; - } - } - if ($row[0] ne "") { - $p = WebGUI::Paginator->new(WebGUI::URL::page('op=search'),\@row,20); - $output .= WebGUI::International::get(365).'

      '; - $output .= $p->getPage($session{form}{pn}); - $output .= '
    '.$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] = '
  • '.$page{title}.''; + $i++; + } + $sth->finish; + } + if ($row[0] ne "") { + $p = WebGUI::Paginator->new(WebGUI::URL::page('op=search'),\@row,$session{form}{numResults}); + $output .= '

    '.WebGUI::International::get(365).'

      '; + $output .= $p->getPage($session{form}{pn}); + $output .= '
    '.$p->getBarTraditional($session{form}{pn}); + } elsif ($session{form}{exactPhrase} ne "" || $session{form}{all} ne "" || $session{form}{without} ne "" || $session{form}{atLeastOne} ne "") { + $output .= '

    '.WebGUI::International::get(366).'

    '; } return $output; }