[932] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[1852] | 3 | # mgppbuilder.pm -- MGBuilder object
|
---|
[932] | 4 | # A component of the Greenstone digital library software
|
---|
| 5 | # from the New Zealand Digital Library Project at the
|
---|
| 6 | # University of Waikato, New Zealand.
|
---|
| 7 | #
|
---|
| 8 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 9 | #
|
---|
| 10 | # This program is free software; you can redistribute it and/or modify
|
---|
| 11 | # it under the terms of the GNU General Public License as published by
|
---|
| 12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | # (at your option) any later version.
|
---|
| 14 | #
|
---|
| 15 | # This program is distributed in the hope that it will be useful,
|
---|
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | # GNU General Public License for more details.
|
---|
| 19 | #
|
---|
| 20 | # You should have received a copy of the GNU General Public License
|
---|
| 21 | # along with this program; if not, write to the Free Software
|
---|
| 22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | #
|
---|
| 24 | ###########################################################################
|
---|
| 25 |
|
---|
| 26 | package mgppbuilder;
|
---|
| 27 |
|
---|
[10468] | 28 | use basebuilder;
|
---|
[932] | 29 | use classify;
|
---|
| 30 | use cfgread;
|
---|
| 31 | use colcfg;
|
---|
| 32 | use plugin;
|
---|
| 33 | use util;
|
---|
[1694] | 34 | use FileHandle;
|
---|
[932] | 35 |
|
---|
[10468] | 36 | sub BEGIN {
|
---|
| 37 | @mgppbuilder::ISA = ('basebuilder');
|
---|
[1694] | 38 | }
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 |
|
---|
[9157] | 42 | our %level_map = ('document'=>'Doc',
|
---|
[4811] | 43 | 'section'=>'Sec',
|
---|
| 44 | 'paragraph'=>'Para',
|
---|
| 45 | 'Doc'=>'_textdocument_',
|
---|
| 46 | 'Sec'=>'_textsection_',
|
---|
| 47 | 'Para'=>'_textparagraph_');
|
---|
[1852] | 48 |
|
---|
[4811] | 49 | #$doc_level = "Doc";
|
---|
| 50 | #$sec_level = "Sec";
|
---|
| 51 | #$para_level = "Para";
|
---|
| 52 |
|
---|
[9157] | 53 | our %wanted_index_files = ('td'=>1,
|
---|
[932] | 54 | 't'=>1,
|
---|
[1852] | 55 | 'tl'=>1,
|
---|
| 56 | 'ti'=>1,
|
---|
[932] | 57 | 'idb'=>1,
|
---|
| 58 | 'ib1'=>1,
|
---|
| 59 | 'ib2'=>1,
|
---|
| 60 | 'ib3'=>1,
|
---|
| 61 | 'i'=>1,
|
---|
[1852] | 62 | 'il'=>1,
|
---|
| 63 | 'w'=>1,
|
---|
[932] | 64 | 'wa'=>1);
|
---|
| 65 |
|
---|
[1852] | 66 | # change this so a user can add their own ones in via a file or cfg
|
---|
[4768] | 67 | #add AND, OR, NOT NEAR to this list - these cannot be used as field names
|
---|
[4811] | 68 | #also add the level names (Doc, Sec, Para)
|
---|
[9157] | 69 | our %static_indexfield_map = ('Title'=>'TI',
|
---|
[1852] | 70 | 'TI'=>1,
|
---|
| 71 | 'Subject'=>'SU',
|
---|
| 72 | 'SU'=>1,
|
---|
| 73 | 'Creator'=>'CR',
|
---|
| 74 | 'CR'=>1,
|
---|
[4768] | 75 | 'Organization'=>'ORG',
|
---|
| 76 | 'ORG'=>1,
|
---|
[1852] | 77 | 'Source'=>'SO',
|
---|
| 78 | 'SO'=>1,
|
---|
| 79 | 'Howto'=>'HT',
|
---|
| 80 | 'HT'=>1,
|
---|
| 81 | 'ItemTitle'=>'IT',
|
---|
| 82 | 'IT'=>1,
|
---|
| 83 | 'ProgNumber'=>'PN',
|
---|
| 84 | 'PN'=>1,
|
---|
| 85 | 'People'=>'PE',
|
---|
| 86 | 'PE'=>1,
|
---|
[5643] | 87 | 'Coverage'=>'CO',
|
---|
| 88 | 'CO'=>1,
|
---|
[4794] | 89 | 'allfields'=>'ZZ',
|
---|
[4768] | 90 | 'ZZ'=>1,
|
---|
[4794] | 91 | 'text'=>'TX',
|
---|
[4768] | 92 | 'TX'=>1,
|
---|
| 93 | 'AND'=>1,
|
---|
| 94 | 'OR'=>1,
|
---|
| 95 | 'NOT'=>1,
|
---|
[4811] | 96 | 'NEAR'=>1,
|
---|
| 97 | 'Doc'=>1,
|
---|
| 98 | 'Sec'=>1,
|
---|
| 99 | 'Para'=>1);
|
---|
[932] | 100 |
|
---|
[10468] | 101 | my $maxdocsize = $basebuilder::maxdocsize;
|
---|
| 102 |
|
---|
[932] | 103 | sub new {
|
---|
[7953] | 104 | my $class = shift(@_);
|
---|
| 105 |
|
---|
| 106 | my ($collection, $source_dir, $build_dir, $verbosity,
|
---|
[8361] | 107 | $maxdocs, $debug, $keepold, $remove_empty_classifications,
|
---|
[8716] | 108 | $outhandle, $no_text, $failhandle, $gli) = @_;
|
---|
[932] | 109 |
|
---|
[10468] | 110 | my $self = new basebuilder (@_);
|
---|
| 111 | $self = bless $self, $class;
|
---|
[932] | 112 |
|
---|
[10468] | 113 | $self->{'indexfieldmap'} = \%static_indexfield_map;
|
---|
[6407] | 114 |
|
---|
[1852] | 115 | # get the levels (Section, Paragraph) for indexing and compression
|
---|
| 116 | $self->{'levels'} = {};
|
---|
[4811] | 117 | $self->{'levelorder'} = ();
|
---|
[1852] | 118 | if (defined $self->{'collect_cfg'}->{'levels'}) {
|
---|
[8716] | 119 | foreach my $level ( @{$self->{'collect_cfg'}->{'levels'}} ){
|
---|
[4811] | 120 | $level =~ tr/A-Z/a-z/;
|
---|
[1852] | 121 | $self->{'levels'}->{$level} = 1;
|
---|
[4811] | 122 | push (@{$self->{'levelorder'}}, $level);
|
---|
[1852] | 123 | }
|
---|
[4811] | 124 | } else { # default to document
|
---|
| 125 | $self->{'levels'}->{'document'} = 1;
|
---|
| 126 | push (@{$self->{'levelorder'}}, 'document');
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | $self->{'doc_level'} = "document";
|
---|
| 130 | if (! $self->{'levels'}->{'document'}) {
|
---|
| 131 | if ($self->{'levels'}->{'section'}) {
|
---|
| 132 | $self->{'doc_level'} = "section";
|
---|
| 133 | } else {
|
---|
| 134 | die "you must have either document or section level specified!!\n";
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
[9919] | 137 |
|
---|
[7953] | 138 | $self->{'buildtype'} = "mgpp";
|
---|
[932] | 139 |
|
---|
| 140 | return $self;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[10468] | 143 | sub generate_index_list {
|
---|
| 144 | my $self = shift (@_);
|
---|
| 145 |
|
---|
| 146 | # sort out the indexes
|
---|
| 147 | #indexes are specified with spaces, but we put them into one index
|
---|
| 148 | my $indexes = $self->{'collect_cfg'}->{'indexes'};
|
---|
| 149 | $self->{'collect_cfg'}->{'indexes'} = [];
|
---|
| 150 | push (@{$self->{'collect_cfg'}->{'indexes'}}, join(',', @$indexes));
|
---|
[932] | 151 | }
|
---|
| 152 |
|
---|
[10468] | 153 | sub default_buildproc {
|
---|
| 154 | my $self = shift (@_);
|
---|
| 155 |
|
---|
| 156 | return "mgppbuildproc";
|
---|
[932] | 157 | }
|
---|
| 158 |
|
---|
| 159 | sub compress_text {
|
---|
| 160 |
|
---|
| 161 | my $self = shift (@_);
|
---|
| 162 | my ($textindex) = @_;
|
---|
| 163 |
|
---|
[2478] | 164 | my $exedir = "$ENV{'GSDLHOME'}/bin/$ENV{'GSDLOS'}";
|
---|
[932] | 165 | my $exe = &util::get_os_exe ();
|
---|
[2478] | 166 | my $mgpp_passes_exe = &util::filename_cat($exedir, "mgpp_passes$exe");
|
---|
| 167 | my $mgpp_compression_dict_exe = &util::filename_cat($exedir, "mgpp_compression_dict$exe");
|
---|
[1694] | 168 | my $outhandle = $self->{'outhandle'};
|
---|
[932] | 169 |
|
---|
| 170 | &util::mk_all_dir (&util::filename_cat($self->{'build_dir'}, "text"));
|
---|
| 171 |
|
---|
| 172 | my $basefilename = "text/$self->{'collection'}";
|
---|
[2700] | 173 | my $fulltextprefix = &util::filename_cat ($self->{'build_dir'}, $basefilename);
|
---|
[7904] | 174 |
|
---|
[2700] | 175 | my $osextra = "";
|
---|
[2478] | 176 | if ($ENV{'GSDLOS'} =~ /^windows$/i) {
|
---|
[3115] | 177 | $fulltextprefix =~ s@/@\\@g;
|
---|
[2478] | 178 | }
|
---|
[2700] | 179 | else {
|
---|
| 180 | $osextra = " -d /";
|
---|
| 181 | }
|
---|
[1852] | 182 |
|
---|
| 183 |
|
---|
[4811] | 184 | # define the section names and possibly the doc name for mgpasses
|
---|
[1852] | 185 | # the compressor doesn't need to know about paragraphs - never want to
|
---|
| 186 | # retrieve them
|
---|
[2478] | 187 | my $mgpp_passes_sections = "";
|
---|
[4811] | 188 | my ($doc_level) = $self->{'doc_level'};
|
---|
[7090] | 189 | $mgpp_passes_sections .= "-J " . $level_map{$doc_level} . " ";
|
---|
[8716] | 190 | foreach my $level (keys %{$self->{'levels'}}) {
|
---|
[4811] | 191 | if ($level ne $doc_level && $level ne "paragraph") {
|
---|
[7090] | 192 | $mgpp_passes_sections .= "-K " . $level_map{$level} . " ";
|
---|
[4811] | 193 | }
|
---|
[1852] | 194 | }
|
---|
[9853] | 195 | $mgpp_passes_sections .= "-K SENT ";
|
---|
[1694] | 196 | print $outhandle "\n*** creating the compressed text\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 197 | print STDERR "<Stage name='CompressText'>\n" if $self->{'gli'};
|
---|
[932] | 198 |
|
---|
| 199 | # collect the statistics for the text
|
---|
[1694] | 200 | # -b $maxdocsize sets the maximum document size to be 12 meg
|
---|
[2478] | 201 | print $outhandle "\n collecting text statistics (mgpp_passes -T1)\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 202 | print STDERR "<Phase name='CollectTextStats'/>\n" if $self->{'gli'};
|
---|
[932] | 203 |
|
---|
| 204 | my ($handle);
|
---|
| 205 | if ($self->{'debug'}) {
|
---|
| 206 | $handle = STDOUT;
|
---|
| 207 | } else {
|
---|
[5077] | 208 | #print $outhandle "trying to run (compress 1) mgpp_passes$exe $mgpp_passes_sections -f \"$fulltextprefix\" -T1 $osextra\n";
|
---|
[2478] | 209 | if (!-e "$mgpp_passes_exe" ||
|
---|
[2700] | 210 | !open (PIPEOUT, "| mgpp_passes$exe $mgpp_passes_sections -f \"$fulltextprefix\" -T1 $osextra")) {
|
---|
[6407] | 211 | print STDERR "<FatalError name='NoRunMGPasses'>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 212 | die "mgppbuilder::compress_text - couldn't run $mgpp_passes_exe\n";
|
---|
[932] | 213 | }
|
---|
| 214 | $handle = mgppbuilder::PIPEOUT;
|
---|
| 215 | }
|
---|
[9919] | 216 |
|
---|
| 217 | # gdbm_level
|
---|
| 218 | my $gdbm_level = "document";
|
---|
| 219 | if ($self->{'levels'}->{'section'}) {
|
---|
| 220 | $gdbm_level = "section";
|
---|
| 221 | }
|
---|
| 222 |
|
---|
[932] | 223 | $self->{'buildproc'}->set_output_handle ($handle);
|
---|
| 224 | $self->{'buildproc'}->set_mode ('text');
|
---|
| 225 | $self->{'buildproc'}->set_index ($textindex);
|
---|
| 226 | $self->{'buildproc'}->set_indexing_text (0);
|
---|
[2478] | 227 | if ($self->{'no_text'}) {
|
---|
| 228 | $self->{'buildproc'}->set_store_text(0);
|
---|
| 229 | } else {
|
---|
| 230 | $self->{'buildproc'}->set_store_text(1);
|
---|
| 231 | }
|
---|
[1852] | 232 | $self->{'buildproc'}->set_indexfieldmap ($self->{'indexfieldmap'});
|
---|
| 233 | $self->{'buildproc'}->set_levels ($self->{'levels'});
|
---|
[9919] | 234 | $self->{'buildproc'}->set_gdbm_level ($gdbm_level);
|
---|
[932] | 235 | $self->{'buildproc'}->reset();
|
---|
| 236 | &plugin::begin($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
| 237 | $self->{'buildproc'}, $self->{'maxdocs'});
|
---|
| 238 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[9853] | 239 | "", {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
|
---|
[932] | 240 | &plugin::end($self->{'pluginfo'});
|
---|
| 241 | close (PIPEOUT);
|
---|
| 242 |
|
---|
| 243 | close ($handle) unless $self->{'debug'};
|
---|
| 244 |
|
---|
[2478] | 245 | $self->print_stats();
|
---|
| 246 |
|
---|
[932] | 247 | # create the compression dictionary
|
---|
| 248 | # the compression dictionary is built by assuming the stats are from a seed
|
---|
| 249 | # dictionary (-S), if a novel word is encountered it is spelled out (-H),
|
---|
| 250 | # and the resulting dictionary must be less than 5 meg with the most
|
---|
| 251 | # frequent words being put into the dictionary first (-2 -k 5120)
|
---|
[1852] | 252 | # note: these options are left over from mg version
|
---|
[932] | 253 | if (!$self->{'debug'}) {
|
---|
[1694] | 254 | print $outhandle "\n creating the compression dictionary\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 255 | print STDERR "<Phase name='CreatingCompress'/>\n" if $self->{'gli'};
|
---|
[2478] | 256 | if (!-e "$mgpp_compression_dict_exe") {
|
---|
[6407] | 257 | print STDERR "<FatalError name='NoRunMGCompress'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 258 | die "mgppbuilder::compress_text - couldn't run $mgpp_compression_dict_exe\n";
|
---|
[932] | 259 | }
|
---|
[2700] | 260 | system ("mgpp_compression_dict$exe -f \"$fulltextprefix\" -S -H -2 -k 5120 $osextra");
|
---|
[932] | 261 |
|
---|
| 262 | if (!$self->{'debug'}) {
|
---|
[5077] | 263 | #print $outhandle "trying to run (compress 2) mgpp_passes$exe $mgpp_passes_sections -f \"$fulltextprefix\" -T2 $osextra\n";
|
---|
[2478] | 264 | if (!-e "$mgpp_passes_exe" ||
|
---|
[2700] | 265 | !open ($handle, "| mgpp_passes$exe $mgpp_passes_sections -f \"$fulltextprefix\" -T2 $osextra")) {
|
---|
[6407] | 266 | print STDERR "<FatalError name='NoRunMGPasses'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 267 | die "mgppbuilder::compress_text - couldn't run $mgpp_passes_exe\n";
|
---|
[932] | 268 | }
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
[6407] | 271 | else {
|
---|
| 272 | print STDERR "<Phase name='SkipCreatingComp'/>\n" if $self->{'gli'};
|
---|
| 273 | }
|
---|
[932] | 274 |
|
---|
| 275 | $self->{'buildproc'}->reset();
|
---|
| 276 | # compress the text
|
---|
[2478] | 277 | print $outhandle "\n compressing the text (mgpp_passes -T2)\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 278 | print STDERR "<Phase name='CompressingText'/>\n" if $self->{'gli'};
|
---|
| 279 |
|
---|
[932] | 280 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[9853] | 281 | "", {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
|
---|
[932] | 282 | close ($handle) unless $self->{'debug'};
|
---|
[1694] | 283 |
|
---|
| 284 | $self->print_stats();
|
---|
[6407] | 285 | print STDERR "</Stage>\n" if $self->{'gli'};
|
---|
[932] | 286 | }
|
---|
| 287 |
|
---|
| 288 |
|
---|
[10468] | 289 | sub build_indexes_extra {
|
---|
| 290 | my $self = shift(@_);
|
---|
[5617] | 291 | #define the final field lists
|
---|
| 292 | $self->make_final_field_list();
|
---|
[10468] | 293 | }
|
---|
[5617] | 294 |
|
---|
[932] | 295 | # creates directory names for each of the index descriptions
|
---|
| 296 | sub create_index_mapping {
|
---|
| 297 | my $self = shift (@_);
|
---|
| 298 | my ($indexes) = @_;
|
---|
| 299 |
|
---|
| 300 | my %mapping = ();
|
---|
[5935] | 301 |
|
---|
[932] | 302 | $mapping{'indexmaporder'} = [];
|
---|
| 303 | $mapping{'subcollectionmaporder'} = [];
|
---|
| 304 | $mapping{'languagemaporder'} = [];
|
---|
| 305 |
|
---|
| 306 | # dirnames is used to check for collisions. Start this off
|
---|
| 307 | # with the manditory directory names
|
---|
| 308 | my %dirnames = ('text'=>'text',
|
---|
| 309 | 'extra'=>'extra');
|
---|
[8716] | 310 | my %pnames = ('index' => {}, 'subcollection' => {}, 'languages' => {});
|
---|
[932] | 311 |
|
---|
[8716] | 312 | foreach my $index (@$indexes) {
|
---|
[932] | 313 | my ($fields, $subcollection, $languages) = split (":", $index);
|
---|
| 314 | # the directory name starts with a processed version of index fields
|
---|
[4768] | 315 | #my ($pindex) = $self->process_field($fields);
|
---|
| 316 | #$pindex = lc ($pindex);
|
---|
| 317 | # now we only ever have one index, and its called 'idx'
|
---|
[8716] | 318 | my $pindex = 'idx';
|
---|
[4768] | 319 |
|
---|
[932] | 320 | # next comes a processed version of the subcollection if there is one.
|
---|
| 321 | my $psub = $self->process_field ($subcollection);
|
---|
| 322 | $psub = lc ($psub);
|
---|
| 323 |
|
---|
| 324 | # next comes a processed version of the language if there is one.
|
---|
| 325 | my $plang = $self->process_field ($languages);
|
---|
| 326 | $plang = lc ($plang);
|
---|
| 327 |
|
---|
| 328 | my $dirname = $pindex . $psub . $plang;
|
---|
| 329 |
|
---|
| 330 | # check to be sure all index names are unique
|
---|
| 331 | while (defined ($dirnames{$dirname})) {
|
---|
| 332 | $dirname = $self->make_unique (\%pnames, $index, \$pindex, \$psub, \$plang);
|
---|
| 333 | }
|
---|
| 334 |
|
---|
[2478] | 335 | $mapping{$index} = $dirname;
|
---|
| 336 |
|
---|
[932] | 337 | # store the mapping orders as well as the maps
|
---|
[2478] | 338 | # also put index, subcollection and language fields into the mapping thing -
|
---|
[4794] | 339 | # (the full index name (eg text:subcol:lang) is not used on
|
---|
[2478] | 340 | # the query page) -these are used for collectionmeta later on
|
---|
[932] | 341 | if (!defined $mapping{'indexmap'}{"$fields"}) {
|
---|
| 342 | $mapping{'indexmap'}{"$fields"} = $pindex;
|
---|
| 343 | push (@{$mapping{'indexmaporder'}}, "$fields");
|
---|
[2478] | 344 | if (!defined $mapping{"$fields"}) {
|
---|
| 345 | $mapping{"$fields"} = $pindex;
|
---|
| 346 | }
|
---|
[932] | 347 | }
|
---|
| 348 | if ($psub =~ /\w/ && !defined ($mapping{'subcollectionmap'}{$subcollection})) {
|
---|
| 349 | $mapping{'subcollectionmap'}{$subcollection} = $psub;
|
---|
| 350 | push (@{$mapping{'subcollectionmaporder'}}, $subcollection);
|
---|
[2478] | 351 | $mapping{$subcollection} = $psub;
|
---|
[932] | 352 | }
|
---|
| 353 | if ($plang =~ /\w/ && !defined ($mapping{'languagemap'}{$languages})) {
|
---|
| 354 | $mapping{'languagemap'}{$languages} = $plang;
|
---|
[6544] | 355 | push (@{$mapping{'languagemaporder'}}, $languages);
|
---|
[2478] | 356 | $mapping{$languages} = $plang;
|
---|
[932] | 357 | }
|
---|
| 358 | $dirnames{$dirname} = $index;
|
---|
[8716] | 359 | $pnames{'index'}->{$pindex} = "$fields";
|
---|
| 360 | $pnames{'subcollection'}->{$psub} = $subcollection;
|
---|
| 361 | $pnames{'languages'}->{$plang} = $languages;
|
---|
[932] | 362 | }
|
---|
| 363 |
|
---|
| 364 | return \%mapping;
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | sub make_unique {
|
---|
| 368 | my $self = shift (@_);
|
---|
| 369 | my ($namehash, $index, $indexref, $subref, $langref) = @_;
|
---|
| 370 | my ($fields, $subcollection, $languages) = split (":", $index);
|
---|
| 371 |
|
---|
| 372 | if ($namehash->{'index'}->{$$indexref} ne "$fields") {
|
---|
| 373 | $self->get_next_version ($indexref);
|
---|
| 374 | } elsif ($namehash->{'subcollection'}->{$$subref} ne $subcollection) {
|
---|
| 375 | $self->get_next_version ($subref);
|
---|
| 376 | } elsif ($namehash->{'languages'}->{$$langref} ne $languages) {
|
---|
| 377 | $self->get_next_version ($langref);
|
---|
| 378 | }
|
---|
| 379 | return "$$indexref$$subref$$langref";
|
---|
| 380 | }
|
---|
| 381 |
|
---|
| 382 |
|
---|
| 383 | sub build_index {
|
---|
| 384 | my $self = shift (@_);
|
---|
| 385 | my ($index) = @_;
|
---|
[1694] | 386 | my $outhandle = $self->{'outhandle'};
|
---|
[932] | 387 |
|
---|
| 388 | # get the full index directory path and make sure it exists
|
---|
| 389 | my $indexdir = $self->{'index_mapping'}->{$index};
|
---|
| 390 | &util::mk_all_dir (&util::filename_cat($self->{'build_dir'}, $indexdir));
|
---|
[2700] | 391 | my $fullindexprefix = &util::filename_cat ($self->{'build_dir'},
|
---|
| 392 | $indexdir,
|
---|
[932] | 393 | $self->{'collection'});
|
---|
[2700] | 394 | my $fulltextprefix = &util::filename_cat ($self->{'build_dir'}, "text",
|
---|
| 395 | $self->{'collection'});
|
---|
[932] | 396 |
|
---|
| 397 | # get any os specific stuff
|
---|
[2478] | 398 | my $exedir = "$ENV{'GSDLHOME'}/bin/$ENV{'GSDLOS'}";
|
---|
[932] | 399 |
|
---|
| 400 | my $exe = &util::get_os_exe ();
|
---|
[2478] | 401 | my $mgpp_passes_exe = &util::filename_cat($exedir, "mgpp_passes$exe");
|
---|
[1852] | 402 |
|
---|
| 403 | # define the section names for mgpasses
|
---|
[4811] | 404 | # define the section names and possibly the doc name for mgpasses
|
---|
[2478] | 405 | my $mgpp_passes_sections = "";
|
---|
[4811] | 406 | my ($doc_level) = $self->{'doc_level'};
|
---|
[7090] | 407 | $mgpp_passes_sections .= "-J " . $level_map{$doc_level} ." ";
|
---|
[4811] | 408 |
|
---|
[8716] | 409 | foreach my $level (keys %{$self->{'levels'}}) {
|
---|
[4811] | 410 | if ($level ne $doc_level) {
|
---|
[7090] | 411 | $mgpp_passes_sections .= "-K " . $level_map{$level}. " ";
|
---|
[1852] | 412 | }
|
---|
| 413 | }
|
---|
| 414 |
|
---|
[2478] | 415 | my $mgpp_perf_hash_build_exe =
|
---|
| 416 | &util::filename_cat($exedir, "mgpp_perf_hash_build$exe");
|
---|
| 417 | my $mgpp_weights_build_exe =
|
---|
| 418 | &util::filename_cat ($exedir, "mgpp_weights_build$exe");
|
---|
| 419 | my $mgpp_invf_dict_exe =
|
---|
| 420 | &util::filename_cat ($exedir, "mgpp_invf_dict$exe");
|
---|
| 421 | my $mgpp_stem_idx_exe =
|
---|
| 422 | &util::filename_cat ($exedir, "mgpp_stem_idx$exe");
|
---|
[932] | 423 |
|
---|
[2700] | 424 | my $osextra = "";
|
---|
| 425 | if ($ENV{'GSDLOS'} =~ /^windows$/i) {
|
---|
[3115] | 426 | $fullindexprefix =~ s@/@\\@g;
|
---|
[2700] | 427 | } else {
|
---|
| 428 | $osextra = " -d /";
|
---|
[3115] | 429 | if ($outhandle ne "STDERR") {
|
---|
| 430 | # so mgpp_passes doesn't print to stderr if we redirect output
|
---|
| 431 | $osextra .= " 2>/dev/null";
|
---|
| 432 | }
|
---|
[2478] | 433 | }
|
---|
[2700] | 434 |
|
---|
[932] | 435 | # get the index expression if this index belongs
|
---|
| 436 | # to a subcollection
|
---|
| 437 | my $indexexparr = [];
|
---|
[9669] | 438 | my $langarr = [];
|
---|
[2478] | 439 | # there may be subcollection info, and language info.
|
---|
| 440 | my ($fields, $subcollection, $language) = split (":", $index);
|
---|
[932] | 441 | my @subcollections = ();
|
---|
| 442 | @subcollections = split /,/, $subcollection if (defined $subcollection);
|
---|
| 443 |
|
---|
| 444 | foreach $subcollection (@subcollections) {
|
---|
| 445 | if (defined ($self->{'collect_cfg'}->{'subcollection'}->{$subcollection})) {
|
---|
| 446 | push (@$indexexparr, $self->{'collect_cfg'}->{'subcollection'}->{$subcollection});
|
---|
| 447 | }
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | # add expressions for languages if this index belongs to
|
---|
[2478] | 451 | # a language subcollection - only put languages expressions for the
|
---|
| 452 | # ones we want in the index
|
---|
[6544] | 453 |
|
---|
[2478] | 454 | my @languages = ();
|
---|
[9548] | 455 | my $language_metadata = "Language";
|
---|
| 456 | if (defined ($self->{'collect_cfg'}->{'language_metadata'})) {
|
---|
| 457 | $language_metadata = $self->{'collect_cfg'}->{'language_metadata'};
|
---|
| 458 | }
|
---|
[2478] | 459 | @languages = split /,/, $language if (defined $language);
|
---|
[9548] | 460 | foreach my $language (@languages) {
|
---|
[2478] | 461 | my $not=0;
|
---|
[932] | 462 | if ($language =~ s/^\!//) {
|
---|
[2478] | 463 | $not = 1;
|
---|
[932] | 464 | }
|
---|
[9548] | 465 | if($not) {
|
---|
[9669] | 466 | push (@$langarr, "!$language");
|
---|
[6544] | 467 | } else {
|
---|
[9669] | 468 | push (@$langarr, "$language");
|
---|
[2478] | 469 | }
|
---|
[932] | 470 | }
|
---|
| 471 |
|
---|
| 472 | # Build index dictionary. Uses verbatim stem method
|
---|
[2478] | 473 | print $outhandle "\n creating index dictionary (mgpp_passes -I1)\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 474 | print STDERR "<Phase name='CreatingIndexDic'/>\n" if $self->{'gli'};
|
---|
[932] | 475 | my ($handle);
|
---|
| 476 | if ($self->{'debug'}) {
|
---|
| 477 | $handle = STDOUT;
|
---|
| 478 | } else {
|
---|
[2478] | 479 | if (!-e "$mgpp_passes_exe" ||
|
---|
[2700] | 480 | !open (PIPEOUT, "| mgpp_passes$exe $mgpp_passes_sections -f \"$fullindexprefix\" -I1 $osextra")) {
|
---|
[6407] | 481 | print STDERR "<FatalError name='NoRunMGPasses'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 482 | die "mgppbuilder::build_index - couldn't run $mgpp_passes_exe\n";
|
---|
[932] | 483 | }
|
---|
| 484 | $handle = mgppbuilder::PIPEOUT;
|
---|
| 485 | }
|
---|
[9919] | 486 |
|
---|
| 487 | # gdbm_level
|
---|
| 488 | my $gdbm_level = "document";
|
---|
| 489 | if ($self->{'levels'}->{'section'}) {
|
---|
| 490 | $gdbm_level = "section";
|
---|
| 491 | }
|
---|
| 492 |
|
---|
[4794] | 493 | # set up the document processr
|
---|
[932] | 494 | $self->{'buildproc'}->set_output_handle ($handle);
|
---|
| 495 | $self->{'buildproc'}->set_mode ('text');
|
---|
| 496 | $self->{'buildproc'}->set_index ($index, $indexexparr);
|
---|
[9669] | 497 | $self->{'buildproc'}->set_index_languages ($language_metadata, $langarr) if (defined $language);
|
---|
[932] | 498 | $self->{'buildproc'}->set_indexing_text (1);
|
---|
[2478] | 499 | $self->{'buildproc'}->set_store_text(1);
|
---|
[1852] | 500 | $self->{'buildproc'}->set_indexfieldmap ($self->{'indexfieldmap'});
|
---|
[9919] | 501 | $self->{'buildproc'}->set_levels ($self->{'levels'});
|
---|
| 502 | $self->{'buildproc'}->set_gdbm_level ($gdbm_level);
|
---|
| 503 |
|
---|
[932] | 504 | $self->{'buildproc'}->reset();
|
---|
| 505 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[9853] | 506 | "", {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
|
---|
[932] | 507 | close ($handle) unless $self->{'debug'};
|
---|
| 508 |
|
---|
[1694] | 509 | $self->print_stats();
|
---|
| 510 |
|
---|
[5768] | 511 | # now we check to see if the required files have been produced - if not we quit building this index so the whole process doesn't crap out.
|
---|
| 512 | # we check on the .id file - index dictionary
|
---|
| 513 | my $dict_file = "$fullindexprefix.id";
|
---|
| 514 | if (!-e $dict_file) {
|
---|
| 515 | print $outhandle "mgppbuilder::build_index - Couldn't create index $index\n";
|
---|
[6407] | 516 | print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[5768] | 517 | $self->{'notbuilt'}->{$index}=1;
|
---|
| 518 | return;
|
---|
| 519 | }
|
---|
| 520 |
|
---|
[932] | 521 | if (!$self->{'debug'}) {
|
---|
| 522 | # create the perfect hash function
|
---|
[2478] | 523 | if (!-e "$mgpp_perf_hash_build_exe") {
|
---|
[6407] | 524 | print STDERR "<FatalError name='NoRunMGHash'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 525 | die "mgppbuilder::build_index - couldn't run $mgpp_perf_hash_build_exe\n";
|
---|
[932] | 526 | }
|
---|
[2700] | 527 | system ("mgpp_perf_hash_build$exe -f \"$fullindexprefix\" $osextra");
|
---|
[932] | 528 |
|
---|
[2478] | 529 | if (!-e "$mgpp_passes_exe" ||
|
---|
[2700] | 530 | !open ($handle, "| mgpp_passes$exe $mgpp_passes_sections -f \"$fullindexprefix\" -I2 $osextra")) {
|
---|
[6407] | 531 | print STDERR "<FatalError name='NoRunMGPasses'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 532 | die "mgppbuilder::build_index - couldn't run $mgpp_passes_exe\n";
|
---|
[932] | 533 | }
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | # invert the text
|
---|
[2478] | 537 | print $outhandle "\n inverting the text (mgpp_passes -I2)\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 538 | print STDERR "<Phase name='InvertingText'/>\n" if $self->{'gli'};
|
---|
[932] | 539 | $self->{'buildproc'}->reset();
|
---|
| 540 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[9853] | 541 | "", {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
|
---|
[1694] | 542 |
|
---|
| 543 | $self->print_stats ();
|
---|
[932] | 544 |
|
---|
| 545 | if (!$self->{'debug'}) {
|
---|
| 546 |
|
---|
| 547 | close ($handle);
|
---|
| 548 |
|
---|
| 549 | # create the weights file
|
---|
[1694] | 550 | print $outhandle "\n create the weights file\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 551 | print STDERR "<Phase name='CreateTheWeights'/>\n" if $self->{'gli'};
|
---|
[2478] | 552 | if (!-e "$mgpp_weights_build_exe") {
|
---|
[6407] | 553 | print STDERR "<FatalError name='NoRunMGWeights'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 554 | die "mgppbuilder::build_index - couldn't run $mgpp_weights_build_exe\n";
|
---|
[932] | 555 | }
|
---|
[2700] | 556 | system ("mgpp_weights_build$exe -f \"$fullindexprefix\" $osextra");
|
---|
[932] | 557 |
|
---|
| 558 | # create 'on-disk' stemmed dictionary
|
---|
[1694] | 559 | print $outhandle "\n creating 'on-disk' stemmed dictionary\n" if ($self->{'verbosity'} >= 1);
|
---|
[2478] | 560 | if (!-e "$mgpp_invf_dict_exe") {
|
---|
[6407] | 561 | print STDERR "<FatalError name='NoRunMGInvf'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 562 | die "mgppbuilder::build_index - couldn't run $mgpp_invf_dict_exe\n";
|
---|
[932] | 563 | }
|
---|
[2700] | 564 | system ("mgpp_invf_dict$exe -f \"$fullindexprefix\" $osextra" );
|
---|
[932] | 565 |
|
---|
| 566 |
|
---|
| 567 | # creates stem index files for the various stemming methods
|
---|
[1694] | 568 | print $outhandle "\n creating stem indexes\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 569 | print STDERR "<Phase name='CreatingStemIndx'/>\n" if $self->{'gli'};
|
---|
[2478] | 570 | if (!-e "$mgpp_stem_idx_exe") {
|
---|
[6407] | 571 | print STDERR "<FatalError name='NoRunMGStem'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 572 | die "mgppbuilder::build_index - couldn't run $mgpp_stem_idx_exe\n";
|
---|
[932] | 573 | }
|
---|
[2700] | 574 | system ("mgpp_stem_idx$exe -b 4096 -s1 -f \"$fullindexprefix\" $osextra");
|
---|
| 575 | system ("mgpp_stem_idx$exe -b 4096 -s2 -f \"$fullindexprefix\" $osextra");
|
---|
| 576 | system ("mgpp_stem_idx$exe -b 4096 -s3 -f \"$fullindexprefix\" $osextra");
|
---|
[4794] | 577 |
|
---|
[932] | 578 | # remove unwanted files
|
---|
[1852] | 579 | my $tmpdir = &util::filename_cat ($self->{'build_dir'}, $indexdir);
|
---|
| 580 | opendir (DIR, $tmpdir) || die
|
---|
| 581 | "mgppbuilder::build_index - couldn't read directory $tmpdir\n";
|
---|
[8716] | 582 | foreach my $file (readdir(DIR)) {
|
---|
[1852] | 583 | next if $file =~ /^\./;
|
---|
| 584 | my ($suffix) = $file =~ /\.([^\.]+)$/;
|
---|
| 585 | if (defined $suffix && !defined $wanted_index_files{$suffix}) {
|
---|
[932] | 586 | # delete it!
|
---|
[1852] | 587 | print $outhandle "deleting $file\n" if $self->{'verbosity'} > 2;
|
---|
[2772] | 588 | #&util::rm (&util::filename_cat ($tmpdir, $file));
|
---|
[1852] | 589 | }
|
---|
| 590 | }
|
---|
| 591 | closedir (DIR);
|
---|
[4794] | 592 | }
|
---|
[6407] | 593 | print STDERR "</Stage>\n" if $self->{'gli'};
|
---|
[932] | 594 | }
|
---|
| 595 |
|
---|
[1694] | 596 |
|
---|
[10468] | 597 | sub output_collection_meta {
|
---|
| 598 | my $self = shift(@_);
|
---|
| 599 | my ($handle) = @_;
|
---|
[1694] | 600 |
|
---|
[10477] | 601 | # define the indexed field mapping if not already done so (ie if infodb called separately from build_index)
|
---|
| 602 | if (!defined $self->{'build_cfg'}) {
|
---|
| 603 | $self->read_final_field_list();
|
---|
| 604 | }
|
---|
| 605 |
|
---|
[4794] | 606 | # do the collection info
|
---|
| 607 | print $handle "[collection]\n";
|
---|
| 608 |
|
---|
| 609 | # first do the collection meta stuff - everything without a dot
|
---|
| 610 | my $collmetadefined = 0;
|
---|
[10468] | 611 | my $metadata_entry;
|
---|
[932] | 612 | if (defined $self->{'collect_cfg'}->{'collectionmeta'}) {
|
---|
[4794] | 613 | $collmetadefined = 1;
|
---|
[8716] | 614 | foreach my $cmeta (keys (%{$self->{'collect_cfg'}->{'collectionmeta'}})) {
|
---|
[4794] | 615 | next if ($cmeta =~ /^\./); # for now, ignore ones with dots
|
---|
[10468] | 616 | $metadata_entry = $self->create_language_db_map($cmeta, $cmeta);
|
---|
[2772] | 617 | #write the entry to the file
|
---|
| 618 | print $handle $metadata_entry;
|
---|
| 619 |
|
---|
[4794] | 620 | } # foreach collmeta key
|
---|
| 621 | }
|
---|
[4811] | 622 | #add the index field macros to [collection]
|
---|
[4794] | 623 | # eg <TI>Title
|
---|
| 624 | # <SU>Subject
|
---|
| 625 | # these now come from collection meta. if that is not defined, usses the metadata name
|
---|
[8716] | 626 | my $field_entry="";
|
---|
| 627 | my $collmeta = "";
|
---|
| 628 | foreach my $longfield (@{$self->{'build_cfg'}->{'indexfields'}}){
|
---|
| 629 | my $shortfield = $self->{'buildproc'}->{'indexfieldmap'}->{$longfield};
|
---|
[4794] | 630 | next if $shortfield eq 1;
|
---|
| 631 |
|
---|
| 632 | # we need to check if some coll meta has been defined
|
---|
[8716] | 633 | $collmeta = ".$longfield";
|
---|
[4794] | 634 | if ($collmetadefined && defined $self->{'collect_cfg'}->{'collectionmeta'}->{$collmeta}) {
|
---|
[10468] | 635 | $metadata_entry = $self->create_language_db_map($collmeta, $shortfield);
|
---|
[4794] | 636 | $field_entry .= $metadata_entry;
|
---|
| 637 | } else { #use the metadata names, or the text macros for allfields and textonly
|
---|
| 638 | if ($longfield eq "allfields") {
|
---|
| 639 | $field_entry .= "<$shortfield>_query:textallfields_\n";
|
---|
| 640 | } elsif ($longfield eq "text") {
|
---|
| 641 | $field_entry .= "<$shortfield>_query:texttextonly_\n";
|
---|
| 642 | } else {
|
---|
| 643 | $field_entry .= "<$shortfield>$longfield\n";
|
---|
| 644 | }
|
---|
[932] | 645 | }
|
---|
| 646 | }
|
---|
[4794] | 647 | print $handle $field_entry;
|
---|
[2772] | 648 |
|
---|
[4811] | 649 | # now add the level names
|
---|
[8716] | 650 | my $level_entry = "";
|
---|
| 651 | foreach my $level (@{$self->{'collect_cfg'}->{'levels'}}) {
|
---|
| 652 | $collmeta = ".$level"; # based on the original specification
|
---|
[4811] | 653 | $level =~ tr/A-Z/a-z/; # make it lower case
|
---|
[7090] | 654 | my $levelid = $level_map{$level}; # find the actual value we used in the index
|
---|
[4811] | 655 | if ($collmetadefined && defined $self->{'collect_cfg'}->{'collectionmeta'}->{$collmeta}) {
|
---|
[10468] | 656 | $metadata_entry = $self->create_language_db_map($collmeta, $levelid);
|
---|
[4811] | 657 | $level_entry .= $metadata_entry;
|
---|
| 658 | } else {
|
---|
| 659 | # use the default macro
|
---|
[7090] | 660 | $level_entry .= "<$levelid>" . $level_map{$levelid} . "\n";
|
---|
[4811] | 661 | }
|
---|
| 662 | }
|
---|
| 663 | print $handle $level_entry;
|
---|
[5935] | 664 |
|
---|
| 665 | # now add subcoll meta
|
---|
[8716] | 666 | my $subcoll_entry = "";
|
---|
| 667 | my $shortname = "";
|
---|
| 668 | my $one_entry = "";
|
---|
| 669 | foreach my $subcoll (@{$self->{'index_mapping'}->{'subcollectionmaporder'}}) {
|
---|
[5935] | 670 | if (defined $self->{'collect_cfg'}->{'collectionmeta'}->{".$subcoll"}) {
|
---|
[8716] | 671 | $shortname = $self->{'index_mapping'}->{$subcoll};
|
---|
[5935] | 672 | $one_entry = $self->create_language_db_map(".$subcoll", $shortname);
|
---|
| 673 | $subcoll_entry .= $one_entry;
|
---|
| 674 | } else {
|
---|
| 675 | $subcoll_entry .= "<$shortname>$subcoll\n";
|
---|
| 676 | }
|
---|
| 677 | }
|
---|
| 678 | print $handle $subcoll_entry;
|
---|
[10158] | 679 |
|
---|
| 680 | # now add language meta
|
---|
[8716] | 681 | my $lang_entry = "";
|
---|
| 682 | foreach my $lang (@{$self->{'index_mapping'}->{'languagemaporder'}}) {
|
---|
[6544] | 683 | if (defined $self->{'collect_cfg'}->{'collectionmeta'}->{".$lang"}) {
|
---|
[8716] | 684 | $shortname = $self->{'index_mapping'}->{$lang};
|
---|
[6544] | 685 | $one_entry = $self->create_language_db_map(".$lang", $shortname);
|
---|
| 686 | $lang_entry .= $one_entry;
|
---|
| 687 | } else {
|
---|
| 688 | $lang_entry .= "<$shortname>$lang\n";
|
---|
| 689 | }
|
---|
| 690 | }
|
---|
| 691 | print $handle $lang_entry;
|
---|
[10158] | 692 | # end the collection entry
|
---|
| 693 | print $handle "\n" . ('-' x 70) . "\n";
|
---|
[932] | 694 |
|
---|
| 695 |
|
---|
| 696 | }
|
---|
[4794] | 697 | sub create_language_db_map {
|
---|
| 698 | my $self = shift (@_);
|
---|
| 699 | my ($metaname, $mapname) = @_;
|
---|
| 700 | my $outhandle = $self->{'outhandle'};
|
---|
| 701 | my $defaultfound=0;
|
---|
| 702 | my $first=1;
|
---|
| 703 | my $metadata_entry = "";
|
---|
| 704 | my $default="";
|
---|
| 705 | #iterate through the languages
|
---|
[8716] | 706 | foreach my $lang (keys (%{$self->{'collect_cfg'}->{'collectionmeta'}->{$metaname}})) {
|
---|
[4794] | 707 | if ($first) {
|
---|
| 708 | $first=0;
|
---|
| 709 | #set the default default to the first entry
|
---|
| 710 | $default=$self->{'collect_cfg'}->{'collectionmeta'}->{$metaname}->{$lang};
|
---|
| 711 | }
|
---|
| 712 | if ($lang =~ /default/) {
|
---|
| 713 | $defaultfound=1;
|
---|
| 714 | #the default entry goes first
|
---|
| 715 | $metadata_entry = "<$mapname>" .
|
---|
| 716 | $self->{'collect_cfg'}->{'collectionmeta'}->{$metaname}->{'default'} . "\n" . $metadata_entry;
|
---|
| 717 | }
|
---|
| 718 | else {
|
---|
| 719 | my ($l) = $lang =~ /^\[l=(\w*)\]$/;
|
---|
[7150] | 720 | if ($l) {
|
---|
[4794] | 721 | $metadata_entry .= "<$mapname:$l>" .
|
---|
| 722 | $self->{'collect_cfg'}->{'collectionmeta'}->{$metaname}->{$lang} . "\n";
|
---|
[7150] | 723 |
|
---|
| 724 | # Use the English value as the default if no default is specified
|
---|
| 725 | if ($l =~ /en/i) {
|
---|
| 726 | $default=$self->{'collect_cfg'}->{'collectionmeta'}->{$metaname}->{$lang};
|
---|
| 727 | }
|
---|
[4794] | 728 | }
|
---|
| 729 | }
|
---|
| 730 | } #foreach lang
|
---|
| 731 | #if we haven't found a default, put one in
|
---|
| 732 | if (!$defaultfound) {
|
---|
| 733 | $metadata_entry = "<$mapname>$default\n" . $metadata_entry;
|
---|
| 734 | }
|
---|
| 735 | return $metadata_entry;
|
---|
| 736 |
|
---|
| 737 | }
|
---|
[932] | 738 |
|
---|
[10158] | 739 | # at the end of building, we have an indexfieldmap with all the mappings,
|
---|
| 740 | # plus some extras, and indexmap with any indexes in it that weren't
|
---|
| 741 | # specified in the index definition. we want to make an ordered list of
|
---|
| 742 | # fields that are indexed, and a list of mappings that are used. this will
|
---|
| 743 | # be used for the build.cfg file, and for collection meta definition we
|
---|
| 744 | # store these in a build.cfg bit
|
---|
[4794] | 745 | sub make_final_field_list {
|
---|
| 746 | my $self = shift (@_);
|
---|
| 747 |
|
---|
| 748 | $self->{'build_cfg'} = {};
|
---|
[10158] | 749 |
|
---|
[4794] | 750 | # store the indexfieldmap information
|
---|
| 751 | my @indexfieldmap = ();
|
---|
| 752 | my @indexfields = ();
|
---|
| 753 | my $specifiedfields = {};
|
---|
| 754 | my @specifiedfieldorder = ();
|
---|
[10158] | 755 |
|
---|
| 756 | # go through the index definition and add each thing to a map, so we
|
---|
| 757 | # can easily check if it is already specified - when doing the
|
---|
| 758 | # metadata, we print out all the individual fields, but some may
|
---|
| 759 | # already be specified in the index definition, so we dont want to add
|
---|
| 760 | # those again.
|
---|
| 761 |
|
---|
[10468] | 762 | my $field;
|
---|
| 763 | foreach $field (@{$self->{'collect_cfg'}->{'indexes'}}) {
|
---|
[5617] | 764 | # remove subcoll stuff
|
---|
| 765 | my $parts = $field;
|
---|
| 766 | $parts =~ s/:.*$//;
|
---|
| 767 | my @fs = split(',', $parts);
|
---|
[8716] | 768 | foreach my $f(@fs) {
|
---|
[5617] | 769 | if (!defined $specifiedfields->{$f}) {
|
---|
| 770 | $specifiedfields->{$f}=1;
|
---|
| 771 | push (@specifiedfieldorder, "$f");
|
---|
| 772 | }
|
---|
[4794] | 773 | }
|
---|
| 774 | }
|
---|
[5643] | 775 |
|
---|
[4794] | 776 | #add all fields bit
|
---|
[10468] | 777 | foreach $field (@specifiedfieldorder) {
|
---|
[4794] | 778 | if ($field eq "metadata") {
|
---|
[8716] | 779 | foreach my $newfield (keys %{$self->{'buildproc'}->{'indexfields'}}) {
|
---|
[4794] | 780 | if (!defined $specifiedfields->{$newfield}) {
|
---|
| 781 | push (@indexfieldmap, "$newfield\-\>$self->{'buildproc'}->{'indexfieldmap'}->{$newfield}");
|
---|
| 782 | push (@indexfields, "$newfield");
|
---|
| 783 | }
|
---|
| 784 | }
|
---|
| 785 |
|
---|
| 786 | } elsif ($field eq 'text') {
|
---|
| 787 | push (@indexfieldmap, "text\-\>TX");
|
---|
| 788 | push (@indexfields, "text");
|
---|
| 789 | } elsif ($field eq 'allfields') {
|
---|
| 790 | push (@indexfieldmap, "allfields\-\>ZZ");
|
---|
| 791 | push (@indexfields, "allfields");
|
---|
| 792 | } else {
|
---|
| 793 | push (@indexfieldmap, "$field\-\>$self->{'buildproc'}->{'indexfieldmap'}->{$field}");
|
---|
| 794 | push (@indexfields, "$field");
|
---|
| 795 |
|
---|
| 796 | }
|
---|
| 797 | }
|
---|
[10158] | 798 |
|
---|
[4794] | 799 | $self->{'build_cfg'}->{'indexfieldmap'} = \@indexfieldmap;
|
---|
| 800 | $self->{'build_cfg'}->{'indexfields'} = \@indexfields;
|
---|
| 801 | }
|
---|
| 802 |
|
---|
| 803 |
|
---|
[10158] | 804 | # recreate the field list from the build.cfg file, look first in building,
|
---|
| 805 | # then in index to find it. if there is no build.cfg, we can't do the field
|
---|
| 806 | # list (there is unlikely to be any index anyway.)
|
---|
[4794] | 807 | sub read_final_field_list {
|
---|
| 808 | my $self = shift (@_);
|
---|
| 809 | $self->{'build_cfg'} = {};
|
---|
| 810 | my @indexfieldmap = ();
|
---|
| 811 | my @indexfields = ();
|
---|
| 812 |
|
---|
| 813 | if (scalar(keys %{$self->{'buildproc'}->{'indexfieldmap'}}) == 0) {
|
---|
| 814 | # set the default mapping
|
---|
| 815 | $self->{'buildproc'}->set_indexfieldmap ($self->{'indexfieldmap'});
|
---|
| 816 | }
|
---|
| 817 | # we read the stuff in from the build.cfg file - if its there
|
---|
[8716] | 818 | my $buildconfigfile = &util::filename_cat($self->{'build_dir'}, "build.cfg");
|
---|
[4794] | 819 |
|
---|
| 820 | if (!-e $buildconfigfile) {
|
---|
| 821 | # try the index dir - but do we know where it is?? try here
|
---|
| 822 | $buildconfigfile = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "index", "build.cfg");
|
---|
| 823 | if (!-e $buildconfigfile) {
|
---|
| 824 | #we cant find a config file - just ignore the field list
|
---|
| 825 | return;
|
---|
| 826 | }
|
---|
| 827 | }
|
---|
[10158] | 828 |
|
---|
[8716] | 829 | my $buildcfg = &colcfg::read_build_cfg( $buildconfigfile);
|
---|
[10468] | 830 | my $field;
|
---|
[4794] | 831 | if (defined $buildcfg->{'indexfields'}) {
|
---|
[10468] | 832 | foreach $field (@{$buildcfg->{'indexfields'}}) {
|
---|
[4794] | 833 | push (@indexfields, "$field");
|
---|
| 834 | }
|
---|
| 835 | }
|
---|
[10158] | 836 |
|
---|
[4794] | 837 | if (defined $buildcfg->{'indexfieldmap'}) {
|
---|
[10468] | 838 | foreach $field (@{$buildcfg->{'indexfieldmap'}}) {
|
---|
[4794] | 839 | push (@indexfieldmap, "$field");
|
---|
[8716] | 840 | my ($f, $v) = $field =~ /^(.*)\-\>(.*)$/;
|
---|
[4794] | 841 | $self->{'buildproc'}->{'indexfieldmap'}->{$f} = $v;
|
---|
| 842 | }
|
---|
| 843 | }
|
---|
[10158] | 844 |
|
---|
[4794] | 845 | $self->{'build_cfg'}->{'indexfieldmap'} = \@indexfieldmap;
|
---|
| 846 | $self->{'build_cfg'}->{'indexfields'} = \@indexfields;
|
---|
| 847 | }
|
---|
[10158] | 848 |
|
---|
[10468] | 849 |
|
---|
| 850 | sub write_cfg_file {
|
---|
| 851 | my $self = shift(@_);
|
---|
| 852 | my ($build_cfg) = @_;
|
---|
| 853 |
|
---|
| 854 | # write out the build information
|
---|
| 855 | &cfgread::write_cfg_file("$self->{'build_dir'}/build.cfg", $build_cfg,
|
---|
| 856 | '^(builddate|buildtype|numdocs|numsections|numbytes|textlevel|indexstem|maxnumeric)$',
|
---|
| 857 | '^(indexmap|subcollectionmap|languagemap|indexfieldmap|notbuilt|indexfields|indexlevels|levelmap)$');
|
---|
| 858 |
|
---|
| 859 | }
|
---|
| 860 |
|
---|
| 861 | sub build_cfg_extra {
|
---|
[932] | 862 | my $self = shift (@_);
|
---|
[10468] | 863 | my ($build_cfg) = @_;
|
---|
| 864 |
|
---|
| 865 | $build_cfg->{'numsections'} = $self->{'buildproc'}->get_num_sections();
|
---|
[4794] | 866 |
|
---|
[4811] | 867 | # store the level info
|
---|
| 868 | my @indexlevels = ();
|
---|
[9936] | 869 | my @levelmap = ();
|
---|
[8716] | 870 | foreach my $l (@{$self->{'levelorder'}}) {
|
---|
[7090] | 871 | push (@indexlevels, $level_map{$l});
|
---|
[9936] | 872 | push (@levelmap, "$l\-\>$level_map{$l}");
|
---|
[4811] | 873 | }
|
---|
| 874 | $build_cfg->{'indexlevels'} = \@indexlevels;
|
---|
[9936] | 875 | $build_cfg->{'levelmap'} = \@levelmap;
|
---|
| 876 |
|
---|
[4811] | 877 | if ($self->{'levels'}->{'section'}) {
|
---|
[7090] | 878 | $build_cfg->{'textlevel'} = $level_map{'section'};
|
---|
[4811] | 879 | } else {
|
---|
[7090] | 880 | $build_cfg->{'textlevel'} = $level_map{'document'};
|
---|
[4811] | 881 | }
|
---|
[10468] | 882 |
|
---|
[932] | 883 | }
|
---|
| 884 |
|
---|
| 885 | 1;
|
---|
| 886 |
|
---|
| 887 |
|
---|