[18508] | 1 | ##########################################################################
|
---|
[9919] | 2 | #
|
---|
| 3 | # basebuildproc.pm --
|
---|
| 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 | # This document processor outputs a document for indexing (should be
|
---|
[15688] | 27 | # implemented by subclass) and storing in the database
|
---|
[9919] | 28 |
|
---|
| 29 | package basebuildproc;
|
---|
| 30 |
|
---|
| 31 | eval {require bytes};
|
---|
| 32 |
|
---|
| 33 | use classify;
|
---|
[15699] | 34 | use dbutil;
|
---|
[9919] | 35 | use doc;
|
---|
| 36 | use docproc;
|
---|
[18456] | 37 | use strict;
|
---|
| 38 | no strict 'subs';
|
---|
| 39 | no strict 'refs';
|
---|
[9919] | 40 | use util;
|
---|
| 41 |
|
---|
| 42 | BEGIN {
|
---|
| 43 | @basebuildproc::ISA = ('docproc');
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[12844] | 46 | sub new()
|
---|
| 47 | {
|
---|
| 48 | my ($class, $collection, $source_dir, $build_dir, $keepold, $verbosity, $outhandle) = @_;
|
---|
[9919] | 49 | my $self = new docproc ();
|
---|
| 50 |
|
---|
| 51 | # outhandle is where all the debugging info goes
|
---|
| 52 | # output_handle is where the output of the plugins is piped
|
---|
[15688] | 53 | # to (i.e. mg, database etc.)
|
---|
[9919] | 54 | $outhandle = STDERR unless defined $outhandle;
|
---|
| 55 |
|
---|
| 56 | $self->{'collection'} = $collection;
|
---|
| 57 | $self->{'source_dir'} = $source_dir;
|
---|
[10159] | 58 | $self->{'build_dir'} = $build_dir;
|
---|
| 59 | $self->{'keepold'} = $keepold;
|
---|
| 60 | $self->{'verbosity'} = $verbosity;
|
---|
| 61 | $self->{'outhandle'} = $outhandle;
|
---|
[9919] | 62 |
|
---|
| 63 | $self->{'classifiers'} = [];
|
---|
| 64 | $self->{'mode'} = "text";
|
---|
| 65 | $self->{'assocdir'} = $build_dir;
|
---|
[15688] | 66 | $self->{'dontdb'} = {};
|
---|
[16222] | 67 | $self->{'store_metadata_coverage'} = "false";
|
---|
[9919] | 68 |
|
---|
| 69 | $self->{'index'} = "section:text";
|
---|
| 70 | $self->{'indexexparr'} = [];
|
---|
| 71 |
|
---|
[17110] | 72 | $self->{'separate_cjk'} = 0;
|
---|
| 73 |
|
---|
[10159] | 74 | my $found_num_data = 0;
|
---|
| 75 | my $buildconfigfile = undef;
|
---|
| 76 |
|
---|
| 77 | if ($keepold) {
|
---|
| 78 | # For incremental building need to seed num_docs etc from values
|
---|
| 79 | # stored in build.cfg (if present)
|
---|
| 80 | $buildconfigfile = &util::filename_cat($build_dir, "build.cfg");
|
---|
| 81 | if (-e $buildconfigfile) {
|
---|
| 82 | $found_num_data = 1;
|
---|
| 83 | }
|
---|
| 84 | else {
|
---|
| 85 | # try the index dir
|
---|
| 86 | $buildconfigfile = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},
|
---|
| 87 | "index", "build.cfg");
|
---|
| 88 | if (-e $buildconfigfile) {
|
---|
| 89 | $found_num_data = 1;
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[12844] | 93 | }
|
---|
[10159] | 94 |
|
---|
[12844] | 95 | if ($found_num_data)
|
---|
| 96 | {
|
---|
| 97 | #print STDERR "Found_Num_Data!\n";
|
---|
[10159] | 98 | my $buildcfg = &colcfg::read_build_cfg($buildconfigfile);
|
---|
| 99 | $self->{'starting_num_docs'} = $buildcfg->{'numdocs'};
|
---|
[12844] | 100 | #print STDERR "- num_docs: $self->{'starting_num_docs'}\n";
|
---|
[10159] | 101 | $self->{'starting_num_sections'} = $buildcfg->{'numsections'};
|
---|
[12844] | 102 | #print STDERR "- num_sections: $self->{'starting_num_sections'}\n";
|
---|
[10159] | 103 | $self->{'starting_num_bytes'} = $buildcfg->{'numbytes'};
|
---|
[12844] | 104 | #print STDERR "- num_bytes: $self->{'starting_num_bytes'}\n";
|
---|
[10159] | 105 | }
|
---|
[12844] | 106 | else
|
---|
| 107 | {
|
---|
| 108 | #print STDERR "NOT Found_Num_Data!\n";
|
---|
| 109 | $self->{'starting_num_docs'} = 0;
|
---|
[10159] | 110 | $self->{'starting_num_sections'} = 0;
|
---|
| 111 | $self->{'starting_num_bytes'} = 0;
|
---|
[12844] | 112 | }
|
---|
[10159] | 113 |
|
---|
[9919] | 114 | $self->{'output_handle'} = "STDOUT";
|
---|
[10159] | 115 | $self->{'num_docs'} = $self->{'starting_num_docs'};
|
---|
| 116 | $self->{'num_sections'} = $self->{'starting_num_sections'};
|
---|
| 117 | $self->{'num_bytes'} = $self->{'starting_num_bytes'};
|
---|
| 118 |
|
---|
[9919] | 119 | $self->{'num_processed_bytes'} = 0;
|
---|
| 120 | $self->{'store_text'} = 1;
|
---|
| 121 |
|
---|
[15685] | 122 | # what level (section/document) the database - indexer intersection is
|
---|
| 123 | $self->{'db_level'} = "section";
|
---|
[9919] | 124 | #used by browse interface
|
---|
| 125 | $self->{'doclist'} = [];
|
---|
| 126 |
|
---|
| 127 | $self->{'indexing_text'} = 0;
|
---|
| 128 |
|
---|
| 129 | return bless $self, $class;
|
---|
| 130 |
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | sub reset {
|
---|
| 134 | my $self = shift (@_);
|
---|
[10159] | 135 |
|
---|
| 136 | $self->{'num_docs'} = $self->{'starting_num_docs'};
|
---|
| 137 | $self->{'num_sections'} = $self->{'starting_num_sections'};
|
---|
| 138 | $self->{'num_bytes'} = $self->{'starting_num_bytes'};
|
---|
[9919] | 139 |
|
---|
| 140 | $self->{'num_processed_bytes'} = 0;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[10159] | 143 | sub zero_reset {
|
---|
| 144 | my $self = shift (@_);
|
---|
| 145 |
|
---|
| 146 | $self->{'num_docs'} = 0;
|
---|
| 147 | $self->{'num_sections'} = 0;
|
---|
[17564] | 148 | # reconstructed docs have no text, just metadata, so we need to
|
---|
| 149 | # remember how many bytes we had initially
|
---|
| 150 | $self->{'num_bytes'} = $self->{'starting_num_bytes'};
|
---|
[10159] | 151 |
|
---|
| 152 | $self->{'num_processed_bytes'} = 0;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[10419] | 155 | sub is_incremental_capable
|
---|
[10304] | 156 | {
|
---|
| 157 | # By default we return 'no' as the answer
|
---|
| 158 | # Safer to assume non-incremental to start with, and then override in
|
---|
| 159 | # inherited classes that are.
|
---|
| 160 |
|
---|
| 161 | return 0;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
[9919] | 164 | sub get_num_docs {
|
---|
| 165 | my $self = shift (@_);
|
---|
| 166 |
|
---|
| 167 | return $self->{'num_docs'};
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | sub get_num_sections {
|
---|
| 171 | my $self = shift (@_);
|
---|
| 172 |
|
---|
| 173 | return $self->{'num_sections'};
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | # num_bytes is the actual number of bytes in the collection
|
---|
| 177 | # this is normally the same as what's processed during text compression
|
---|
| 178 | sub get_num_bytes {
|
---|
| 179 | my $self = shift (@_);
|
---|
| 180 |
|
---|
| 181 | return $self->{'num_bytes'};
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | # num_processed_bytes is the number of bytes actually passed
|
---|
| 185 | # to mg for the current index
|
---|
| 186 | sub get_num_processed_bytes {
|
---|
| 187 | my $self = shift (@_);
|
---|
| 188 |
|
---|
| 189 | return $self->{'num_processed_bytes'};
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | sub set_output_handle {
|
---|
| 193 | my $self = shift (@_);
|
---|
| 194 | my ($handle) = @_;
|
---|
| 195 |
|
---|
| 196 | $self->{'output_handle'} = $handle;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 | sub set_mode {
|
---|
| 201 | my $self = shift (@_);
|
---|
| 202 | my ($mode) = @_;
|
---|
| 203 |
|
---|
| 204 | $self->{'mode'} = $mode;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[10159] | 207 | sub get_mode {
|
---|
| 208 | my $self = shift (@_);
|
---|
| 209 |
|
---|
| 210 | return $self->{'mode'};
|
---|
| 211 | }
|
---|
| 212 |
|
---|
[9919] | 213 | sub set_assocdir {
|
---|
| 214 | my $self = shift (@_);
|
---|
| 215 | my ($assocdir) = @_;
|
---|
| 216 |
|
---|
| 217 | $self->{'assocdir'} = $assocdir;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
[15688] | 220 | sub set_dontdb {
|
---|
[9919] | 221 | my $self = shift (@_);
|
---|
[15688] | 222 | my ($dontdb) = @_;
|
---|
[9919] | 223 |
|
---|
[15688] | 224 | $self->{'dontdb'} = $dontdb;
|
---|
[9919] | 225 | }
|
---|
| 226 |
|
---|
[15725] | 227 | sub set_infodbtype
|
---|
| 228 | {
|
---|
| 229 | my $self = shift(@_);
|
---|
| 230 | my $infodbtype = shift(@_);
|
---|
| 231 | $self->{'infodbtype'} = $infodbtype;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[9919] | 234 | sub set_index {
|
---|
| 235 | my $self = shift (@_);
|
---|
| 236 | my ($index, $indexexparr) = @_;
|
---|
| 237 |
|
---|
| 238 | $self->{'index'} = $index;
|
---|
| 239 | $self->{'indexexparr'} = $indexexparr if defined $indexexparr;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | sub set_index_languages {
|
---|
| 243 | my $self = shift (@_);
|
---|
| 244 | my ($lang_meta, $langarr) = @_;
|
---|
[20420] | 245 | $lang_meta =~ s/^ex\.//; # strip ex. if there
|
---|
[9919] | 246 | $self->{'lang_meta'} = $lang_meta;
|
---|
| 247 | $self->{'langarr'} = $langarr;
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | sub get_index {
|
---|
| 251 | my $self = shift (@_);
|
---|
| 252 |
|
---|
| 253 | return $self->{'index'};
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | sub set_classifiers {
|
---|
| 257 | my $self = shift (@_);
|
---|
| 258 | my ($classifiers) = @_;
|
---|
| 259 |
|
---|
| 260 | $self->{'classifiers'} = $classifiers;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | sub set_indexing_text {
|
---|
| 264 | my $self = shift (@_);
|
---|
| 265 | my ($indexing_text) = @_;
|
---|
| 266 |
|
---|
| 267 | $self->{'indexing_text'} = $indexing_text;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | sub get_indexing_text {
|
---|
| 271 | my $self = shift (@_);
|
---|
| 272 |
|
---|
| 273 | return $self->{'indexing_text'};
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | sub set_store_text {
|
---|
| 277 | my $self = shift (@_);
|
---|
| 278 | my ($store_text) = @_;
|
---|
| 279 |
|
---|
| 280 | $self->{'store_text'} = $store_text;
|
---|
| 281 | }
|
---|
[16222] | 282 |
|
---|
| 283 | sub set_store_metadata_coverage {
|
---|
| 284 | my $self = shift (@_);
|
---|
| 285 | my ($store_metadata_coverage) = @_;
|
---|
| 286 |
|
---|
| 287 | $self->{'store_metadata_coverage'} = $store_metadata_coverage || "";
|
---|
| 288 | }
|
---|
| 289 |
|
---|
[9919] | 290 | sub get_doc_list {
|
---|
| 291 | my $self = shift(@_);
|
---|
| 292 |
|
---|
| 293 | return @{$self->{'doclist'}};
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[15685] | 296 | # the standard database level is section, but you may want to change it to document
|
---|
| 297 | sub set_db_level {
|
---|
[9919] | 298 | my $self= shift (@_);
|
---|
[15685] | 299 | my ($db_level) = @_;
|
---|
[9919] | 300 |
|
---|
[15685] | 301 | $self->{'db_level'} = $db_level;
|
---|
[9919] | 302 | }
|
---|
| 303 |
|
---|
[10469] | 304 | sub set_sections_index_document_metadata {
|
---|
| 305 | my $self= shift (@_);
|
---|
| 306 | my ($index_type) = @_;
|
---|
| 307 |
|
---|
| 308 | $self->{'sections_index_document_metadata'} = $index_type;
|
---|
| 309 | }
|
---|
[17110] | 310 |
|
---|
| 311 | sub set_separate_cjk {
|
---|
| 312 | my $self = shift (@_);
|
---|
| 313 | my ($sep_cjk) = @_;
|
---|
| 314 |
|
---|
| 315 | $self->{'separate_cjk'} = $sep_cjk;
|
---|
| 316 | }
|
---|
| 317 |
|
---|
[9919] | 318 | sub process {
|
---|
| 319 | my $self = shift (@_);
|
---|
| 320 | my $method = $self->{'mode'};
|
---|
| 321 |
|
---|
| 322 | $self->$method(@_);
|
---|
| 323 | }
|
---|
| 324 |
|
---|
[17110] | 325 | # post process text depending on field. Currently don't do anything here
|
---|
[17111] | 326 | # except cjk separation, and only for indexing
|
---|
| 327 | # should only do this for indexed text (if $self->{'indexing_text'}),
|
---|
| 328 | # but currently search term highlighting doesn't work if you do that.
|
---|
| 329 | # once thats fixed up, then fix this.
|
---|
[17110] | 330 | sub filter_text {
|
---|
| 331 | my $self = shift (@_);
|
---|
| 332 | my ($field, $text) = @_;
|
---|
[14934] | 333 |
|
---|
[17110] | 334 | # lets do cjk seg here
|
---|
| 335 | my $new_text =$text;
|
---|
| 336 | if ($self->{'separate_cjk'}) {
|
---|
| 337 | $new_text = &cnseg::segment($text);
|
---|
| 338 | }
|
---|
| 339 | return $new_text;
|
---|
| 340 | }
|
---|
[14934] | 341 |
|
---|
[17110] | 342 |
|
---|
[14934] | 343 | sub infodb_metadata_stats
|
---|
| 344 | {
|
---|
| 345 | my $self = shift (@_);
|
---|
[18469] | 346 | my ($field,$edit_mode) = @_;
|
---|
[14934] | 347 |
|
---|
| 348 | # Keep some statistics relating to metadata sets used and
|
---|
| 349 | # frequency of particular metadata fields within each set
|
---|
| 350 |
|
---|
| 351 | # Union of metadata prefixes and frequency of fields
|
---|
| 352 | # (both scoped for this document alone, and across whole collection)
|
---|
| 353 |
|
---|
| 354 | if ($field =~ m/^(.+)\.(.*)$/) {
|
---|
| 355 | my $prefix = $1;
|
---|
| 356 | my $core_field = $2;
|
---|
| 357 |
|
---|
[18471] | 358 | if (($edit_mode eq "add") || ($edit_mode eq "update")) {
|
---|
[18469] | 359 | $self->{'doc_mdprefix_fields'}->{$prefix}->{$core_field}++;
|
---|
| 360 | $self->{'mdprefix_fields'}->{$prefix}->{$core_field}++;
|
---|
| 361 | }
|
---|
| 362 | else {
|
---|
| 363 | # delete
|
---|
| 364 | $self->{'doc_mdprefix_fields'}->{$prefix}->{$core_field}--;
|
---|
| 365 | $self->{'mdprefix_fields'}->{$prefix}->{$core_field}--;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
[14934] | 368 | }
|
---|
| 369 | elsif ($field =~ m/^[[:upper:]]/) {
|
---|
| 370 | # implicit 'ex' metadata set
|
---|
| 371 |
|
---|
[18471] | 372 | if (($edit_mode eq "add") || ($edit_mode eq "update")) {
|
---|
[18469] | 373 |
|
---|
| 374 | $self->{'doc_mdprefix_fields'}->{'ex'}->{$field}++;
|
---|
| 375 | $self->{'mdprefix_fields'}->{'ex'}->{$field}++;
|
---|
| 376 | }
|
---|
| 377 | else {
|
---|
| 378 | # delete
|
---|
| 379 | $self->{'doc_mdprefix_fields'}->{'ex'}->{$field}--;
|
---|
| 380 | $self->{'mdprefix_fields'}->{'ex'}->{$field}--;
|
---|
| 381 | }
|
---|
[14934] | 382 | }
|
---|
| 383 |
|
---|
| 384 | }
|
---|
| 385 |
|
---|
| 386 |
|
---|
[18456] | 387 | sub infodbedit {
|
---|
[9919] | 388 | my $self = shift (@_);
|
---|
[18456] | 389 | my ($doc_obj, $filename, $edit_mode) = @_;
|
---|
[9919] | 390 |
|
---|
[15696] | 391 | # only output this document if it is a "indexed_doc" or "info_doc" (database only) document
|
---|
[9919] | 392 | my $doctype = $doc_obj->get_doc_type();
|
---|
[11793] | 393 | return if ($doctype ne "indexed_doc" && $doctype ne "info_doc");
|
---|
[9919] | 394 |
|
---|
[11994] | 395 | my $archivedir = "";
|
---|
| 396 | if (defined $filename)
|
---|
| 397 | {
|
---|
| 398 | # doc_obj derived directly from file
|
---|
| 399 | my ($dir) = $filename =~ /^(.*?)(?:\/|\\)[^\/\\]*$/;
|
---|
| 400 | $dir = "" unless defined $dir;
|
---|
| 401 | $dir =~ s/\\/\//g;
|
---|
| 402 | $dir =~ s/^\/+//;
|
---|
| 403 | $dir =~ s/\/+$//;
|
---|
| 404 |
|
---|
| 405 | $archivedir = $dir;
|
---|
| 406 |
|
---|
| 407 | # resolve the final filenames of the files associated with this document
|
---|
| 408 | $self->assoc_files ($doc_obj, $archivedir);
|
---|
| 409 | }
|
---|
| 410 | else
|
---|
| 411 | {
|
---|
[15688] | 412 | # doc_obj reconstructed from database (has metadata, doc structure but no text)
|
---|
[11994] | 413 | my $top_section = $doc_obj->get_top_section();
|
---|
| 414 | $archivedir = $doc_obj->get_metadata_element($top_section,"archivedir");
|
---|
| 415 | }
|
---|
| 416 |
|
---|
[18471] | 417 | if (($edit_mode eq "add") || ($edit_mode eq "update")) {
|
---|
[18456] | 418 | #add this document to the browse structure
|
---|
| 419 | push(@{$self->{'doclist'}},$doc_obj->get_OID())
|
---|
| 420 | unless ($doctype eq "classification");
|
---|
| 421 | }
|
---|
| 422 | else {
|
---|
| 423 | # delete => remove this doc from browse structure
|
---|
| 424 | my $del_doc_oid = $doc_obj->get_OID();
|
---|
[9919] | 425 |
|
---|
[18456] | 426 | my @filtered_doc_list = ();
|
---|
| 427 | foreach my $oid (@{$self->{'doclist'}}) {
|
---|
| 428 | push(@filtered_doc_list,$oid) if ($oid ne $del_doc_oid);
|
---|
| 429 | }
|
---|
| 430 | $self->{'doclist'} = \@filtered_doc_list;
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 |
|
---|
[9919] | 434 | # classify this document
|
---|
[18456] | 435 | &classify::classify_doc ($self->{'classifiers'}, $doc_obj, $edit_mode);
|
---|
[9919] | 436 |
|
---|
[18471] | 437 | if (($edit_mode eq "add") || ($edit_mode eq "update")) {
|
---|
[18456] | 438 | # this is another document
|
---|
| 439 | $self->{'num_docs'} += 1 unless ($doctype eq "classification");
|
---|
| 440 | }
|
---|
| 441 | else {
|
---|
| 442 | # delete
|
---|
| 443 | $self->{'num_docs'} -= 1 unless ($doctype eq "classification");
|
---|
| 444 | }
|
---|
[9919] | 445 |
|
---|
| 446 | # is this a paged or a hierarchical document
|
---|
| 447 | my ($thistype, $childtype) = $self->get_document_type ($doc_obj);
|
---|
| 448 |
|
---|
| 449 | my $section = $doc_obj->get_top_section ();
|
---|
| 450 | my $doc_OID = $doc_obj->get_OID();
|
---|
| 451 | my $first = 1;
|
---|
[15699] | 452 | my $infodb_handle = $self->{'output_handle'};
|
---|
[14934] | 453 |
|
---|
| 454 | $self->{'doc_mdprefix_fields'} = {};
|
---|
| 455 |
|
---|
[15695] | 456 | while (defined $section)
|
---|
| 457 | {
|
---|
| 458 | my $section_OID = $doc_OID;
|
---|
| 459 | if ($section ne "")
|
---|
| 460 | {
|
---|
| 461 | $section_OID = $doc_OID . "." . $section;
|
---|
| 462 | }
|
---|
[15696] | 463 | my %section_infodb = ();
|
---|
[15695] | 464 |
|
---|
[9919] | 465 | # update a few statistics
|
---|
[18471] | 466 | if (($edit_mode eq "add") || ($edit_mode eq "update")) {
|
---|
[9919] | 467 |
|
---|
[18469] | 468 | $self->{'num_bytes'} += $doc_obj->get_text_length ($section);
|
---|
| 469 | $self->{'num_sections'} += 1 unless ($doctype eq "classification");
|
---|
| 470 | }
|
---|
| 471 | else {
|
---|
| 472 | # delete
|
---|
| 473 | $self->{'num_bytes'} -= $doc_obj->get_text_length ($section);
|
---|
| 474 | $self->{'num_sections'} -= 1 unless ($doctype eq "classification");
|
---|
| 475 | }
|
---|
| 476 |
|
---|
[9919] | 477 | # output the fact that this document is a document (unless doctype
|
---|
| 478 | # has been set to something else from within a plugin
|
---|
| 479 | my $dtype = $doc_obj->get_metadata_element ($section, "doctype");
|
---|
| 480 | if (!defined $dtype || $dtype !~ /\w/) {
|
---|
[15697] | 481 | $section_infodb{"doctype"} = [ "doc" ];
|
---|
[9919] | 482 | }
|
---|
| 483 |
|
---|
[11994] | 484 | # Output whether this node contains text
|
---|
| 485 | #
|
---|
[15688] | 486 | # If doc_obj reconstructed from database file then no need to
|
---|
[11994] | 487 | # explicitly add <hastxt> as this is preserved as metadata when
|
---|
[15688] | 488 | # the database file is loaded in
|
---|
[11994] | 489 | if (defined $filename)
|
---|
| 490 | {
|
---|
| 491 | # doc_obj derived directly from file
|
---|
| 492 | if ($doc_obj->get_text_length($section) > 0) {
|
---|
[15697] | 493 | $section_infodb{"hastxt"} = [ "1" ];
|
---|
[11994] | 494 | } else {
|
---|
[15697] | 495 | $section_infodb{"hastxt"} = [ "0" ];
|
---|
[11994] | 496 | }
|
---|
[9919] | 497 | }
|
---|
| 498 |
|
---|
| 499 | # output all the section metadata
|
---|
| 500 | my $metadata = $doc_obj->get_all_metadata ($section);
|
---|
| 501 | foreach my $pair (@$metadata) {
|
---|
| 502 | my ($field, $value) = (@$pair);
|
---|
| 503 |
|
---|
| 504 | if ($field ne "Identifier" && $field !~ /^gsdl/ &&
|
---|
| 505 | defined $value && $value ne "") {
|
---|
| 506 |
|
---|
| 507 | # escape problematic stuff
|
---|
| 508 | $value =~ s/\\/\\\\/g;
|
---|
| 509 | $value =~ s/\n/\\n/g;
|
---|
| 510 | $value =~ s/\r/\\r/g;
|
---|
| 511 |
|
---|
| 512 | # special case for URL metadata
|
---|
| 513 | if ($field =~ /^URL$/i) {
|
---|
[18471] | 514 | if (($edit_mode eq "add") || ($edit_mode eq "update")) {
|
---|
[18469] | 515 |
|
---|
| 516 | &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $value, { 'section' => [ $section_OID ] });
|
---|
| 517 | }
|
---|
| 518 | else {
|
---|
| 519 | # delete
|
---|
| 520 | &dbutil::delete_infodb_entry($self->{'infodbtype'}, $infodb_handle, $value);
|
---|
| 521 | }
|
---|
| 522 |
|
---|
| 523 |
|
---|
[9919] | 524 | }
|
---|
| 525 |
|
---|
[15688] | 526 | if (!defined $self->{'dontdb'}->{$field}) {
|
---|
[15697] | 527 | push(@{$section_infodb{$field}}, $value);
|
---|
[14934] | 528 |
|
---|
[16222] | 529 | if ($section eq "" && $self->{'store_metadata_coverage'} =~ /^true$/i)
|
---|
[14934] | 530 | {
|
---|
[18469] | 531 | $self->infodb_metadata_stats($field,$edit_mode);
|
---|
[14934] | 532 | }
|
---|
[9919] | 533 | }
|
---|
| 534 | }
|
---|
| 535 | }
|
---|
| 536 |
|
---|
[14934] | 537 | if ($section eq "")
|
---|
| 538 | {
|
---|
| 539 | my $doc_mdprefix_fields = $self->{'doc_mdprefix_fields'};
|
---|
[11994] | 540 |
|
---|
[14934] | 541 | foreach my $prefix (keys %$doc_mdprefix_fields)
|
---|
| 542 | {
|
---|
[15697] | 543 | push(@{$section_infodb{"metadataset"}}, $prefix);
|
---|
[14934] | 544 |
|
---|
| 545 | foreach my $field (keys %{$doc_mdprefix_fields->{$prefix}})
|
---|
| 546 | {
|
---|
[15708] | 547 | push(@{$section_infodb{"metadatalist-$prefix"}}, $field);
|
---|
| 548 |
|
---|
[14934] | 549 | my $val = $doc_mdprefix_fields->{$prefix}->{$field};
|
---|
[15697] | 550 | push(@{$section_infodb{"metadatafreq-$prefix-$field"}}, $val);
|
---|
[14934] | 551 | }
|
---|
| 552 | }
|
---|
| 553 | }
|
---|
| 554 |
|
---|
[15688] | 555 | # If doc_obj reconstructed from database file then no need to
|
---|
[11994] | 556 | # explicitly add <archivedir> as this is preserved as metadata when
|
---|
[15688] | 557 | # the database file is loaded in
|
---|
[11994] | 558 | if (defined $filename)
|
---|
| 559 | {
|
---|
| 560 | # output archivedir if at top level
|
---|
| 561 | if ($section eq $doc_obj->get_top_section()) {
|
---|
[15697] | 562 | $section_infodb{"archivedir"} = [ $archivedir ];
|
---|
[11994] | 563 | }
|
---|
[9919] | 564 | }
|
---|
| 565 |
|
---|
| 566 | # output document display type
|
---|
| 567 | if ($first) {
|
---|
[15697] | 568 | $section_infodb{"thistype"} = [ $thistype ];
|
---|
[9919] | 569 | }
|
---|
| 570 |
|
---|
[15685] | 571 | if ($self->{'db_level'} eq "document") {
|
---|
[9919] | 572 | # doc num is num_docs not num_sections
|
---|
| 573 | # output the matching document number
|
---|
[15697] | 574 | $section_infodb{"docnum"} = [ $self->{'num_docs'} ];
|
---|
[15696] | 575 | }
|
---|
| 576 | else {
|
---|
[9919] | 577 | # output a list of children
|
---|
| 578 | my $children = $doc_obj->get_children ($section);
|
---|
| 579 | if (scalar(@$children) > 0) {
|
---|
[15697] | 580 | $section_infodb{"childtype"} = [ $childtype ];
|
---|
[15696] | 581 | my $contains = "";
|
---|
| 582 | foreach my $child (@$children)
|
---|
| 583 | {
|
---|
| 584 | $contains .= ";" unless ($contains eq "");
|
---|
| 585 | if ($child =~ /^.*?\.(\d+)$/)
|
---|
| 586 | {
|
---|
| 587 | $contains .= "\".$1";
|
---|
[9919] | 588 | }
|
---|
[15698] | 589 | else
|
---|
| 590 | {
|
---|
[15696] | 591 | $contains .= "\".$child";
|
---|
| 592 | }
|
---|
[9919] | 593 | }
|
---|
[15697] | 594 | $section_infodb{"contains"} = [ $contains ];
|
---|
[9919] | 595 | }
|
---|
[15696] | 596 | # output the matching doc number
|
---|
[15697] | 597 | $section_infodb{"docnum"} = [ $self->{'num_sections'} ];
|
---|
[9919] | 598 | }
|
---|
| 599 |
|
---|
[18471] | 600 | if (($edit_mode eq "add") || ($edit_mode eq "update")) {
|
---|
[18469] | 601 |
|
---|
| 602 | &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $section_OID, \%section_infodb);
|
---|
| 603 | }
|
---|
| 604 | else {
|
---|
| 605 | # delete
|
---|
| 606 | &dbutil::delete_infodb_entry($self->{'infodbtype'}, $infodb_handle, $section_OID);
|
---|
| 607 | }
|
---|
| 608 |
|
---|
[9919] | 609 |
|
---|
[17106] | 610 | # output a database entry for the document number, except for Lucene (which no longer needs this information)
|
---|
| 611 | unless (ref($self) eq "lucenebuildproc")
|
---|
| 612 | {
|
---|
[18471] | 613 | if (($edit_mode eq "add") || ($edit_mode eq "update")) {
|
---|
[18469] | 614 |
|
---|
| 615 | if ($self->{'db_level'} eq "document") {
|
---|
| 616 | &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_docs'}, { 'section' => [ $doc_OID ] });
|
---|
| 617 | }
|
---|
| 618 | else {
|
---|
| 619 | &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_sections'}, { 'section' => [ $section_OID ] });
|
---|
| 620 | }
|
---|
[17106] | 621 | }
|
---|
| 622 | else {
|
---|
[18469] | 623 |
|
---|
| 624 | if ($self->{'db_level'} eq "document") {
|
---|
| 625 | &dbutil::delete_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_docs'});
|
---|
| 626 | }
|
---|
| 627 | else {
|
---|
| 628 | &dbutil::delete_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_sections'});
|
---|
| 629 | }
|
---|
| 630 |
|
---|
[17106] | 631 | }
|
---|
[9919] | 632 | }
|
---|
| 633 |
|
---|
| 634 | $first = 0;
|
---|
| 635 | $section = $doc_obj->get_next_section($section);
|
---|
[15685] | 636 | last if ($self->{'db_level'} eq "document"); # if no sections wanted, only add the docs
|
---|
[9919] | 637 | }
|
---|
[15696] | 638 | }
|
---|
[9919] | 639 |
|
---|
[15696] | 640 |
|
---|
[18456] | 641 |
|
---|
| 642 |
|
---|
| 643 | sub infodb {
|
---|
| 644 | my $self = shift (@_);
|
---|
| 645 | my ($doc_obj, $filename) = @_;
|
---|
| 646 |
|
---|
| 647 | $self->infodbedit($doc_obj,$filename,"add");
|
---|
| 648 | }
|
---|
| 649 |
|
---|
| 650 | sub infodbreindex {
|
---|
| 651 | my $self = shift (@_);
|
---|
| 652 | my ($doc_obj, $filename) = @_;
|
---|
| 653 |
|
---|
[18471] | 654 | $self->infodbedit($doc_obj,$filename,"update");
|
---|
[18456] | 655 | }
|
---|
| 656 |
|
---|
| 657 | sub infodbdelete {
|
---|
| 658 | my $self = shift (@_);
|
---|
| 659 | my ($doc_obj, $filename) = @_;
|
---|
| 660 |
|
---|
| 661 | $self->infodbedit($doc_obj,$filename,"delete");
|
---|
| 662 | }
|
---|
| 663 |
|
---|
| 664 |
|
---|
[9919] | 665 | sub text {
|
---|
| 666 | my $self = shift (@_);
|
---|
| 667 | my ($doc_obj) = @_;
|
---|
| 668 |
|
---|
| 669 | my $handle = $self->{'outhandle'};
|
---|
| 670 | print $handle "basebuildproc::text function must be implemented in sub classes\n";
|
---|
| 671 | die "\n";
|
---|
| 672 | }
|
---|
| 673 |
|
---|
[18456] | 674 | sub textreindex
|
---|
| 675 | {
|
---|
| 676 | my $self = shift @_;
|
---|
| 677 |
|
---|
| 678 | my $outhandle = $self->{'outhandle'};
|
---|
| 679 | print $outhandle "basebuildproc::textreindex function must be implemented in sub classes\n";
|
---|
| 680 | if (!$self->is_incremental_capable()) {
|
---|
| 681 |
|
---|
| 682 | print $outhandle " This operation is only possible with indexing tools with that support\n";
|
---|
| 683 | print $outhandle " incremental building\n";
|
---|
| 684 | }
|
---|
| 685 | die "\n";
|
---|
| 686 | }
|
---|
| 687 |
|
---|
| 688 | sub textdelete
|
---|
| 689 | {
|
---|
| 690 | my $self = shift @_;
|
---|
| 691 |
|
---|
| 692 | my $outhandle = $self->{'outhandle'};
|
---|
| 693 | print $outhandle "basebuildproc::textdelete function must be implemented in sub classes\n";
|
---|
| 694 | if (!$self->is_incremental_capable()) {
|
---|
| 695 |
|
---|
| 696 | print $outhandle " This operation is only possible with indexing tools with that support\n";
|
---|
| 697 | print $outhandle " incremental building\n";
|
---|
| 698 | }
|
---|
| 699 | die "\n";
|
---|
| 700 | }
|
---|
| 701 |
|
---|
| 702 |
|
---|
[9919] | 703 | # should the document be indexed - according to the subcollection and language
|
---|
| 704 | # specification.
|
---|
| 705 | sub is_subcollection_doc {
|
---|
| 706 | my $self = shift (@_);
|
---|
| 707 | my ($doc_obj) = @_;
|
---|
| 708 |
|
---|
| 709 | my $indexed_doc = 1;
|
---|
| 710 | foreach my $indexexp (@{$self->{'indexexparr'}}) {
|
---|
| 711 | $indexed_doc = 0;
|
---|
| 712 | my ($field, $exp, $options) = split /\//, $indexexp;
|
---|
| 713 | if (defined ($field) && defined ($exp)) {
|
---|
| 714 | my ($bool) = $field =~ /^(.)/;
|
---|
| 715 | $field =~ s/^.// if $bool eq '!';
|
---|
[10028] | 716 | my @metadata_values;
|
---|
[9919] | 717 | if ($field =~ /^filename$/i) {
|
---|
[10028] | 718 | push(@metadata_values, $doc_obj->get_source_filename());
|
---|
[9919] | 719 | }
|
---|
[10028] | 720 | else {
|
---|
[20420] | 721 | $field =~ s/^ex\.//; #strip ex. if present
|
---|
[10028] | 722 | @metadata_values = @{$doc_obj->get_metadata($doc_obj->get_top_section(), $field)};
|
---|
| 723 | }
|
---|
| 724 | next unless @metadata_values;
|
---|
| 725 | foreach my $metadata_value (@metadata_values) {
|
---|
| 726 | if ($bool eq '!') {
|
---|
| 727 | if ($options =~ /^i$/i) {
|
---|
| 728 | if ($metadata_value !~ /$exp/i) {$indexed_doc = 1; last;}
|
---|
| 729 | } else {
|
---|
| 730 | if ($metadata_value !~ /$exp/) {$indexed_doc = 1; last;}
|
---|
| 731 | }
|
---|
[9919] | 732 | } else {
|
---|
[10028] | 733 | if ($options =~ /^i$/i) {
|
---|
| 734 | if ($metadata_value =~ /$exp/i) {$indexed_doc = 1; last;}
|
---|
| 735 | } else {
|
---|
| 736 | if ($metadata_value =~ /$exp/) {$indexed_doc = 1; last;}
|
---|
| 737 | }
|
---|
[9919] | 738 | }
|
---|
| 739 | }
|
---|
[10028] | 740 |
|
---|
| 741 | last if ($indexed_doc == 1);
|
---|
[9919] | 742 | }
|
---|
| 743 | }
|
---|
| 744 |
|
---|
| 745 | # if this doc is so far in the sub collection, and we have lang info,
|
---|
| 746 | # now we check the languages to see if it matches
|
---|
| 747 | if($indexed_doc && defined $self->{'lang_meta'}) {
|
---|
| 748 | $indexed_doc = 0;
|
---|
| 749 | my $field = $doc_obj->get_metadata_element($doc_obj->get_top_section(), $self->{'lang_meta'});
|
---|
| 750 | if (defined $field) {
|
---|
| 751 | foreach my $lang (@{$self->{'langarr'}}) {
|
---|
| 752 | my ($bool) = $lang =~ /^(.)/;
|
---|
| 753 | if ($bool eq '!') {
|
---|
| 754 | $lang =~ s/^.//;
|
---|
| 755 | if ($field !~ /$lang/) {
|
---|
| 756 | $indexed_doc = 1; last;
|
---|
| 757 | }
|
---|
| 758 | } else {
|
---|
| 759 | if ($field =~ /$lang/) {
|
---|
| 760 | $indexed_doc = 1; last;
|
---|
| 761 | }
|
---|
| 762 | }
|
---|
| 763 | }
|
---|
| 764 | }
|
---|
| 765 | }
|
---|
| 766 | return $indexed_doc;
|
---|
| 767 |
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | # use 'Paged' if document has no more than 2 levels
|
---|
| 771 | # and each section at second level has a number for
|
---|
| 772 | # Title metadata
|
---|
| 773 | # also use Paged if gsdlthistype metadata is set to Paged
|
---|
| 774 | sub get_document_type {
|
---|
| 775 | my $self = shift (@_);
|
---|
| 776 | my ($doc_obj) = @_;
|
---|
| 777 |
|
---|
| 778 | my $thistype = "VList";
|
---|
| 779 | my $childtype = "VList";
|
---|
| 780 | my $title;
|
---|
| 781 | my @tmp = ();
|
---|
| 782 |
|
---|
| 783 | my $section = $doc_obj->get_top_section ();
|
---|
| 784 |
|
---|
| 785 | my $gsdlthistype = $doc_obj->get_metadata_element ($section, "gsdlthistype");
|
---|
| 786 | if (defined $gsdlthistype) {
|
---|
| 787 | if ($gsdlthistype eq "Paged") {
|
---|
| 788 | $childtype = "Paged";
|
---|
| 789 | if ($doc_obj->get_text_length ($doc_obj->get_top_section())) {
|
---|
| 790 | $thistype = "Paged";
|
---|
| 791 | } else {
|
---|
| 792 | $thistype = "Invisible";
|
---|
| 793 | }
|
---|
| 794 |
|
---|
| 795 | return ($thistype, $childtype);
|
---|
| 796 | } elsif ($gsdlthistype eq "Hierarchy") {
|
---|
| 797 | return ($thistype, $childtype); # use VList, VList
|
---|
| 798 | }
|
---|
| 799 | }
|
---|
| 800 | my $first = 1;
|
---|
| 801 | while (defined $section) {
|
---|
| 802 | @tmp = split /\./, $section;
|
---|
| 803 | if (scalar(@tmp) > 1) {
|
---|
| 804 | return ($thistype, $childtype);
|
---|
| 805 | }
|
---|
| 806 | if (!$first) {
|
---|
| 807 | $title = $doc_obj->get_metadata_element ($section, "Title");
|
---|
| 808 | if (!defined $title || $title !~ /^\d+$/) {
|
---|
| 809 | return ($thistype, $childtype);
|
---|
| 810 | }
|
---|
| 811 | }
|
---|
| 812 | $first = 0;
|
---|
| 813 | $section = $doc_obj->get_next_section($section);
|
---|
| 814 | }
|
---|
| 815 | if ($doc_obj->get_text_length ($doc_obj->get_top_section())) {
|
---|
| 816 | $thistype = "Paged";
|
---|
| 817 | } else {
|
---|
| 818 | $thistype = "Invisible";
|
---|
| 819 | }
|
---|
| 820 | $childtype = "Paged";
|
---|
| 821 | return ($thistype, $childtype);
|
---|
| 822 | }
|
---|
| 823 |
|
---|
[18456] | 824 | sub assoc_files
|
---|
| 825 | {
|
---|
[9919] | 826 | my $self = shift (@_);
|
---|
| 827 | my ($doc_obj, $archivedir) = @_;
|
---|
| 828 | my ($afile);
|
---|
| 829 |
|
---|
| 830 | foreach my $assoc_file (@{$doc_obj->get_assoc_files()}) {
|
---|
[12844] | 831 | #rint STDERR "Processing associated file - copy " . $assoc_file->[0] . " to " . $assoc_file->[1] . "\n";
|
---|
[9919] | 832 | # if assoc file starts with a slash, we put it relative to the assoc
|
---|
| 833 | # dir, otherwise it is relative to the HASH... directory
|
---|
| 834 | if ($assoc_file->[1] =~ m@^[/\\]@) {
|
---|
[12844] | 835 | $afile = &util::filename_cat($self->{'assocdir'}, $assoc_file->[1]);
|
---|
[9919] | 836 | } else {
|
---|
| 837 | $afile = &util::filename_cat($self->{'assocdir'}, $archivedir, $assoc_file->[1]);
|
---|
| 838 | }
|
---|
[18463] | 839 | &util::hard_link ($assoc_file->[0], $afile, $self->{'verbosity'});
|
---|
[9919] | 840 | }
|
---|
| 841 | }
|
---|
| 842 |
|
---|