Changeset 24343

Show
Ignore:
Timestamp:
29.07.2011 13:08:43 (8 years ago)
Author:
davidb
Message:

Support for building non-text indexes that are orthogonol to the usual text-based index

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/bin/script/buildcol.pl

    r22743 r24343  
    546546    $builderdir = "$ENV{'GSDLCOLLECTDIR'}/perllib"; 
    547547    $buildertype = "${collection}builder"; 
    548     } else { 
     548    } else {     
     549 
    549550    $builderdir = "$ENV{'GSDLHOME'}/perllib"; 
    550551    if ($buildtype eq "lucene") { 
     
    558559    } 
    559560    } 
     561    # check for extension specific builders  
     562    # (that will then be run after main builder.pm 
     563 
     564    my @builderdir_list = ($builderdir); 
     565    my @buildertype_list = ($buildertype); 
     566     
     567    if (defined $ENV{'GSDLEXTS'}) { 
    560568     
    561     require "$builderdir/$buildertype.pm"; 
    562  
    563     eval("\$builder = new $buildertype(\$collection, " . 
    564      "\$realarchivedir, \$realbuilddir, \$verbosity, " . 
    565      "\$maxdocs, \$debug, \$keepold, \$incremental, \$incremental_mode, " . 
    566      "\$remove_empty_classifications, " . 
    567      "\$out, \$no_text, \$faillog, \$gli)"); 
    568     die "$@" if $@; 
    569  
    570     $builder->init(); 
    571     $builder->set_maxnumeric($maxnumeric); 
    572      
    573     if (($buildertype eq "mgppbuilder") && $no_strip_html) { 
    574     $builder->set_strip_html(0); 
    575     } 
    576     if ($sections_index_document_metadata ne "never") { 
    577     $builder->set_sections_index_document_metadata($sections_index_document_metadata); 
     569    my $ext_prefix = &util::filename_cat($ENV{'GSDLHOME'}, "ext"); 
     570     
     571    my @extensions = split(/:/,$ENV{'GSDLEXTS'}); 
     572    foreach my $e (@extensions) { 
     573        my $pm = "$e-builder.pm"; 
     574        $pm =~ s/-(.)/\u$1/g; 
     575 
     576        my $extbuilderdir  = &util::filename_cat($ext_prefix,$e,"perllib"); 
     577        my $full_pm = &util::filename_cat($extbuilderdir,$pm); 
     578                             
     579        if (-e $full_pm) { 
     580        my ($extbuildertype) = ($pm =~ m/^(.*)\.pm$/); 
     581        push(@builderdir_list,$extbuilderdir); 
     582        push(@buildertype_list,$extbuildertype); 
     583        } 
     584    } 
     585    } 
     586 
     587    if (defined $ENV{'GSDL3EXTS'}) { 
     588     
     589    my $ext_prefix = &util::filename_cat($ENV{'GSDL3SRCHOME'}, "ext"); 
     590     
     591    my @extensions = split(/:/,$ENV{'GSDL3EXTS'}); 
     592 
     593    foreach my $e (@extensions) { 
     594        my $pm = "$e-builder.pm"; 
     595        $pm =~ s/-(.)/\u$1/g; 
     596 
     597        my $extbuilderdir  = &util::filename_cat($ext_prefix,$e,"perllib"); 
     598        my $full_pm = &util::filename_cat($extbuilderdir,$pm); 
     599                             
     600        if (-e $full_pm) { 
     601        my ($extbuildertype) = ($pm =~ m/^(.*)\.pm$/); 
     602        push(@builderdir_list,$extbuilderdir); 
     603        push(@buildertype_list,$extbuildertype); 
     604        } 
     605    } 
     606    } 
     607 
     608    # Set up array of the main builder.pm, followed by any ones 
     609    # from the extension folders 
     610     
     611    my $num_builders = scalar(@buildertype_list); 
     612    my @builders = (); 
     613 
     614 
     615    for (my $i=0; $i<$num_builders; $i++) { 
     616    my $this_builder; 
     617    my $this_buildertype = $buildertype_list[$i]; 
     618    my $this_builderdir  = $builderdir_list[$i]; 
     619 
     620    require "$this_builderdir/$this_buildertype.pm"; 
     621 
     622    eval("\$this_builder = new $this_buildertype(\$collection, " . 
     623         "\$realarchivedir, \$realbuilddir, \$verbosity, " . 
     624         "\$maxdocs, \$debug, \$keepold, \$incremental, \$incremental_mode, " . 
     625         "\$remove_empty_classifications, " . 
     626         "\$out, \$no_text, \$faillog, \$gli)"); 
     627    die "$@" if $@; 
     628 
     629    push(@builders,$this_builder); 
     630    } 
     631     
     632    # Init phase for builders 
     633    for (my $i=0; $i<$num_builders; $i++) { 
     634    my $this_buildertype = $buildertype_list[$i]; 
     635    my $this_builderdir  = $builderdir_list[$i]; 
     636    my $this_builder     = $builders[$i]; 
     637 
     638    $this_builder->init(); 
     639    $this_builder->set_maxnumeric($maxnumeric); 
     640     
     641    if (($this_buildertype eq "mgppbuilder") && $no_strip_html) { 
     642        $this_builder->set_strip_html(0); 
     643    } 
     644    if ($sections_index_document_metadata ne "never") { 
     645        $this_builder->set_sections_index_document_metadata($sections_index_document_metadata); 
     646    } 
    578647    } 
    579648         
     649    # Run the requested passes 
     650 
    580651    if ($mode =~ /^all$/i) { 
    581     $builder->compress_text($textindex); 
    582     $builder->build_indexes($indexname); 
    583     $builder->make_infodatabase(); 
    584     $builder->collect_specific(); 
     652 
     653    # 'map' modifies the elements of the original array, so calling 
     654    # methods -- as done below -- will cause (by default) @builders 
     655    # to be changed to whatever these functions return (which is *not* 
     656    # what we want -- we want to leave the values unchanged)  
     657    # => Use 'local' (dynamic scoping) to give each 'map' call its 
     658    #    own local copy This could also be done with:  
     659    #      (my $new =$_)->method(); $new  
     660    #    but is a bit more cumbersome to write 
     661 
     662    map { local $_=$_; $_->compress_text($textindex); } @builders; 
     663    map { local $_=$_; $_->build_indexes($indexname); } @builders; 
     664    map { local $_=$_; $_->make_infodatabase(); }  @builders; 
     665    map { local $_=$_; $_->collect_specific(); } @builders; 
    585666    } elsif ($mode =~ /^compress_text$/i) { 
    586     $builder->compress_text($textindex); 
     667    map { local $_=$_; $_->compress_text($textindex); } @builders; 
    587668    } elsif ($mode =~ /^build_index$/i) { 
    588     $builder->build_indexes($indexname);     
     669    map { local $_=$_; $_->build_indexes($indexname); } @builders; 
    589670    } elsif ($mode =~ /^infodb$/i) { 
    590     $builder->make_infodatabase(); 
     671    map { local $_=$_; $_->make_infodatabase(); } @builders; 
    591672    } else { 
    592673    (&gsprintf(STDERR, "{buildcol.unknown_mode}\n", $mode) && die); 
    593674    } 
    594675 
    595     $builder->make_auxiliary_files() if !$debug; 
    596     $builder->deinit(); 
     676    if (!$debug) { 
     677    map {local $_=$_; $_->make_auxiliary_files(); } @builders; 
     678    } 
     679    map {local $_=$_; $_->deinit(); } @builders; 
    597680     
    598681    if (($realbuilddir ne $builddir) && !$debug) { 
     
    608691    print STDERR "</Build>\n" if $gli; 
    609692} 
    610 ## main() ## 
    611  
    612  
     693 
     694 
     695