the search engine, it works!!!
This commit is contained in:
parent
66baa5cea2
commit
e33b3bb9b9
7 changed files with 135 additions and 16 deletions
|
|
@ -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
|
||||
--------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ my $session = start(); # this line required
|
|||
|
||||
templateParsers();
|
||||
removeFiles();
|
||||
addSearchEngine();
|
||||
|
||||
finish($session); # this line required
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
106
sbin/search.pl
Normal file
106
sbin/search.pl
Normal file
|
|
@ -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 <<STOP;
|
||||
perl $0 [ options ]
|
||||
|
||||
Options:
|
||||
|
||||
--configFile= The config file of the site you wish to perform
|
||||
an action on.
|
||||
|
||||
--help Displays this message.
|
||||
|
||||
--indexsite * Reindexes the entire site. Note that depending
|
||||
upon the amount of content you have, it may take
|
||||
hours to index a site and server performance will
|
||||
suffer somewhat during the indexing process.
|
||||
|
||||
--search= * Searches the site for a keyword or phrase and
|
||||
returns the results.
|
||||
|
||||
* This option requires the --configFile option.
|
||||
|
||||
STOP
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub reindexSite {
|
||||
my $session = shift;
|
||||
my $siteTime = [Time::HiRes::gettimeofday()];
|
||||
my $rs = $session->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";
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue