[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 colcfg;
|
---|
| 30 | use plugin;
|
---|
[15715] | 31 | use strict; no strict 'refs';
|
---|
[932] | 32 | use util;
|
---|
[27306] | 33 | use FileUtils;
|
---|
[932] | 34 |
|
---|
[15715] | 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 |
|
---|
[9157] | 49 | our %wanted_index_files = ('td'=>1,
|
---|
[932] | 50 | 't'=>1,
|
---|
[1852] | 51 | 'tl'=>1,
|
---|
| 52 | 'ti'=>1,
|
---|
[932] | 53 | 'idb'=>1,
|
---|
| 54 | 'ib1'=>1,
|
---|
| 55 | 'ib2'=>1,
|
---|
| 56 | 'ib3'=>1,
|
---|
[12910] | 57 | 'ib4'=>1,
|
---|
| 58 | 'ib5'=>1,
|
---|
| 59 | 'ib6'=>1,
|
---|
| 60 | 'ib7'=>1,
|
---|
[932] | 61 | 'i'=>1,
|
---|
[1852] | 62 | 'il'=>1,
|
---|
| 63 | 'w'=>1,
|
---|
[932] | 64 | 'wa'=>1);
|
---|
| 65 |
|
---|
| 66 |
|
---|
[10468] | 67 | my $maxdocsize = $basebuilder::maxdocsize;
|
---|
| 68 |
|
---|
[932] | 69 | sub new {
|
---|
[7953] | 70 | my $class = shift(@_);
|
---|
| 71 |
|
---|
[10468] | 72 | my $self = new basebuilder (@_);
|
---|
| 73 | $self = bless $self, $class;
|
---|
[932] | 74 |
|
---|
[17564] | 75 | #$self->{'indexfieldmap'} = \%static_indexfield_map;
|
---|
[6407] | 76 |
|
---|
[1852] | 77 | # get the levels (Section, Paragraph) for indexing and compression
|
---|
| 78 | $self->{'levels'} = {};
|
---|
[4811] | 79 | $self->{'levelorder'} = ();
|
---|
[1852] | 80 | if (defined $self->{'collect_cfg'}->{'levels'}) {
|
---|
[8716] | 81 | foreach my $level ( @{$self->{'collect_cfg'}->{'levels'}} ){
|
---|
[4811] | 82 | $level =~ tr/A-Z/a-z/;
|
---|
[1852] | 83 | $self->{'levels'}->{$level} = 1;
|
---|
[4811] | 84 | push (@{$self->{'levelorder'}}, $level);
|
---|
[1852] | 85 | }
|
---|
[4811] | 86 | } else { # default to document
|
---|
| 87 | $self->{'levels'}->{'document'} = 1;
|
---|
| 88 | push (@{$self->{'levelorder'}}, 'document');
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[7953] | 91 | $self->{'buildtype'} = "mgpp";
|
---|
[932] | 92 |
|
---|
| 93 | return $self;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[10468] | 96 | sub generate_index_list {
|
---|
| 97 | my $self = shift (@_);
|
---|
| 98 |
|
---|
| 99 | # sort out the indexes
|
---|
| 100 | #indexes are specified with spaces, but we put them into one index
|
---|
| 101 | my $indexes = $self->{'collect_cfg'}->{'indexes'};
|
---|
[19218] | 102 | if (defined $indexes) {
|
---|
| 103 | $self->{'collect_cfg'}->{'indexes'} = [];
|
---|
[24404] | 104 |
|
---|
| 105 | # remove any ex. from index spec but iff it is the only namespace in the metadata name
|
---|
| 106 | my @indexes_copy = @$indexes; # make a copy, as 'map' changes entry in array
|
---|
| 107 | #map { $_ =~ s/(^|,|;)ex\.([^.]+)$/$1$2/; } @indexes_copy; # No. Will replace metanames like flex.Image with fl.Image
|
---|
| 108 | map { $_ =~ s/(,|;)/$1 /g; } @indexes_copy; # introduce a space after every separator
|
---|
| 109 | map { $_ =~ s/(^| )ex\.([^.,:]+)(,|;|$)/$1$2$3/g; } @indexes_copy; # replace all <ex.> at start of metanames or <, ex.> when in a comma separated list
|
---|
| 110 | map { $_ =~ s/(,|:) /$1/g; } @indexes_copy; # remove space introduced after every separator
|
---|
| 111 | my $single_index = join(';', @indexes_copy).";";
|
---|
| 112 |
|
---|
[22352] | 113 | push (@{$self->{'collect_cfg'}->{'indexes'}}, $single_index);
|
---|
[19218] | 114 | }
|
---|
[932] | 115 | }
|
---|
| 116 |
|
---|
[12910] | 117 | sub generate_index_options {
|
---|
| 118 | my $self = shift (@_);
|
---|
| 119 |
|
---|
[17110] | 120 | $self->SUPER::generate_index_options();
|
---|
| 121 |
|
---|
[12910] | 122 | $self->{'casefold'} = 0;
|
---|
| 123 | $self->{'stem'} = 0;
|
---|
| 124 | $self->{'accentfold'} = 0;
|
---|
| 125 |
|
---|
[28215] | 126 | if (defined($self->{'collect_cfg'}->{'indexoptions'})) {
|
---|
[12910] | 127 | foreach my $option (@{$self->{'collect_cfg'}->{'indexoptions'}}) {
|
---|
| 128 | if ($option =~ /stem/) {
|
---|
| 129 | $self->{'stem'} = 1;
|
---|
| 130 | } elsif ($option =~ /casefold/) {
|
---|
| 131 | $self->{'casefold'} = 1;
|
---|
| 132 | } elsif ($option =~ /accentfold/) {
|
---|
| 133 | $self->{'accentfold'} = 1;
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | # now we record this for the build cfg
|
---|
| 139 | $self->{'stemindexes'} = 0;
|
---|
| 140 | if ($self->{'casefold'}) {
|
---|
| 141 | $self->{'stemindexes'} += 1;
|
---|
| 142 | }
|
---|
| 143 | if ($self->{'stem'}) {
|
---|
| 144 | $self->{'stemindexes'} += 2;
|
---|
| 145 | }
|
---|
| 146 | if ($self->{'accentfold'}) {
|
---|
| 147 | $self->{'stemindexes'} += 4;
|
---|
| 148 | }
|
---|
[13341] | 149 |
|
---|
[12910] | 150 | }
|
---|
| 151 |
|
---|
[10468] | 152 | sub default_buildproc {
|
---|
| 153 | my $self = shift (@_);
|
---|
| 154 |
|
---|
| 155 | return "mgppbuildproc";
|
---|
[932] | 156 | }
|
---|
| 157 |
|
---|
| 158 | sub compress_text {
|
---|
| 159 |
|
---|
| 160 | my $self = shift (@_);
|
---|
[10961] | 161 |
|
---|
| 162 | # we don't do anything if we don't want compressed text
|
---|
| 163 | return if $self->{'no_text'};
|
---|
| 164 |
|
---|
[932] | 165 | my ($textindex) = @_;
|
---|
| 166 |
|
---|
[2478] | 167 | my $exedir = "$ENV{'GSDLHOME'}/bin/$ENV{'GSDLOS'}";
|
---|
[932] | 168 | my $exe = &util::get_os_exe ();
|
---|
[27306] | 169 | my $mgpp_passes_exe = &FileUtils::filenameConcatenate($exedir, "mgpp_passes$exe");
|
---|
| 170 | my $mgpp_compression_dict_exe = &FileUtils::filenameConcatenate($exedir, "mgpp_compression_dict$exe");
|
---|
[1694] | 171 | my $outhandle = $self->{'outhandle'};
|
---|
[932] | 172 |
|
---|
[12340] | 173 | my $maxnumeric = $self->{'maxnumeric'};
|
---|
[12325] | 174 |
|
---|
[27306] | 175 | &FileUtils::makeAllDirectories (&FileUtils::filenameConcatenate($self->{'build_dir'}, "text"));
|
---|
[932] | 176 |
|
---|
[15003] | 177 | my $collect_tail = &util::get_dirsep_tail($self->{'collection'});
|
---|
[27306] | 178 | my $basefilename = &FileUtils::filenameConcatenate("text",$collect_tail);
|
---|
| 179 | my $fulltextprefix = &FileUtils::filenameConcatenate($self->{'build_dir'}, $basefilename);
|
---|
[7904] | 180 |
|
---|
[15003] | 181 | my $osextra = "";
|
---|
[28375] | 182 | if (($ENV{'GSDLOS'} =~ /^windows$/i) && ($^O ne "cygwin")) {
|
---|
[3115] | 183 | $fulltextprefix =~ s@/@\\@g;
|
---|
[2478] | 184 | }
|
---|
[2700] | 185 | else {
|
---|
| 186 | $osextra = " -d /";
|
---|
| 187 | }
|
---|
[1852] | 188 |
|
---|
| 189 |
|
---|
[4811] | 190 | # define the section names and possibly the doc name for mgpasses
|
---|
[1852] | 191 | # the compressor doesn't need to know about paragraphs - never want to
|
---|
| 192 | # retrieve them
|
---|
[13590] | 193 |
|
---|
| 194 | # always use Doc and Sec levels
|
---|
| 195 | my $mgpp_passes_sections = "-J ". $level_map{"document"} ." -K " . $level_map{"section"} ." ";
|
---|
[12911] | 196 |
|
---|
[1694] | 197 | print $outhandle "\n*** creating the compressed text\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 198 | print STDERR "<Stage name='CompressText'>\n" if $self->{'gli'};
|
---|
[932] | 199 |
|
---|
| 200 | # collect the statistics for the text
|
---|
[1694] | 201 | # -b $maxdocsize sets the maximum document size to be 12 meg
|
---|
[2478] | 202 | print $outhandle "\n collecting text statistics (mgpp_passes -T1)\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 203 | print STDERR "<Phase name='CollectTextStats'/>\n" if $self->{'gli'};
|
---|
[932] | 204 |
|
---|
| 205 | my ($handle);
|
---|
| 206 | if ($self->{'debug'}) {
|
---|
[15715] | 207 | $handle = *STDOUT;
|
---|
| 208 | }
|
---|
| 209 | else {
|
---|
[2478] | 210 | if (!-e "$mgpp_passes_exe" ||
|
---|
[15715] | 211 | !open($handle, "| mgpp_passes$exe -M $maxnumeric $mgpp_passes_sections -f \"$fulltextprefix\" -T1 $osextra")) {
|
---|
[6407] | 212 | print STDERR "<FatalError name='NoRunMGPasses'>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 213 | die "mgppbuilder::compress_text - couldn't run $mgpp_passes_exe\n";
|
---|
[932] | 214 | }
|
---|
| 215 | }
|
---|
[13590] | 216 |
|
---|
[15685] | 217 | my $db_level = "section";
|
---|
[9919] | 218 |
|
---|
[932] | 219 | $self->{'buildproc'}->set_output_handle ($handle);
|
---|
| 220 | $self->{'buildproc'}->set_mode ('text');
|
---|
| 221 | $self->{'buildproc'}->set_index ($textindex);
|
---|
| 222 | $self->{'buildproc'}->set_indexing_text (0);
|
---|
[17564] | 223 | #$self->{'buildproc'}->set_indexfieldmap ($self->{'indexfieldmap'});
|
---|
[1852] | 224 | $self->{'buildproc'}->set_levels ($self->{'levels'});
|
---|
[15685] | 225 | $self->{'buildproc'}->set_db_level ($db_level);
|
---|
[932] | 226 | $self->{'buildproc'}->reset();
|
---|
| 227 | &plugin::begin($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
| 228 | $self->{'buildproc'}, $self->{'maxdocs'});
|
---|
| 229 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[16379] | 230 | "", {}, {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
|
---|
[932] | 231 | &plugin::end($self->{'pluginfo'});
|
---|
| 232 |
|
---|
| 233 | close ($handle) unless $self->{'debug'};
|
---|
| 234 |
|
---|
[2478] | 235 | $self->print_stats();
|
---|
| 236 |
|
---|
[932] | 237 | # create the compression dictionary
|
---|
| 238 | # the compression dictionary is built by assuming the stats are from a seed
|
---|
| 239 | # dictionary (-S), if a novel word is encountered it is spelled out (-H),
|
---|
| 240 | # and the resulting dictionary must be less than 5 meg with the most
|
---|
| 241 | # frequent words being put into the dictionary first (-2 -k 5120)
|
---|
[1852] | 242 | # note: these options are left over from mg version
|
---|
[932] | 243 | if (!$self->{'debug'}) {
|
---|
[1694] | 244 | print $outhandle "\n creating the compression dictionary\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 245 | print STDERR "<Phase name='CreatingCompress'/>\n" if $self->{'gli'};
|
---|
[2478] | 246 | if (!-e "$mgpp_compression_dict_exe") {
|
---|
[6407] | 247 | print STDERR "<FatalError name='NoRunMGCompress'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 248 | die "mgppbuilder::compress_text - couldn't run $mgpp_compression_dict_exe\n";
|
---|
[932] | 249 | }
|
---|
[28119] | 250 | my $comp_dict_status = system ("mgpp_compression_dict$exe -f \"$fulltextprefix\" -S -H -2 -k 5120 $osextra");
|
---|
| 251 | if($comp_dict_status != 0) {
|
---|
| 252 | print $outhandle "\nmgppbuilder::compress_text - Warning: there's no compressed text\n";
|
---|
| 253 | $self->{'notbuilt'}->{'compressedtext'} = 1;
|
---|
| 254 | print STDERR "<Warning name='NoCompressedText'/>\n</Stage>\n" if $self->{'gli'};
|
---|
| 255 | return;
|
---|
| 256 | }
|
---|
[932] | 257 |
|
---|
| 258 | if (!$self->{'debug'}) {
|
---|
[2478] | 259 | if (!-e "$mgpp_passes_exe" ||
|
---|
[12325] | 260 | !open ($handle, "| mgpp_passes$exe -M $maxnumeric $mgpp_passes_sections -f \"$fulltextprefix\" -T2 $osextra")) {
|
---|
[6407] | 261 | print STDERR "<FatalError name='NoRunMGPasses'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 262 | die "mgppbuilder::compress_text - couldn't run $mgpp_passes_exe\n";
|
---|
[932] | 263 | }
|
---|
| 264 | }
|
---|
| 265 | }
|
---|
[6407] | 266 | else {
|
---|
| 267 | print STDERR "<Phase name='SkipCreatingComp'/>\n" if $self->{'gli'};
|
---|
| 268 | }
|
---|
[932] | 269 |
|
---|
[22820] | 270 | $self->{'buildproc'}->set_output_handle ($handle);
|
---|
[932] | 271 | $self->{'buildproc'}->reset();
|
---|
[22820] | 272 |
|
---|
[932] | 273 | # compress the text
|
---|
[2478] | 274 | print $outhandle "\n compressing the text (mgpp_passes -T2)\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 275 | print STDERR "<Phase name='CompressingText'/>\n" if $self->{'gli'};
|
---|
| 276 |
|
---|
[932] | 277 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[16379] | 278 | "", {}, {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
|
---|
[932] | 279 | close ($handle) unless $self->{'debug'};
|
---|
[1694] | 280 |
|
---|
| 281 | $self->print_stats();
|
---|
[6407] | 282 | print STDERR "</Stage>\n" if $self->{'gli'};
|
---|
[932] | 283 | }
|
---|
| 284 |
|
---|
| 285 |
|
---|
[24460] | 286 | sub post_build_indexes {
|
---|
[10468] | 287 | my $self = shift(@_);
|
---|
[24460] | 288 |
|
---|
[5617] | 289 | #define the final field lists
|
---|
| 290 | $self->make_final_field_list();
|
---|
[10468] | 291 | }
|
---|
[5617] | 292 |
|
---|
[932] | 293 | # creates directory names for each of the index descriptions
|
---|
| 294 | sub create_index_mapping {
|
---|
| 295 | my $self = shift (@_);
|
---|
| 296 | my ($indexes) = @_;
|
---|
| 297 |
|
---|
| 298 | my %mapping = ();
|
---|
[5935] | 299 |
|
---|
[19218] | 300 | return \%mapping if !(scalar @$indexes);
|
---|
| 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);
|
---|
[13590] | 314 |
|
---|
| 315 | # we only ever have one index, and its called 'idx'
|
---|
[8716] | 316 | my $pindex = 'idx';
|
---|
[4768] | 317 |
|
---|
[932] | 318 | # next comes a processed version of the subcollection if there is one.
|
---|
| 319 | my $psub = $self->process_field ($subcollection);
|
---|
| 320 | $psub = lc ($psub);
|
---|
| 321 |
|
---|
| 322 | # next comes a processed version of the language if there is one.
|
---|
| 323 | my $plang = $self->process_field ($languages);
|
---|
| 324 | $plang = lc ($plang);
|
---|
| 325 |
|
---|
| 326 | my $dirname = $pindex . $psub . $plang;
|
---|
| 327 |
|
---|
| 328 | # check to be sure all index names are unique
|
---|
| 329 | while (defined ($dirnames{$dirname})) {
|
---|
| 330 | $dirname = $self->make_unique (\%pnames, $index, \$pindex, \$psub, \$plang);
|
---|
| 331 | }
|
---|
| 332 |
|
---|
[2478] | 333 | $mapping{$index} = $dirname;
|
---|
| 334 |
|
---|
[932] | 335 | # store the mapping orders as well as the maps
|
---|
[2478] | 336 | # also put index, subcollection and language fields into the mapping thing -
|
---|
[4794] | 337 | # (the full index name (eg text:subcol:lang) is not used on
|
---|
[2478] | 338 | # the query page) -these are used for collectionmeta later on
|
---|
[932] | 339 | if (!defined $mapping{'indexmap'}{"$fields"}) {
|
---|
| 340 | $mapping{'indexmap'}{"$fields"} = $pindex;
|
---|
| 341 | push (@{$mapping{'indexmaporder'}}, "$fields");
|
---|
[2478] | 342 | if (!defined $mapping{"$fields"}) {
|
---|
| 343 | $mapping{"$fields"} = $pindex;
|
---|
| 344 | }
|
---|
[932] | 345 | }
|
---|
| 346 | if ($psub =~ /\w/ && !defined ($mapping{'subcollectionmap'}{$subcollection})) {
|
---|
| 347 | $mapping{'subcollectionmap'}{$subcollection} = $psub;
|
---|
| 348 | push (@{$mapping{'subcollectionmaporder'}}, $subcollection);
|
---|
[2478] | 349 | $mapping{$subcollection} = $psub;
|
---|
[932] | 350 | }
|
---|
| 351 | if ($plang =~ /\w/ && !defined ($mapping{'languagemap'}{$languages})) {
|
---|
| 352 | $mapping{'languagemap'}{$languages} = $plang;
|
---|
[6544] | 353 | push (@{$mapping{'languagemaporder'}}, $languages);
|
---|
[2478] | 354 | $mapping{$languages} = $plang;
|
---|
[932] | 355 | }
|
---|
| 356 | $dirnames{$dirname} = $index;
|
---|
[8716] | 357 | $pnames{'index'}->{$pindex} = "$fields";
|
---|
| 358 | $pnames{'subcollection'}->{$psub} = $subcollection;
|
---|
| 359 | $pnames{'languages'}->{$plang} = $languages;
|
---|
[932] | 360 | }
|
---|
| 361 |
|
---|
| 362 | return \%mapping;
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | sub make_unique {
|
---|
| 366 | my $self = shift (@_);
|
---|
| 367 | my ($namehash, $index, $indexref, $subref, $langref) = @_;
|
---|
| 368 | my ($fields, $subcollection, $languages) = split (":", $index);
|
---|
| 369 |
|
---|
| 370 | if ($namehash->{'index'}->{$$indexref} ne "$fields") {
|
---|
| 371 | $self->get_next_version ($indexref);
|
---|
| 372 | } elsif ($namehash->{'subcollection'}->{$$subref} ne $subcollection) {
|
---|
| 373 | $self->get_next_version ($subref);
|
---|
| 374 | } elsif ($namehash->{'languages'}->{$$langref} ne $languages) {
|
---|
| 375 | $self->get_next_version ($langref);
|
---|
| 376 | }
|
---|
| 377 | return "$$indexref$$subref$$langref";
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 |
|
---|
| 381 | sub build_index {
|
---|
| 382 | my $self = shift (@_);
|
---|
| 383 | my ($index) = @_;
|
---|
[1694] | 384 | my $outhandle = $self->{'outhandle'};
|
---|
[932] | 385 |
|
---|
| 386 | # get the full index directory path and make sure it exists
|
---|
| 387 | my $indexdir = $self->{'index_mapping'}->{$index};
|
---|
[27306] | 388 | &FileUtils::makeAllDirectories (&FileUtils::filenameConcatenate($self->{'build_dir'}, $indexdir));
|
---|
[15003] | 389 |
|
---|
| 390 | my $collect_tail = &util::get_dirsep_tail($self->{'collection'});
|
---|
[27306] | 391 | my $fullindexprefix = &FileUtils::filenameConcatenate($self->{'build_dir'},
|
---|
[2700] | 392 | $indexdir,
|
---|
[15003] | 393 | $collect_tail);
|
---|
[27306] | 394 | my $fulltextprefix = &FileUtils::filenameConcatenate($self->{'build_dir'}, "text",
|
---|
[15003] | 395 | $collect_tail);
|
---|
[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 ();
|
---|
[27306] | 401 | my $mgpp_passes_exe = &FileUtils::filenameConcatenate($exedir, "mgpp_passes$exe");
|
---|
[1852] | 402 |
|
---|
| 403 | # define the section names for mgpasses
|
---|
[13590] | 404 | my $mgpp_passes_sections = "-J ". $level_map{"document"} ." -K " . $level_map{"section"} ." ";
|
---|
| 405 | if ($self->{'levels'}->{'paragraph'}) {
|
---|
| 406 | $mgpp_passes_sections .= "-K " . $level_map{'paragraph'}. " ";
|
---|
[1852] | 407 | }
|
---|
| 408 |
|
---|
[2478] | 409 | my $mgpp_perf_hash_build_exe =
|
---|
[27306] | 410 | &FileUtils::filenameConcatenate($exedir, "mgpp_perf_hash_build$exe");
|
---|
[2478] | 411 | my $mgpp_weights_build_exe =
|
---|
[27306] | 412 | &FileUtils::filenameConcatenate($exedir, "mgpp_weights_build$exe");
|
---|
[2478] | 413 | my $mgpp_invf_dict_exe =
|
---|
[27306] | 414 | &FileUtils::filenameConcatenate($exedir, "mgpp_invf_dict$exe");
|
---|
[2478] | 415 | my $mgpp_stem_idx_exe =
|
---|
[27306] | 416 | &FileUtils::filenameConcatenate($exedir, "mgpp_stem_idx$exe");
|
---|
[932] | 417 |
|
---|
[12340] | 418 | my $maxnumeric = $self->{'maxnumeric'};
|
---|
[12325] | 419 |
|
---|
| 420 | my $osextra = "";
|
---|
[28375] | 421 | if (($ENV{'GSDLOS'} =~ /^windows$/i) && ($^O ne "cygwin")) {
|
---|
[3115] | 422 | $fullindexprefix =~ s@/@\\@g;
|
---|
[2700] | 423 | } else {
|
---|
| 424 | $osextra = " -d /";
|
---|
[3115] | 425 | if ($outhandle ne "STDERR") {
|
---|
| 426 | # so mgpp_passes doesn't print to stderr if we redirect output
|
---|
| 427 | $osextra .= " 2>/dev/null";
|
---|
| 428 | }
|
---|
[2478] | 429 | }
|
---|
[2700] | 430 |
|
---|
[932] | 431 | # get the index expression if this index belongs
|
---|
| 432 | # to a subcollection
|
---|
| 433 | my $indexexparr = [];
|
---|
[9669] | 434 | my $langarr = [];
|
---|
[2478] | 435 | # there may be subcollection info, and language info.
|
---|
| 436 | my ($fields, $subcollection, $language) = split (":", $index);
|
---|
[932] | 437 | my @subcollections = ();
|
---|
| 438 | @subcollections = split /,/, $subcollection if (defined $subcollection);
|
---|
| 439 |
|
---|
| 440 | foreach $subcollection (@subcollections) {
|
---|
| 441 | if (defined ($self->{'collect_cfg'}->{'subcollection'}->{$subcollection})) {
|
---|
| 442 | push (@$indexexparr, $self->{'collect_cfg'}->{'subcollection'}->{$subcollection});
|
---|
| 443 | }
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | # add expressions for languages if this index belongs to
|
---|
[2478] | 447 | # a language subcollection - only put languages expressions for the
|
---|
| 448 | # ones we want in the index
|
---|
[6544] | 449 |
|
---|
[2478] | 450 | my @languages = ();
|
---|
[20418] | 451 | my $languagemetadata = "Language";
|
---|
| 452 | if (defined ($self->{'collect_cfg'}->{'languagemetadata'})) {
|
---|
| 453 | $languagemetadata = $self->{'collect_cfg'}->{'languagemetadata'};
|
---|
[9548] | 454 | }
|
---|
[2478] | 455 | @languages = split /,/, $language if (defined $language);
|
---|
[9548] | 456 | foreach my $language (@languages) {
|
---|
[2478] | 457 | my $not=0;
|
---|
[932] | 458 | if ($language =~ s/^\!//) {
|
---|
[2478] | 459 | $not = 1;
|
---|
[932] | 460 | }
|
---|
[9548] | 461 | if($not) {
|
---|
[9669] | 462 | push (@$langarr, "!$language");
|
---|
[6544] | 463 | } else {
|
---|
[9669] | 464 | push (@$langarr, "$language");
|
---|
[2478] | 465 | }
|
---|
[932] | 466 | }
|
---|
| 467 |
|
---|
| 468 | # Build index dictionary. Uses verbatim stem method
|
---|
[2478] | 469 | print $outhandle "\n creating index dictionary (mgpp_passes -I1)\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 470 | print STDERR "<Phase name='CreatingIndexDic'/>\n" if $self->{'gli'};
|
---|
[932] | 471 | my ($handle);
|
---|
| 472 | if ($self->{'debug'}) {
|
---|
[15715] | 473 | $handle = *STDOUT;
|
---|
| 474 | }
|
---|
| 475 | else {
|
---|
[2478] | 476 | if (!-e "$mgpp_passes_exe" ||
|
---|
[15715] | 477 | !open($handle, "| mgpp_passes$exe -M $maxnumeric $mgpp_passes_sections -f \"$fullindexprefix\" -I1 $osextra")) {
|
---|
[6407] | 478 | print STDERR "<FatalError name='NoRunMGPasses'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 479 | die "mgppbuilder::build_index - couldn't run $mgpp_passes_exe\n";
|
---|
[932] | 480 | }
|
---|
| 481 | }
|
---|
[9919] | 482 |
|
---|
[15685] | 483 | # db_level is always section
|
---|
| 484 | my $db_level = "section";
|
---|
[9919] | 485 |
|
---|
[4794] | 486 | # set up the document processr
|
---|
[932] | 487 | $self->{'buildproc'}->set_output_handle ($handle);
|
---|
| 488 | $self->{'buildproc'}->set_mode ('text');
|
---|
| 489 | $self->{'buildproc'}->set_index ($index, $indexexparr);
|
---|
[20418] | 490 | $self->{'buildproc'}->set_index_languages ($languagemetadata, $langarr) if (defined $language);
|
---|
[932] | 491 | $self->{'buildproc'}->set_indexing_text (1);
|
---|
[9919] | 492 | $self->{'buildproc'}->set_levels ($self->{'levels'});
|
---|
[15685] | 493 | $self->{'buildproc'}->set_db_level ($db_level);
|
---|
[9919] | 494 |
|
---|
[932] | 495 | $self->{'buildproc'}->reset();
|
---|
[22820] | 496 |
|
---|
[932] | 497 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[16379] | 498 | "", {}, {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
|
---|
[932] | 499 | close ($handle) unless $self->{'debug'};
|
---|
| 500 |
|
---|
[1694] | 501 | $self->print_stats();
|
---|
| 502 |
|
---|
[5768] | 503 | # 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.
|
---|
| 504 | # we check on the .id file - index dictionary
|
---|
| 505 | my $dict_file = "$fullindexprefix.id";
|
---|
| 506 | if (!-e $dict_file) {
|
---|
| 507 | print $outhandle "mgppbuilder::build_index - Couldn't create index $index\n";
|
---|
[6407] | 508 | print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[5768] | 509 | $self->{'notbuilt'}->{$index}=1;
|
---|
| 510 | return;
|
---|
| 511 | }
|
---|
| 512 |
|
---|
[932] | 513 | if (!$self->{'debug'}) {
|
---|
| 514 | # create the perfect hash function
|
---|
[2478] | 515 | if (!-e "$mgpp_perf_hash_build_exe") {
|
---|
[6407] | 516 | print STDERR "<FatalError name='NoRunMGHash'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 517 | die "mgppbuilder::build_index - couldn't run $mgpp_perf_hash_build_exe\n";
|
---|
[932] | 518 | }
|
---|
[27985] | 519 | my $hash_cmd = "mgpp_perf_hash_build$exe -f \"$fullindexprefix\" $osextra";
|
---|
| 520 | print $outhandle "\ncmd: $hash_cmd\n" if ($self->{'verbosity'} >= 4);
|
---|
| 521 |
|
---|
| 522 | my $hash_status = system ($hash_cmd);
|
---|
[27997] | 523 | print $outhandle "\nstatus from running hash_cmd: $hash_status\n" if ($self->{'verbosity'} >= 4);
|
---|
| 524 | # check that perf hash was generated - if not, don't carry on
|
---|
| 525 | if ($hash_status !=0) {
|
---|
| 526 | print $outhandle "mgppbuilder::build_index - Couldn't create index $index as there are too few words in the index.\n";
|
---|
| 527 | print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
|
---|
| 528 | $self->{'notbuilt'}->{$index}=1;
|
---|
| 529 | return;
|
---|
| 530 |
|
---|
| 531 | }
|
---|
[27985] | 532 |
|
---|
[2478] | 533 | if (!-e "$mgpp_passes_exe" ||
|
---|
[12325] | 534 | !open ($handle, "| mgpp_passes$exe -M $maxnumeric $mgpp_passes_sections -f \"$fullindexprefix\" -I2 $osextra")) {
|
---|
[6407] | 535 | print STDERR "<FatalError name='NoRunMGPasses'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 536 | die "mgppbuilder::build_index - couldn't run $mgpp_passes_exe\n";
|
---|
[932] | 537 | }
|
---|
| 538 | }
|
---|
| 539 |
|
---|
| 540 | # invert the text
|
---|
[2478] | 541 | print $outhandle "\n inverting the text (mgpp_passes -I2)\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 542 | print STDERR "<Phase name='InvertingText'/>\n" if $self->{'gli'};
|
---|
[22820] | 543 |
|
---|
| 544 | $self->{'buildproc'}->set_output_handle ($handle);
|
---|
[932] | 545 | $self->{'buildproc'}->reset();
|
---|
[22820] | 546 |
|
---|
[932] | 547 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
[16379] | 548 | "", {}, {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
|
---|
[1694] | 549 |
|
---|
| 550 | $self->print_stats ();
|
---|
[932] | 551 |
|
---|
| 552 | if (!$self->{'debug'}) {
|
---|
| 553 |
|
---|
| 554 | close ($handle);
|
---|
[27985] | 555 | my $passes_exit_status = $?;
|
---|
| 556 | print $outhandle "\nMGPP Passes exit status $passes_exit_status\n" if ($self->{'verbosity'} >= 4);
|
---|
[932] | 557 |
|
---|
| 558 | # create the weights file
|
---|
[1694] | 559 | print $outhandle "\n create the weights file\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 560 | print STDERR "<Phase name='CreateTheWeights'/>\n" if $self->{'gli'};
|
---|
[2478] | 561 | if (!-e "$mgpp_weights_build_exe") {
|
---|
[6407] | 562 | print STDERR "<FatalError name='NoRunMGWeights'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 563 | die "mgppbuilder::build_index - couldn't run $mgpp_weights_build_exe\n";
|
---|
[932] | 564 | }
|
---|
[27985] | 565 | my $weights_cmd = "mgpp_weights_build$exe -f \"$fullindexprefix\" $osextra";
|
---|
| 566 | print $outhandle "\ncmd: $weights_cmd\n" if ($self->{'verbosity'} >= 4);
|
---|
[28119] | 567 | my $weights_status = system ($weights_cmd);
|
---|
| 568 | # check that it worked - if not, don't carry on
|
---|
| 569 | if ($weights_status !=0) {
|
---|
[28121] | 570 | print $outhandle "mgppbuilder::build_index - No Index: couldn't create weights file, error calling mgpp_weights_build.\n";
|
---|
[28119] | 571 | print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
|
---|
| 572 | $self->{'notbuilt'}->{$index}=1;
|
---|
| 573 | return;
|
---|
| 574 |
|
---|
| 575 | }
|
---|
[932] | 576 |
|
---|
| 577 | # create 'on-disk' stemmed dictionary
|
---|
[1694] | 578 | print $outhandle "\n creating 'on-disk' stemmed dictionary\n" if ($self->{'verbosity'} >= 1);
|
---|
[2478] | 579 | if (!-e "$mgpp_invf_dict_exe") {
|
---|
[6407] | 580 | print STDERR "<FatalError name='NoRunMGInvf'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 581 | die "mgppbuilder::build_index - couldn't run $mgpp_invf_dict_exe\n";
|
---|
[932] | 582 | }
|
---|
[28119] | 583 | my $invdict_status = system ("mgpp_invf_dict$exe -f \"$fullindexprefix\" $osextra" );
|
---|
| 584 | # check that it worked - if not, don't carry on
|
---|
| 585 | if ($invdict_status !=0) {
|
---|
[28121] | 586 | print $outhandle "mgppbuilder::build_index - No Index: couldn't create on-disk stemmed dictionary, error calling mgpp_invf_dict.\n";
|
---|
[28119] | 587 | print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
|
---|
| 588 | $self->{'notbuilt'}->{$index}=1;
|
---|
| 589 | return;
|
---|
| 590 |
|
---|
| 591 | }
|
---|
[932] | 592 |
|
---|
| 593 | # creates stem index files for the various stemming methods
|
---|
[1694] | 594 | print $outhandle "\n creating stem indexes\n" if ($self->{'verbosity'} >= 1);
|
---|
[6407] | 595 | print STDERR "<Phase name='CreatingStemIndx'/>\n" if $self->{'gli'};
|
---|
[2478] | 596 | if (!-e "$mgpp_stem_idx_exe") {
|
---|
[6407] | 597 | print STDERR "<FatalError name='NoRunMGStem'/>\n</Stage>\n" if $self->{'gli'};
|
---|
[2478] | 598 | die "mgppbuilder::build_index - couldn't run $mgpp_stem_idx_exe\n";
|
---|
[932] | 599 | }
|
---|
[12910] | 600 | my $accent_folding_enabled = 1;
|
---|
| 601 | if ($self->{'accentfold'}) {
|
---|
| 602 | # the first time we do this, we test for accent folding enabled
|
---|
[28119] | 603 | my $accent_status = system ("mgpp_stem_idx$exe -b 4096 -s4 -f \"$fullindexprefix\" $osextra");
|
---|
| 604 | if ($accent_status == 2) {
|
---|
[12910] | 605 | # accent folding has not been enabled in mgpp
|
---|
| 606 | $accent_folding_enabled = 0;
|
---|
| 607 | $self->{'stemindexes'} -= 4;
|
---|
[28119] | 608 | } elsif ($accent_status != 0) {
|
---|
| 609 | print $outhandle "\nAccent folding failed: mgpp_stem_idx exit status $accent_status\n" if ($self->{'verbosity'} >= 4);
|
---|
| 610 | $self->{'accentfold'} = 0;
|
---|
| 611 | #$accent_folding_enabled = 0;
|
---|
| 612 | $self->{'stemindexes'} -= 4;
|
---|
[12910] | 613 | }
|
---|
| 614 | }
|
---|
| 615 | if ($self->{'casefold'}) {
|
---|
[28119] | 616 | my $casefold_status = system ("mgpp_stem_idx$exe -b 4096 -s1 -f \"$fullindexprefix\" $osextra");
|
---|
| 617 | if ($casefold_status != 0) {
|
---|
| 618 | print $outhandle "\nCase folding failed: mgpp_stem_idx exit status $casefold_status\n" if ($self->{'verbosity'} >= 4);
|
---|
| 619 | $self->{'casefold'} = 0;
|
---|
| 620 | $self->{'stemindexes'} -= 1;
|
---|
[12910] | 621 | }
|
---|
[28119] | 622 |
|
---|
| 623 | elsif ($accent_folding_enabled && $self->{'accentfold'}) {
|
---|
| 624 | my $status = system ("mgpp_stem_idx$exe -b 4096 -s5 -f \"$fullindexprefix\" $osextra");
|
---|
| 625 | if($status != 0) {
|
---|
| 626 | print $outhandle "\nAccent folding (with casefolding) failed: mgpp_stem_idx exit status $status\n" if ($self->{'verbosity'} >= 4);
|
---|
| 627 | $self->{'accentfold'} = 0;
|
---|
| 628 | $self->{'stemindexes'} -= 4; # casefold worked, only accentfold failed, so -= 4, not -= 5
|
---|
| 629 | }
|
---|
| 630 | }
|
---|
[12910] | 631 | }
|
---|
| 632 | if ($self->{'stem'}) {
|
---|
[28119] | 633 | my $stem_status = system ("mgpp_stem_idx$exe -b 4096 -s2 -f \"$fullindexprefix\" $osextra");
|
---|
| 634 | if ($stem_status != 0) {
|
---|
| 635 | print $outhandle "\nStemming failed: mgpp_stem_idx exit status $stem_status\n" if ($self->{'verbosity'} >= 4);
|
---|
| 636 | $self->{'stem'} = 0;
|
---|
| 637 | $self->{'stemindexes'} -= 2;
|
---|
[12910] | 638 | }
|
---|
[28119] | 639 | elsif ($accent_folding_enabled && $self->{'accentfold'}) {
|
---|
| 640 | my $status = system ("mgpp_stem_idx$exe -b 4096 -s6 -f \"$fullindexprefix\" $osextra");
|
---|
| 641 | if($status != 0) {
|
---|
| 642 | print $outhandle "\nAccent folding (with stemming) failed: mgpp_stem_idx exit status $status\n" if ($self->{'verbosity'} >= 4);
|
---|
| 643 | $self->{'accentfold'} = 0;
|
---|
| 644 | $self->{'stemindexes'} -= 4; # stem worked, only accentfold failed, so -= 4, not -= 6
|
---|
| 645 | }
|
---|
| 646 | }
|
---|
[12910] | 647 | }
|
---|
| 648 | if ($self->{'casefold'} && $self->{'stem'}) {
|
---|
[28119] | 649 | my $case_and_stem_status = system ("mgpp_stem_idx$exe -b 4096 -s3 -f \"$fullindexprefix\" $osextra");
|
---|
| 650 | if ($case_and_stem_status != 0) {
|
---|
| 651 | print $outhandle "\nCasefolding and stemming failed: mgpp_stem_idx exit status $case_and_stem_status\n" if ($self->{'verbosity'} >= 4);
|
---|
| 652 | $self->{'stem'} = 0;
|
---|
| 653 | $self->{'casefold'} = 0;
|
---|
| 654 | $self->{'stemindexes'} -= 3;
|
---|
[12910] | 655 | }
|
---|
[28119] | 656 | elsif ($accent_folding_enabled && $self->{'accentfold'}) {
|
---|
| 657 | my $status = system ("mgpp_stem_idx$exe -b 4096 -s7 -f \"$fullindexprefix\" $osextra");
|
---|
| 658 | if($status != 0) {
|
---|
| 659 | print $outhandle "\nAccent folding (with stemming and casefolding) failed: mgpp_stem_idx exit status $status\n" if ($self->{'verbosity'} >= 4);
|
---|
| 660 | $self->{'accentfold'} = 0;
|
---|
| 661 | $self->{'stemindexes'} -= 4; # casefold and stem worked, only accentfold failed, so -= 4, not -= 7
|
---|
| 662 | }
|
---|
| 663 | }
|
---|
[12910] | 664 | }
|
---|
| 665 |
|
---|
[932] | 666 | # remove unwanted files
|
---|
[27306] | 667 | my $tmpdir = &FileUtils::filenameConcatenate($self->{'build_dir'}, $indexdir);
|
---|
[1852] | 668 | opendir (DIR, $tmpdir) || die
|
---|
| 669 | "mgppbuilder::build_index - couldn't read directory $tmpdir\n";
|
---|
[8716] | 670 | foreach my $file (readdir(DIR)) {
|
---|
[1852] | 671 | next if $file =~ /^\./;
|
---|
| 672 | my ($suffix) = $file =~ /\.([^\.]+)$/;
|
---|
| 673 | if (defined $suffix && !defined $wanted_index_files{$suffix}) {
|
---|
[932] | 674 | # delete it!
|
---|
[1852] | 675 | print $outhandle "deleting $file\n" if $self->{'verbosity'} > 2;
|
---|
[27306] | 676 | #&util::rm (&FileUtils::filenameConcatenate($tmpdir, $file));
|
---|
[1852] | 677 | }
|
---|
| 678 | }
|
---|
| 679 | closedir (DIR);
|
---|
[4794] | 680 | }
|
---|
[6407] | 681 | print STDERR "</Stage>\n" if $self->{'gli'};
|
---|
[932] | 682 | }
|
---|
| 683 |
|
---|
[15709] | 684 |
|
---|
| 685 | sub get_collection_meta_indexes
|
---|
| 686 | {
|
---|
[10468] | 687 | my $self = shift(@_);
|
---|
[15709] | 688 | my $collection_infodb = shift(@_);
|
---|
[1694] | 689 |
|
---|
[24460] | 690 | # define the indexed field mapping if not already done so
|
---|
| 691 | # (i.e. if infodb called separately from build_index)
|
---|
[10477] | 692 | if (!defined $self->{'build_cfg'}) {
|
---|
| 693 | $self->read_final_field_list();
|
---|
| 694 | }
|
---|
| 695 |
|
---|
[4794] | 696 | # first do the collection meta stuff - everything without a dot
|
---|
| 697 | my $collmetadefined = 0;
|
---|
[10468] | 698 | my $metadata_entry;
|
---|
[932] | 699 | if (defined $self->{'collect_cfg'}->{'collectionmeta'}) {
|
---|
[4794] | 700 | $collmetadefined = 1;
|
---|
| 701 | }
|
---|
[11965] | 702 |
|
---|
[4811] | 703 | #add the index field macros to [collection]
|
---|
[4794] | 704 | # eg <TI>Title
|
---|
| 705 | # <SU>Subject
|
---|
[17565] | 706 | # these now come from collection meta. if that is not defined, uses the metadata name
|
---|
[8716] | 707 | my $collmeta = "";
|
---|
[27328] | 708 | if (defined $self->{'build_cfg'}->{'extraindexfields'}) {
|
---|
| 709 | foreach my $longfield (@{$self->{'build_cfg'}->{'extraindexfields'}}){
|
---|
| 710 | my $shortfield = $self->{'buildproc'}->{'fieldnamemap'}->{$longfield};
|
---|
[19218] | 711 | next if $shortfield eq 1;
|
---|
| 712 |
|
---|
| 713 | # we need to check if some coll meta has been defined - don't output
|
---|
| 714 | # any that have
|
---|
| 715 | $collmeta = ".$longfield";
|
---|
| 716 | if (!$collmetadefined || !defined $self->{'collect_cfg'}->{'collectionmeta'}->{$collmeta}) {
|
---|
| 717 | if ($longfield eq "allfields") {
|
---|
| 718 | $collection_infodb->{$shortfield} = [ "_query:textallfields_" ];
|
---|
| 719 | } elsif ($longfield eq "text") {
|
---|
| 720 | $collection_infodb->{$shortfield} = [ "_query:texttextonly_" ];
|
---|
| 721 | } else {
|
---|
| 722 | $collection_infodb->{$shortfield} = [ $longfield ];
|
---|
| 723 | }
|
---|
[4794] | 724 | }
|
---|
[932] | 725 | }
|
---|
| 726 | }
|
---|
[19218] | 727 |
|
---|
[4811] | 728 | # now add the level names
|
---|
[8716] | 729 | my $level_entry = "";
|
---|
| 730 | foreach my $level (@{$self->{'collect_cfg'}->{'levels'}}) {
|
---|
| 731 | $collmeta = ".$level"; # based on the original specification
|
---|
[4811] | 732 | $level =~ tr/A-Z/a-z/; # make it lower case
|
---|
[7090] | 733 | my $levelid = $level_map{$level}; # find the actual value we used in the index
|
---|
[11965] | 734 | if (!$collmetadefined || !defined $self->{'collect_cfg'}->{'collectionmeta'}->{$collmeta}) {
|
---|
[4811] | 735 | # use the default macro
|
---|
[15709] | 736 | $collection_infodb->{$levelid} = [ $level_map{$levelid} ];
|
---|
[4811] | 737 | }
|
---|
| 738 | }
|
---|
[5935] | 739 |
|
---|
| 740 | # now add subcoll meta
|
---|
[8716] | 741 | my $subcoll_entry = "";
|
---|
| 742 | my $shortname = "";
|
---|
| 743 | my $one_entry = "";
|
---|
| 744 | foreach my $subcoll (@{$self->{'index_mapping'}->{'subcollectionmaporder'}}) {
|
---|
[11965] | 745 | $shortname = $self->{'index_mapping'}->{$subcoll};
|
---|
| 746 | if (!$collmetadefined || !defined $self->{'collect_cfg'}->{'collectionmeta'}->{".$subcoll"}) {
|
---|
[15709] | 747 | $collection_infodb->{$shortname} = [ $subcoll ];
|
---|
[5935] | 748 | }
|
---|
| 749 | }
|
---|
[10158] | 750 |
|
---|
| 751 | # now add language meta
|
---|
[8716] | 752 | my $lang_entry = "";
|
---|
| 753 | foreach my $lang (@{$self->{'index_mapping'}->{'languagemaporder'}}) {
|
---|
[11965] | 754 | $shortname = $self->{'index_mapping'}->{$lang};
|
---|
| 755 | if (!$collmetadefined || !defined $self->{'collect_cfg'}->{'collectionmeta'}->{".$lang"}) {
|
---|
[15709] | 756 | $collection_infodb->{$shortname} = [ $lang ];
|
---|
[6544] | 757 | }
|
---|
| 758 | }
|
---|
[15709] | 759 | }
|
---|
[932] | 760 |
|
---|
[15709] | 761 |
|
---|
| 762 | # default is to output the metadata sets (prefixes) used in collection
|
---|
| 763 | sub output_collection_meta
|
---|
| 764 | {
|
---|
| 765 | my $self = shift(@_);
|
---|
| 766 | my $infodb_handle = shift(@_);
|
---|
| 767 |
|
---|
| 768 | my %collection_infodb = ();
|
---|
| 769 | $self->get_collection_meta_sets(\%collection_infodb);
|
---|
| 770 | $self->get_collection_meta_indexes(\%collection_infodb);
|
---|
[15725] | 771 | &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, "collection", \%collection_infodb);
|
---|
[932] | 772 | }
|
---|
[7150] | 773 |
|
---|
[15709] | 774 |
|
---|
[10158] | 775 | # at the end of building, we have an indexfieldmap with all the mappings,
|
---|
| 776 | # plus some extras, and indexmap with any indexes in it that weren't
|
---|
[24460] | 777 | # specified in the index definition. We want to make an ordered list of
|
---|
| 778 | # fields that are indexed, and a list of mappings that are used. This will
|
---|
[10158] | 779 | # be used for the build.cfg file, and for collection meta definition we
|
---|
| 780 | # store these in a build.cfg bit
|
---|
[4794] | 781 | sub make_final_field_list {
|
---|
| 782 | my $self = shift (@_);
|
---|
| 783 |
|
---|
| 784 | $self->{'build_cfg'} = {};
|
---|
[10158] | 785 |
|
---|
[4794] | 786 | # store the indexfieldmap information
|
---|
| 787 | my @indexfieldmap = ();
|
---|
| 788 | my @indexfields = ();
|
---|
| 789 | my $specifiedfields = {};
|
---|
| 790 | my @specifiedfieldorder = ();
|
---|
[10158] | 791 |
|
---|
| 792 | # go through the index definition and add each thing to a map, so we
|
---|
| 793 | # can easily check if it is already specified - when doing the
|
---|
| 794 | # metadata, we print out all the individual fields, but some may
|
---|
| 795 | # already be specified in the index definition, so we dont want to add
|
---|
| 796 | # those again.
|
---|
| 797 |
|
---|
[10468] | 798 | my $field;
|
---|
| 799 | foreach $field (@{$self->{'collect_cfg'}->{'indexes'}}) {
|
---|
[5617] | 800 | # remove subcoll stuff
|
---|
| 801 | my $parts = $field;
|
---|
| 802 | $parts =~ s/:.*$//;
|
---|
[10961] | 803 | # *************
|
---|
| 804 | my @fs = split(';', $parts);
|
---|
[8716] | 805 | foreach my $f(@fs) {
|
---|
[5617] | 806 | if (!defined $specifiedfields->{$f}) {
|
---|
| 807 | $specifiedfields->{$f}=1;
|
---|
| 808 | push (@specifiedfieldorder, "$f");
|
---|
| 809 | }
|
---|
[4794] | 810 | }
|
---|
| 811 | }
|
---|
[5643] | 812 |
|
---|
[4794] | 813 | #add all fields bit
|
---|
[27328] | 814 | my $fnm = $self->{'buildproc'}->{'fieldnamemap'};
|
---|
[17574] | 815 |
|
---|
[10468] | 816 | foreach $field (@specifiedfieldorder) {
|
---|
[4794] | 817 | if ($field eq "metadata") {
|
---|
[27328] | 818 | foreach my $newfield (keys %{$self->{'buildproc'}->{'extraindexfields'}}) {
|
---|
[4794] | 819 | if (!defined $specifiedfields->{$newfield}) {
|
---|
[27328] | 820 | push (@indexfieldmap, "$newfield\-\>$fnm->{$newfield}");
|
---|
[4794] | 821 | push (@indexfields, "$newfield");
|
---|
| 822 | }
|
---|
| 823 | }
|
---|
| 824 |
|
---|
| 825 | } elsif ($field eq 'text') {
|
---|
| 826 | push (@indexfieldmap, "text\-\>TX");
|
---|
| 827 | push (@indexfields, "text");
|
---|
| 828 | } elsif ($field eq 'allfields') {
|
---|
| 829 | push (@indexfieldmap, "allfields\-\>ZZ");
|
---|
| 830 | push (@indexfields, "allfields");
|
---|
| 831 | } else {
|
---|
[17574] | 832 | # we only add in the ones that have been processed
|
---|
[27328] | 833 | if (defined $self->{'buildproc'}->{'allindexfields'}->{$field}) {
|
---|
| 834 | push (@indexfieldmap, "$field\-\>$fnm->{$field}");
|
---|
[11996] | 835 | push (@indexfields, "$field");
|
---|
| 836 | }
|
---|
[4794] | 837 | }
|
---|
| 838 | }
|
---|
[10158] | 839 |
|
---|
[19218] | 840 | if (scalar @indexfieldmap) {
|
---|
| 841 | $self->{'build_cfg'}->{'indexfieldmap'} = \@indexfieldmap;
|
---|
| 842 | }
|
---|
[24460] | 843 |
|
---|
[19218] | 844 | if (scalar @indexfields) {
|
---|
| 845 | $self->{'build_cfg'}->{'indexfields'} = \@indexfields;
|
---|
| 846 | }
|
---|
[4794] | 847 | }
|
---|
| 848 |
|
---|
| 849 |
|
---|
[10158] | 850 | # recreate the field list from the build.cfg file, look first in building,
|
---|
| 851 | # then in index to find it. if there is no build.cfg, we can't do the field
|
---|
| 852 | # list (there is unlikely to be any index anyway.)
|
---|
[4794] | 853 | sub read_final_field_list {
|
---|
| 854 | my $self = shift (@_);
|
---|
| 855 | $self->{'build_cfg'} = {};
|
---|
| 856 | my @indexfieldmap = ();
|
---|
| 857 | my @indexfields = ();
|
---|
[14666] | 858 | my @indexmap = ();
|
---|
| 859 |
|
---|
[4794] | 860 | # we read the stuff in from the build.cfg file - if its there
|
---|
[17574] | 861 | my $buildcfg = $self->read_build_cfg();
|
---|
| 862 | return unless defined $buildcfg;
|
---|
[10158] | 863 |
|
---|
[10468] | 864 | my $field;
|
---|
[4794] | 865 | if (defined $buildcfg->{'indexfields'}) {
|
---|
[10468] | 866 | foreach $field (@{$buildcfg->{'indexfields'}}) {
|
---|
[4794] | 867 | push (@indexfields, "$field");
|
---|
| 868 | }
|
---|
| 869 | }
|
---|
[10158] | 870 |
|
---|
[4794] | 871 | if (defined $buildcfg->{'indexfieldmap'}) {
|
---|
[10468] | 872 | foreach $field (@{$buildcfg->{'indexfieldmap'}}) {
|
---|
[4794] | 873 | push (@indexfieldmap, "$field");
|
---|
[8716] | 874 | my ($f, $v) = $field =~ /^(.*)\-\>(.*)$/;
|
---|
[4794] | 875 | $self->{'buildproc'}->{'indexfieldmap'}->{$f} = $v;
|
---|
| 876 | }
|
---|
| 877 | }
|
---|
[10158] | 878 |
|
---|
[14666] | 879 | if (defined $buildcfg->{'indexmap'}) {
|
---|
| 880 | foreach $field (@{$buildcfg->{'indexmap'}}) {
|
---|
| 881 | push (@indexmap, "$field");
|
---|
| 882 | }
|
---|
| 883 | }
|
---|
| 884 |
|
---|
[4794] | 885 | $self->{'build_cfg'}->{'indexfieldmap'} = \@indexfieldmap;
|
---|
| 886 | $self->{'build_cfg'}->{'indexfields'} = \@indexfields;
|
---|
[14666] | 887 | $self->{'build_cfg'}->{'indexmap'} = \@indexmap;
|
---|
[4794] | 888 | }
|
---|
[10158] | 889 |
|
---|
[10468] | 890 |
|
---|
| 891 | sub build_cfg_extra {
|
---|
[932] | 892 | my $self = shift (@_);
|
---|
[10468] | 893 | my ($build_cfg) = @_;
|
---|
| 894 |
|
---|
| 895 | $build_cfg->{'numsections'} = $self->{'buildproc'}->get_num_sections();
|
---|
[4794] | 896 |
|
---|
[4811] | 897 | # store the level info
|
---|
| 898 | my @indexlevels = ();
|
---|
[9936] | 899 | my @levelmap = ();
|
---|
[8716] | 900 | foreach my $l (@{$self->{'levelorder'}}) {
|
---|
[7090] | 901 | push (@indexlevels, $level_map{$l});
|
---|
[9936] | 902 | push (@levelmap, "$l\-\>$level_map{$l}");
|
---|
[4811] | 903 | }
|
---|
| 904 | $build_cfg->{'indexlevels'} = \@indexlevels;
|
---|
[9936] | 905 | $build_cfg->{'levelmap'} = \@levelmap;
|
---|
| 906 |
|
---|
[15687] | 907 | # text level (and database level) is always section
|
---|
[13590] | 908 | $build_cfg->{'textlevel'} = $level_map{'section'};
|
---|
[10468] | 909 |
|
---|
[932] | 910 | }
|
---|
| 911 |
|
---|
| 912 | 1;
|
---|
| 913 |
|
---|
| 914 |
|
---|