diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 793e4e178..32a76b77c 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -23,6 +23,12 @@ save you many hours of grief. Template HTML::Template::Expr + * In order to make the upgrades run quickly, the upgrade process + will not automatically index your sites for the new search + engine. You need to do this manually after the upgrades + have completed by running the search.pl script in the + sbin folder. + 6.8.4 -------------------------------------------------------------------- diff --git a/docs/upgrades/upgrade_6.8.5-6.9.0.pl b/docs/upgrades/upgrade_6.8.5-6.9.0.pl index 98df292ed..d1fc9d829 100644 --- a/docs/upgrades/upgrade_6.8.5-6.9.0.pl +++ b/docs/upgrades/upgrade_6.8.5-6.9.0.pl @@ -22,6 +22,7 @@ my $session = start(); # this line required templateParsers(); removeFiles(); +addSearchEngine(); finish($session); # this line required diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index ea3319361..3d980d07b 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -993,7 +993,9 @@ Returns an indexer object for this asset. When this method is called the asset's sub indexContent { my $self = shift; - return WebGUI::Search::Index->create($self); + my $indexer = WebGUI::Search::Index->create($self); + $indexer->setIsPublic(0) if ($self->getId eq "PBasset000000000000001"); + return $indexer; } diff --git a/lib/WebGUI/Form/Control.pm b/lib/WebGUI/Form/Control.pm index f08c75734..7b8752a52 100644 --- a/lib/WebGUI/Form/Control.pm +++ b/lib/WebGUI/Form/Control.pm @@ -397,7 +397,7 @@ Retrieves a value from a form GET or POST and returns it. If the value comes bac sub getValueFromPost { my $self = shift; - my $formValue = $self->session->request->param($self->get("name")); + my $formValue = $self->session->request->param($self->get("name")) if ($self->session->request); if (defined $formValue) { return $formValue; } else { diff --git a/lib/WebGUI/Search.pm b/lib/WebGUI/Search.pm index a510dbb88..34f344bf8 100644 --- a/lib/WebGUI/Search.pm +++ b/lib/WebGUI/Search.pm @@ -48,9 +48,11 @@ Returns an array reference containing all the asset ids of the assets that match sub getAssetIds { my $self = shift; - my $query = "select assetId from assetIndex where isPublic=? and (".$self->{_query}.")"; - my $rs = $self->session->db->prepare($self->{_query}); - $rs->execute([$self->{_isPublic},@{$self->{_params}}]); + my $query = "select assetId from assetIndex where "; + $query .= "isPublic=1 and " if ($self->{_isPublic}); + $query .= "(".$self->{_query}.")"; + my $rs = $self->session->db->prepare($query); + $rs->execute($self->{_params}); my @ids = (); while (my ($id) = $rs->array) { push(@ids, $id); @@ -69,9 +71,11 @@ Returns an array reference containing asset objects for those that matched. sub getAssets { my $self = shift; - my $query = "select assetId,className,revisionDate from assetIndex where isPublic=? and (".$self->{_query}.")"; - my $rs = $self->session->db->prepare($self->{_query}); - $rs->execute([$self->{_isPublic},@{$self->{_params}}]); + my $query = "select assetId,className,revisionDate from assetIndex where "; + $query .= "isPublic=1 and " if ($self->{_isPublic}); + $query .= "(".$self->{_query}.")"; + my $rs = $self->session->db->prepare($query); + $rs->execute($self->{_params}); my @assets; while (my ($id, $class, $version) = $rs->array) { push(@assets, WebGUI::Asset->new($id, $class, $version)); @@ -90,10 +94,11 @@ Returns a WebGUI::SQL::ResultSet object containing the search results with colum sub getResultSet { my $self = shift; - my $query = "select assetId, title, url, synopsis, ownerUserId, groupIdView, groupIdEdit, creationDate, revisionDate, className - from assetIndex where isPublic=? and (".$self->{_query}.")"; - my $rs = $self->session->db->prepare($self->{_query}); - $rs->execute([$self->{_isPublic},@{$self->{_params}}]); + my $query = "select assetId, title, url, synopsis, ownerUserId, groupIdView, groupIdEdit, creationDate, revisionDate, className from assetIndex where "; + $query .= "isPublic=1 and " if ($self->{_isPublic}); + $query .= "(".$self->{_query}.")"; + my $rs = $self->session->db->prepare($query); + $rs->execute($self->{_params}); return $rs; } diff --git a/lib/WebGUI/Search/Index.pm b/lib/WebGUI/Search/Index.pm index ca2de0cc5..4a76cf8ab 100644 --- a/lib/WebGUI/Search/Index.pm +++ b/lib/WebGUI/Search/Index.pm @@ -15,7 +15,6 @@ package WebGUI::Search::Index; =cut use strict; -use warnings; =head1 NAME @@ -113,7 +112,7 @@ sub create { my $description = WebGUI::HTML::filter($asset->get('description'), "all"); my $keywords = join(" ",$asset->get("title"), $asset->get("menuTitle"), $asset->get("synopsis"), $url, $description); my $add = $self->session->db->prepare("insert into assetIndex (assetId, title, url, creationDate, revisionDate, - ownerUserId, groupIdView, groupIdEdit, lineage, className, synopsis, keywords) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"); + ownerUserId, groupIdView, groupIdEdit, lineage, className, synopsis, keywords) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"); $add->execute([$asset->getId, $asset->get("title"), $asset->get("url"), $asset->get("creationDate"), $asset->get("revisionDate"), $asset->get("ownerUserId"), $asset->get("groupIdView"), $asset->get("groupIdEdit"), $asset->get("lineage"), $asset->get("className"), $asset->get("synopsis"), $keywords]); @@ -169,7 +168,7 @@ Sets the status of whether this asset will appear in public searches. =cut -sub isPublic { +sub setIsPublic { my $self = shift; my $boolean = shift; my $set = $self->session->db->prepare("update assetIndex set isPublic=? where assetId=?"); @@ -192,7 +191,7 @@ sub new { my $class = shift; my $asset = shift; my $self = {_asset=>$asset, _session=>$asset->session, _id=>$asset->getId}; - return $self; + bless $self; } diff --git a/sbin/search.pl b/sbin/search.pl new file mode 100644 index 000000000..6a5163a28 --- /dev/null +++ b/sbin/search.pl @@ -0,0 +1,106 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2006 Plain Black Corporation. +#------------------------------------------------------------------- +# 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 strict; +use lib '../lib'; +use Getopt::Long; +use WebGUI::Asset; +use WebGUI::Session; +use WebGUI::Search; +use WebGUI::Search::Index; +use Time::HiRes; + +$|=1; +my $search = ""; +my $help = 0; +my $indexsite = 0; +my $configFile = ""; + +GetOptions( + 'configFile=s'=>\$configFile, + 'search=s'=>\$search, + 'help'=>\$help, + 'indexsite'=>\$indexsite + ); + +if ($configFile) { + my $session = WebGUI::Session->open("..", $configFile); + if ($indexsite) { + reindexSite($session); + } elsif ($search) { + searchSite($session, $search); + } else { + displayHelp(); + } + $session->var->end; + $session->close; +} else { + displayHelp(); +} + +#------------------------------------------------------------------- +sub displayHelp { + print <db->read("select assetId, className from asset where state='published'"); + while (my ($id, $class) = $rs->array) { + my $asset = WebGUI::Asset->new($session,$id,$class); + if (defined $asset && $asset->get("status") eq "approved" || $asset->get("status") eq "archived") { + print $asset->getId."\t".$asset->getTitle."\t"; + my $t = [Time::HiRes::gettimeofday()]; + $asset->indexContent; + print "(".Time::HiRes::tv_interval($t).")\n"; + } + } + + print "\nSite indexing took ".Time::HiRes::tv_interval($siteTime)." seconds.\n"; +} + +#------------------------------------------------------------------- +sub searchSite { + my $session = shift; + my $keywords = shift; + my $t = [Time::HiRes::gettimeofday()]; + my $search = WebGUI::Search->new($session, 0); + $search->search("any",$keywords); + my $rs = $search->getResultSet; + while (my $data = $rs->hashRef) { + print $data->{assetId}."\t".$data->{title}."\n"; + } + print "\nSearch took ".Time::HiRes::tv_interval($t)." seconds.\n"; +} + +