source: main/trunk/greenstone2/perllib/basebuildproc.pm@ 35832

Last change on this file since 35832 was 35832, checked in by davidb, 2 years ago

Addition on used debug print statement (comment out)

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