Changeset 26324 for main

Show
Ignore:
Timestamp:
16.10.2012 21:12:31 (7 years ago)
Author:
ak19
Message:

1. When purging documents from the fedora repository during import and buildcol, these documents are also removed from the Fedora GSearch index. Likewise, when documents are ingested into the Fedora repository during buildcol, these documents are also indexed by Fedora GSearch. 2. Added methods in g2futil.pm to be able to do this

Location:
main/trunk/greenstone2
Files:
3 modified

Legend:

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

    r26322 r26324  
    208208    # => Ingest individually! 
    209209 
     210    # set up fedoragsearch for updating the index upon ingesting documents 
     211    my $fedoragsearch_webapp = &g2futil::gsearch_webapp_folder();     
     212 
     213    # need the username and password preset in order to run fedoraGSearch's RESTClient script 
     214    # this assumes that the fedoragsearch authentication details are the same as for fedora 
     215    if (defined $fedoragsearch_webapp) {     
     216    $ENV{'fgsUserName'} = $options->{'username'}; 
     217    $ENV{'fgsPassword'} = $options->{'password'}; 
     218    } 
     219 
    210220    if (opendir(DIR, $export_dir)) { 
    211221    closedir DIR; 
     
    227237         
    228238        if ($dsinfo_status == 0) { 
    229             print "  $pid being updated.\n";         
     239            # first remove the doc from the gsearch index before removing it from the fedora repository 
     240            print "  deleting $pid from GSearch index\n"; 
     241            &g2futil::run_delete_from_index($fedoragsearch_webapp,$pid,$options) if defined $fedoragsearch_webapp; 
     242 
     243            print "  $pid being updated.\n"; 
    230244            &g2futil::run_purge($pid,$options); 
    231245        } 
     
    242256        print "Ingesting $docmets_filename\n"; 
    243257 
    244         &g2futil::run_ingest($docmets_filename,$options); 
     258        my $status = &g2futil::run_ingest($docmets_filename,$options); 
     259 
     260        # if the document was ingested into Fedora successfully, index it with GSearch next 
     261        if($status == 0) { 
     262        if(defined $hash_id) { 
     263            my $pid = "$pid_namespace:$gs_col-$hash_id"; 
     264            # now update the fedoragsearch index with the newly ingested document 
     265            &g2futil::run_update_index($fedoragsearch_webapp,$pid,$options) if defined $fedoragsearch_webapp; 
     266        } 
     267        } 
     268 
    245269        print STDERR "</Build>\n" if $gli; 
    246270 
  • main/trunk/greenstone2/bin/script/g2f-import.pl

    r26183 r26324  
    209209    print "* Updating existing Greenstone $gs_col objects from Fedora $pid_namespace\n"; 
    210210        print "***\n"; 
     211 
     212    # set up fedoragsearch for updating the index upon ingesting documents 
     213    my $fedoragsearch_webapp = &g2futil::gsearch_webapp_folder(); 
     214     
     215    # need the username and password preset in order to run fedoraGSearch's RESTClient script 
     216    # this assumes that the fedoragsearch authentication details are the same as for fedora 
     217    if (defined $fedoragsearch_webapp) {     
     218        $ENV{'fgsUserName'} = $options->{'username'}; 
     219        $ENV{'fgsPassword'} = $options->{'password'}; 
     220    } 
    211221 
    212222    # readdir 
     
    243253 
    244254        if ($dsinfo_status == 0) { 
     255            # first remove the doc from the gsearch index before removing it from the fedora repository 
     256            print "  deleting $pid from GSearch index\n"; 
     257            &g2futil::run_delete_from_index($fedoragsearch_webapp,$pid,$options) if defined $fedoragsearch_webapp; 
     258 
    245259            print "  $pid being updated.\n";         
    246260            &g2futil::run_purge($pid,$options); 
  • main/trunk/greenstone2/perllib/g2futil.pm

    r24362 r26324  
    5959    my $script_ext = ($ENV{'GSDLOS'} =~ m/^windows/) ? ".bat" : ".sh"; 
    6060 
    61     if ($prog =~ m/^fedora-/) { 
     61    if ($prog =~ m/^fedora-/ || $prog =~ m/^run[A-Z]*Client/) { # fedora or fedoragsearch script 
    6262    $prog .= $script_ext; 
    6363    } 
     
    168168    return $status; 
    169169} 
     170 
     171# runs fedora gsearch's runRESTClient.sh: updateIndex deletePID <PID> 
     172sub run_delete_from_index 
     173{ 
     174    my ($fedoragsearch_webapp,$pid,$options) = @_; 
     175 
     176    my $verbosity = $options->{'verbosity'}; 
     177 
     178    my $hostname = $options->{'hostname'}; 
     179    my $port     = $options->{'port'}; 
     180    my $username = $options->{'username'}; 
     181    my $password = $options->{'password'}; 
     182    my $protocol = $options->{'protocol'}; 
     183 
     184    my $server = "$hostname:$port"; 
     185    #$ENV{'fgsUserName'} = $options->{'username'}; 
     186    #$ENV{'fgsPassword'} = $options->{'password'};     
     187 
     188    #my $prog = &util::filename_cat($ENV{'FEDORA_GSEARCH'}, "runRESTClient.sh"); 
     189    my $prog = &util::filename_cat($fedoragsearch_webapp, "client", "runRESTClient.sh"); 
     190 
     191    my $gsearch_commands = "updateIndex deletePID"; 
     192    my $arguments = "$server $gsearch_commands $pid";     
     193 
     194    my $status = run_cmd($prog,$arguments,$verbosity); 
     195 
     196    return $status; 
     197} 
     198 
     199# runs fedora gsearch's runRESTClient.sh: updateIndex fromPID <PID> 
     200sub run_update_index 
     201{ 
     202    my ($fedoragsearch_webapp,$pid,$options) = @_; 
     203 
     204    my $verbosity = $options->{'verbosity'}; 
     205 
     206    my $hostname = $options->{'hostname'}; 
     207    my $port     = $options->{'port'}; 
     208    my $username = $options->{'username'}; 
     209    my $password = $options->{'password'}; 
     210    my $protocol = $options->{'protocol'}; 
     211 
     212    my $server = "$hostname:$port"; 
     213    #$ENV{'fgsUserName'} = $options->{'username'}; 
     214    #$ENV{'fgsPassword'} = $options->{'password'};     
     215 
     216    #my $prog = &util::filename_cat($ENV{'FEDORA_GSEARCH'}, "runRESTClient.sh"); 
     217    my $prog = &util::filename_cat($fedoragsearch_webapp, "client", "runRESTClient.sh"); 
     218     
     219    my $gsearch_commands = "updateIndex fromPID"; 
     220    my $arguments = "$server $gsearch_commands $pid";     
     221 
     222    my $status = run_cmd($prog,$arguments,$verbosity); 
     223 
     224    return $status; 
     225} 
     226 
     227sub gsearch_webapp_folder 
     228{    
     229    my $fedoragsearch_webapp = undef; 
     230     
     231    # if GS3, first look for a fedoragsearch webapp installed in Greenstone's tomcat 
     232    if(defined $ENV{'GSDL3SRCHOME'}) { 
     233    $fedoragsearch_webapp = &util::filename_cat($ENV{'GSDL3SRCHOME'},"packages","tomcat","webapps","fedoragsearch");     
     234    return $fedoragsearch_webapp if (&util::dir_exists($fedoragsearch_webapp)); 
     235    } 
     236 
     237    # next look for a fedoragsearch webapp installed in Fedora's tomcat 
     238    if(defined $ENV{'FEDORA_HOME'}) { 
     239    $fedoragsearch_webapp =  &util::filename_cat($ENV{'FEDORA_HOME'},"tomcat","webapps","fedoragsearch"); 
     240    return $fedoragsearch_webapp if (&util::dir_exists($fedoragsearch_webapp)); 
     241    } 
     242 
     243    ## check for a user-defined $ENV{'FEDORA_GSEARCH'} variable first, which points to a gsearch webapp folder?? 
     244 
     245    # assume no fedoragsearch 
     246    return $fedoragsearch_webapp; # undef 
     247} 
     248 
    170249 
    171250sub run_ingest