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

Last change on this file since 27261 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
RevLine 
[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
29package basebuildproc;
30
31eval {require bytes};
32
33use classify;
[15699]34use dbutil;
[9919]35use doc;
36use docproc;
[18456]37use strict;
38no strict 'subs';
39no strict 'refs';
[9919]40use util;
41
42BEGIN {
43 @basebuildproc::ISA = ('docproc');
44}
45
[12844]46sub 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
133sub 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]143sub 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
[23133]150 #$self->{'num_bytes'} = $self->{'starting_num_bytes'};
151 $self->{'num_bytes'} = 0; # we'll store num bytes in db for reconstructed docs.
[10159]152 $self->{'num_processed_bytes'} = 0;
153}
154
[10419]155sub 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]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;
[25411]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 }
[9919]205}
206
207
208sub set_mode {
209 my $self = shift (@_);
210 my ($mode) = @_;
211
212 $self->{'mode'} = $mode;
213}
214
[10159]215sub get_mode {
216 my $self = shift (@_);
217
218 return $self->{'mode'};
219}
220
[9919]221sub set_assocdir {
222 my $self = shift (@_);
223 my ($assocdir) = @_;
224
225 $self->{'assocdir'} = $assocdir;
226}
227
[15688]228sub set_dontdb {
[9919]229 my $self = shift (@_);
[15688]230 my ($dontdb) = @_;
[9919]231
[15688]232 $self->{'dontdb'} = $dontdb;
[9919]233}
234
[15725]235sub set_infodbtype
236{
237 my $self = shift(@_);
238 my $infodbtype = shift(@_);
239 $self->{'infodbtype'} = $infodbtype;
240}
241
[9919]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) = @_;
[24404]253 $lang_meta =~ s/^ex\.([^.]+)$/$1/; # strip any ex. namespace iff it's the only namespace prefix (will leave ex.dc.* intact)
254
[9919]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}
[16222]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
[9919]299sub get_doc_list {
300 my $self = shift(@_);
301
302 return @{$self->{'doclist'}};
303}
304
[15685]305# the standard database level is section, but you may want to change it to document
306sub set_db_level {
[9919]307 my $self= shift (@_);
[15685]308 my ($db_level) = @_;
[9919]309
[15685]310 $self->{'db_level'} = $db_level;
[9919]311}
312
[10469]313sub set_sections_index_document_metadata {
314 my $self= shift (@_);
315 my ($index_type) = @_;
316
317 $self->{'sections_index_document_metadata'} = $index_type;
318}
[17110]319
320sub set_separate_cjk {
321 my $self = shift (@_);
322 my ($sep_cjk) = @_;
323
324 $self->{'separate_cjk'} = $sep_cjk;
325}
326
[9919]327sub process {
328 my $self = shift (@_);
329 my $method = $self->{'mode'};
330
331 $self->$method(@_);
332}
333
[17110]334# post process text depending on field. Currently don't do anything here
[17111]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.
[17110]339sub filter_text {
340 my $self = shift (@_);
341 my ($field, $text) = @_;
[14934]342
[17110]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}
[14934]350
[17110]351
[14934]352sub infodb_metadata_stats
353{
354 my $self = shift (@_);
[18469]355 my ($field,$edit_mode) = @_;
[14934]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
[18471]367 if (($edit_mode eq "add") || ($edit_mode eq "update")) {
[18469]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
[14934]377 }
378 elsif ($field =~ m/^[[:upper:]]/) {
379 # implicit 'ex' metadata set
380
[18471]381 if (($edit_mode eq "add") || ($edit_mode eq "update")) {
[18469]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 }
[14934]391 }
392
393}
394
395
[18456]396sub infodbedit {
[9919]397 my $self = shift (@_);
[18456]398 my ($doc_obj, $filename, $edit_mode) = @_;
[23133]399
[15696]400 # only output this document if it is a "indexed_doc" or "info_doc" (database only) document
[9919]401 my $doctype = $doc_obj->get_doc_type();
[11793]402 return if ($doctype ne "indexed_doc" && $doctype ne "info_doc");
[23165]403
[11994]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
[23182]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
[11994]430 # resolve the final filenames of the files associated with this document
[23182]431 # now save the new assoc files for an update/new doc.
[11994]432 $self->assoc_files ($doc_obj, $archivedir);
433 }
434 else
435 {
[15688]436 # doc_obj reconstructed from database (has metadata, doc structure but no text)
[11994]437 my $top_section = $doc_obj->get_top_section();
438 $archivedir = $doc_obj->get_metadata_element($top_section,"archivedir");
439 }
440
[23133]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
[23160]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 }
[23133]454 }
455 # classify the document
456 &classify::classify_doc ($self->{'classifiers'}, $doc_obj);
457
[23160]458 # now add all the sections to the infodb.
[23133]459
[9919]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;
[15699]466 my $infodb_handle = $self->{'output_handle'};
[14934]467
468 $self->{'doc_mdprefix_fields'} = {};
469
[15695]470 while (defined $section)
471 {
472 my $section_OID = $doc_OID;
473 if ($section ne "")
474 {
475 $section_OID = $doc_OID . "." . $section;
476 }
[15696]477 my %section_infodb = ();
[15695]478
[23133]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
[9919]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/) {
[15697]487 $section_infodb{"doctype"} = [ "doc" ];
[9919]488 }
489
[23133]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 }
[11994]495 # Output whether this node contains text
496 #
[15688]497 # If doc_obj reconstructed from database file then no need to
[11994]498 # explicitly add <hastxt> as this is preserved as metadata when
[15688]499 # the database file is loaded in
[11994]500 if (defined $filename)
501 {
502 # doc_obj derived directly from file
503 if ($doc_obj->get_text_length($section) > 0) {
[15697]504 $section_infodb{"hastxt"} = [ "1" ];
[11994]505 } else {
[15697]506 $section_infodb{"hastxt"} = [ "0" ];
[11994]507 }
[9919]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
[22590]519 $value =~ s/([^\\])\\([^\\])/$1\\\\$2/g;
[9919]520 $value =~ s/\n/\\n/g;
521 $value =~ s/\r/\\r/g;
[24404]522 # remove any ex. iff it's the only namespace prefix (will leave ex.dc.* intact)
523 $field =~ s/^ex\.([^.]+)$/$1/; # $field =~ s/^ex\.//;
[9919]524
[23387]525 # special case for UTF8URL metadata
526 if ($field =~ m/^UTF8URL$/i) {
[23371]527 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle,
528 $value, { 'section' => [ $section_OID ] });
[9919]529 }
[23133]530
[15688]531 if (!defined $self->{'dontdb'}->{$field}) {
[15697]532 push(@{$section_infodb{$field}}, $value);
[14934]533
[24754]534 if ($section eq ""
535 && (($self->{'store_metadata_coverage'} =~ /^true$/i)
536 || $self->{'store_metadata_coverage'} eq "1"))
[14934]537 {
[18469]538 $self->infodb_metadata_stats($field,$edit_mode);
[14934]539 }
[9919]540 }
541 }
542 }
543
[14934]544 if ($section eq "")
545 {
546 my $doc_mdprefix_fields = $self->{'doc_mdprefix_fields'};
[11994]547
[14934]548 foreach my $prefix (keys %$doc_mdprefix_fields)
549 {
[15697]550 push(@{$section_infodb{"metadataset"}}, $prefix);
[14934]551
552 foreach my $field (keys %{$doc_mdprefix_fields->{$prefix}})
553 {
[15708]554 push(@{$section_infodb{"metadatalist-$prefix"}}, $field);
555
[14934]556 my $val = $doc_mdprefix_fields->{$prefix}->{$field};
[15697]557 push(@{$section_infodb{"metadatafreq-$prefix-$field"}}, $val);
[14934]558 }
559 }
560 }
561
[15688]562 # If doc_obj reconstructed from database file then no need to
[11994]563 # explicitly add <archivedir> as this is preserved as metadata when
[15688]564 # the database file is loaded in
[11994]565 if (defined $filename)
566 {
567 # output archivedir if at top level
568 if ($section eq $doc_obj->get_top_section()) {
[15697]569 $section_infodb{"archivedir"} = [ $archivedir ];
[11994]570 }
[9919]571 }
572
573 # output document display type
574 if ($first) {
[15697]575 $section_infodb{"thistype"} = [ $thistype ];
[9919]576 }
577
[15685]578 if ($self->{'db_level'} eq "document") {
[9919]579 # doc num is num_docs not num_sections
580 # output the matching document number
[15697]581 $section_infodb{"docnum"} = [ $self->{'num_docs'} ];
[15696]582 }
583 else {
[9919]584 # output a list of children
585 my $children = $doc_obj->get_children ($section);
586 if (scalar(@$children) > 0) {
[15697]587 $section_infodb{"childtype"} = [ $childtype ];
[15696]588 my $contains = "";
589 foreach my $child (@$children)
590 {
591 $contains .= ";" unless ($contains eq "");
592 if ($child =~ /^.*?\.(\d+)$/)
593 {
594 $contains .= "\".$1";
[9919]595 }
[15698]596 else
597 {
[15696]598 $contains .= "\".$child";
599 }
[9919]600 }
[15697]601 $section_infodb{"contains"} = [ $contains ];
[9919]602 }
[15696]603 # output the matching doc number
[15697]604 $section_infodb{"docnum"} = [ $self->{'num_sections'} ];
[9919]605 }
606
[25556]607 if(defined $section_infodb{'assocfilepath'})
608 {
609 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $section_infodb{'assocfilepath'}[0], { 'contains' => [ $section_OID ]});
610 }
[23133]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())
[17106]615 {
[23133]616 if ($self->{'db_level'} eq "document") {
617 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_docs'}, { 'section' => [ $doc_OID ] });
[17106]618 }
619 else {
[23133]620 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_sections'}, { 'section' => [ $section_OID ] });
[17106]621 }
[9919]622 }
[23133]623
[9919]624 $first = 0;
625 $section = $doc_obj->get_next_section($section);
[15685]626 last if ($self->{'db_level'} eq "document"); # if no sections wanted, only add the docs
[23133]627 } # while defined section
628
[15696]629}
[9919]630
[15696]631
[18456]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
[18471]645 $self->infodbedit($doc_obj,$filename,"update");
[18456]646}
647
648sub infodbdelete {
649 my $self = shift (@_);
650 my ($doc_obj, $filename) = @_;
651
652 $self->infodbedit($doc_obj,$filename,"delete");
653}
654
655
[9919]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
[18456]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
[9919]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 '!';
[10028]707 my @metadata_values;
[9919]708 if ($field =~ /^filename$/i) {
[10028]709 push(@metadata_values, $doc_obj->get_source_filename());
[9919]710 }
[10028]711 else {
[24404]712 $field =~ s/^ex\.([^.]+)$/$1/; # remove any ex. iff it's the only namespace prefix (will leave ex.dc.* intact)
[10028]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 }
[9919]723 } else {
[10028]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 }
[9919]729 }
730 }
[10028]731
732 last if ($indexed_doc == 1);
[9919]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) {
[25959]778 if ($gsdlthistype =~ /^paged$/i) {
[9919]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);
[25959]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) {
[9919]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
[18456]826sub assoc_files
827{
[9919]828 my $self = shift (@_);
829 my ($doc_obj, $archivedir) = @_;
830 my ($afile);
831
832 foreach my $assoc_file (@{$doc_obj->get_assoc_files()}) {
[12844]833 #rint STDERR "Processing associated file - copy " . $assoc_file->[0] . " to " . $assoc_file->[1] . "\n";
[9919]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@^[/\\]@) {
[12844]837 $afile = &util::filename_cat($self->{'assocdir'}, $assoc_file->[1]);
[9919]838 } else {
839 $afile = &util::filename_cat($self->{'assocdir'}, $archivedir, $assoc_file->[1]);
840 }
[25556]841
[18463]842 &util::hard_link ($assoc_file->[0], $afile, $self->{'verbosity'});
[9919]843 }
844}
845
[23176]846sub delete_assoc_files
847{
848 my $self = shift (@_);
[23182]849 my ($archivedir, $edit_mode) = @_;
[23176]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.