/usr/bin/wg-search is in webgui 7.10.29-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | #!/usr/bin/perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 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 File::Basename ();
use File::Spec;
my $webguiRoot;
BEGIN {
$webguiRoot = '/usr/share/webgui';
unshift @INC, File::Spec->catdir($webguiRoot, 'lib');
}
foreach my $libDir ( readLines( "preload.custom" ) ) {
if ( !-d $libDir ) {
warn "WARNING: Not adding lib directory '$libDir' from preload.custom: Directory does not exist.\n";
next;
}
unshift @INC, $libDir;
}
use Getopt::Long;
use WebGUI::Asset;
use WebGUI::Config;
use WebGUI::Session;
use WebGUI::Search;
use WebGUI::Search::Index;
use Time::HiRes;
use Pod::Usage;
$|=1;
my $search = "";
my $help = 0;
my $indexsite = 0;
my $configFile = "";
my $indexAll = "";
my $updatesite = 0;
GetOptions(
'indexall'=>\$indexAll,
'configFile=s'=>\$configFile,
'search=s'=>\$search,
'help'=>\$help,
'indexsite'=>\$indexsite,
'updatesite'=>\$updatesite
);
pod2usage( verbose => 2 ) if $help;
if ($configFile) {
my $session = WebGUI::Session->open($webguiRoot, $configFile);
if ($indexsite) {
reindexSite($session);
} elsif ($updatesite) {
updateSite($session);
} elsif ($search) {
searchSite($session, $search);
} else {
pod2usage();
}
$session->var->end;
$session->close;
} elsif ($indexAll) {
reindexAllSites();
} else {
pod2usage();
}
#-------------------------------------------------------------------
sub reindexAllSites {
my $configs = WebGUI::Config->readAllConfigs($webguiRoot);
foreach my $site (keys %{$configs}) {
print "Indexing ".$site."...\n";
my $session = WebGUI::Session->open($webguiRoot,$site);
reindexSite($session);
$session->var->end;
$session->close;
print "Finished indexing ".$site.".\n";
}
}
#-------------------------------------------------------------------
sub reindexSite {
my $session = shift;
my $siteTime = [Time::HiRes::gettimeofday()];
my $rs = $session->db->read("select assetId, className from asset where state='published'");
my @searchableAssetIds;
while (my ($id, $class) = $rs->array) {
my $asset = WebGUI::Asset->new($session,$id,$class);
if ( !$asset ) {
warn sprintf "- Asset %s (%s) could not be instantiated\n", $id, $class;
next;
}
if ($asset->get("state") eq "published" && ($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";
push (@searchableAssetIds, $id);
}
}
# delete indexes of assets that are no longer searchable
my $list = $session->db->quoteAndJoin(\@searchableAssetIds) if scalar(@searchableAssetIds);
$session->db->write("delete from assetIndex where assetId not in (".$list.")") if $list;
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({keywords=>$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";
}
#-------------------------------------------------------------------
sub updateSite {
my $session = shift;
my $siteTime = [Time::HiRes::gettimeofday()];
my $rs = $session->db->read("select assetId, className from asset where state='published'");
my @searchableAssetIds;
while (my ($id, $class) = $rs->array) {
push(@searchableAssetIds, $id);
my ($done) = $session->db->quickArray("select count(*) from assetIndex where assetId=?",[$id]);
next if $done;
my $asset = WebGUI::Asset->new($session,$id,$class);
if (defined $asset && $asset->get("status") eq "approved" || defined $asset && $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";
}
}
# delete indexes of assets that are no longer searchable
my $list = $session->db->quoteAndJoin(\@searchableAssetIds) if scalar(@searchableAssetIds);
$session->db->write("delete from assetIndex where assetId not in (".$list.")") if $list;
print "\nSite indexing took ".Time::HiRes::tv_interval($siteTime)." seconds.\n";
}
#-------------------------------------------------
sub readLines {
my $file = shift;
my @lines;
if (open(my $fh, '<', $file)) {
while (my $line = <$fh>) {
$line =~ s/#.*//;
$line =~ s/^\s+//;
$line =~ s/\s+$//;
next if !$line;
push @lines, $line;
}
close $fh;
}
return @lines;
}
__END__
=head1 NAME
search - Reindex and search a WebGUI site.
=head1 SYNOPSIS
search --configFile config.conf --indexsite
search --configFile config.conf --updatesite
search --configFile config.conf --search text
search --indexall
search --help
=head1 DESCRIPTION
This WebGUI utility scripts helps maintaining search indexes on
any site. It can be used to build the index for an entire site,
build the index only for new content, and perform searches.
=over
=item B<--configFile config.conf>
The WebGUI config file to use. Only the file name needs to be specified,
since it will be looked up inside WebGUI's configuration directory.
This parameter is required.
=item B<--indexsite>
Reindexes the entire site specified in the config file. This process
may take a while (even hours) depending on the amount of content the
site has. Server performance will suffer somewhat during the
indexing process. This option requires a B<--configFile> to be
specified.
=item B<--updatesite>
Indexes content that has not be indexed for the site specified in
the config file, keeping the indexes for already indexed content
intact. This is useful if the B<--indexsite> had to be stopped
partway through. This option requires a B<--configFile> to be
specified.
=item B<--search text>
Searches the site specified in the config file for a given keyword or
phrase, returning the results. This option requires a B<--configFile>
to be specified.
=item B<--indexall>
Reindexes B<all> the sites. Note that this can take many hours and
will affect performance of the server during the indexing process.
=item B<--help>
Shows this documentation, then exits.
=back
=head1 AUTHOR
Copyright 2001-2009 Plain Black Corporation.
=cut
|