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

Last change on this file since 27188 was 27188, checked in by davidb, 11 years ago

Deleting spurious binmode line

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