2 # Copyright (C) 2002 Stanislav Sinyagin
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18 # $Id: buildsearchdb.in,v 1.1 2010-12-27 00:04:01 ivan Exp $
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
21 BEGIN { require '@torrus_config_pl@'; }
26 use Torrus::ConfigTree;
28 use Torrus::SiteConfig;
31 exit(1) if not Torrus::SiteConfig::verify();
40 my $ok = GetOptions ('tree=s' => \@trees,
42 'global' => \$build_global,
43 'verbose' => \$verbose,
44 'help' => \$help_needed);
46 if( not $ok or not (scalar(@trees) or $all_trees or $build_global) or
47 $help_needed or scalar(@ARGV) > 0 )
49 print STDERR "Usage: $0 --tree=NAME [options...]\n",
51 " --tree=NAME rebuild search DB for a tree\n",
52 " --all rebuild search DB for all trees\n",
53 " --global rebuild global search DB\n",
54 " --verbose print extra information\n",
55 " --help this help message\n";
66 @trees = Torrus::SiteConfig::listTreeNames();
71 Torrus::Log::setLevel('verbose');
74 &Torrus::DB::setSafeSignalHandlers();
76 Verbose(sprintf('Torrus version %s', '@VERSION@'));
78 my $search = new Torrus::Search( -WriteAccess => 1 );
82 $search->openGlobal();
85 foreach my $tree ( @trees )
87 if( not Torrus::SiteConfig::treeExists( $tree ) )
89 Error("Tree named \"" . $tree . "\" does not exist");
93 &Torrus::DB::checkInterrupted();
95 my $config_tree = new Torrus::ConfigTree( -TreeName => $tree );
96 if( not defined($config_tree) )
98 print("Configuration is not ready\n");
102 Verbose("Processing the tree: $tree");
104 $search->openTree( $tree );
106 walkSubtree( $config_tree, $search, $config_tree->token('/') );
108 $search->closeTree( $tree );
109 $config_tree = undef;
117 my $config_tree = shift;
121 my $tree = $config_tree->treeName();
123 foreach my $token ( $config_tree->getChildren( $ptoken ) )
125 &Torrus::DB::checkInterrupted();
127 if( $config_tree->isSubtree( $token ) )
129 walkSubtree( $config_tree, $search, $token );
133 $config_tree->getNodeParam( $token, 'searchable', 1 );
134 if( defined( $isSearchable ) and $isSearchable eq 'yes' )
136 my $path = $config_tree->path( $token );
138 my $nodeName = $config_tree->nodeName( $path );
139 splitAndStore( $tree, $nodeName, $path );
141 my $params = $config_tree->getParams( $token, 1 );
142 while( my( $param, $value ) = each %{$params} )
144 if( $config_tree->getParamProperty( $param, 'search' ) )
146 splitAndStore( $tree, $value, $path, $param );
161 if( length( $value ) > 0 )
163 # split the value into words
164 my @words = split( /\W+/ms, $value );
165 if( scalar( @words ) > 0 )
167 foreach my $word ( @words )
169 if( length( $word ) > 1 )
171 $search->storeKeyword( $tree, $word, $path, $param );
173 # Split the word by underscores and minus
174 my @subwords = split( /_+/, $word );
175 if( scalar( @subwords ) > 1 )
177 foreach my $subword ( @subwords )
179 if( length( $subword ) > 1 )
181 $search->storeKeyword( $tree,
198 # indent-tabs-mode: nil
199 # perl-indent-level: 4