Index: main/trunk/greenstone2/bin/script/g2f-buildcol.pl
===================================================================
--- main/trunk/greenstone2/bin/script/g2f-buildcol.pl	(revision 26323)
+++ main/trunk/greenstone2/bin/script/g2f-buildcol.pl	(revision 26324)
@@ -208,4 +208,14 @@
     # => Ingest individually!
 
+    # set up fedoragsearch for updating the index upon ingesting documents
+    my $fedoragsearch_webapp = &g2futil::gsearch_webapp_folder();    
+
+    # need the username and password preset in order to run fedoraGSearch's RESTClient script
+    # this assumes that the fedoragsearch authentication details are the same as for fedora
+    if (defined $fedoragsearch_webapp) {	
+	$ENV{'fgsUserName'} = $options->{'username'};
+	$ENV{'fgsPassword'} = $options->{'password'};
+    }
+
     if (opendir(DIR, $export_dir)) {
 	closedir DIR;
@@ -227,5 +237,9 @@
 		
 		if ($dsinfo_status == 0) {
-		    print "  $pid being updated.\n";	    
+		    # first remove the doc from the gsearch index before removing it from the fedora repository
+		    print "  deleting $pid from GSearch index\n";
+		    &g2futil::run_delete_from_index($fedoragsearch_webapp,$pid,$options) if defined $fedoragsearch_webapp;
+
+		    print "  $pid being updated.\n";
 		    &g2futil::run_purge($pid,$options);
 		}
@@ -242,5 +256,15 @@
 	    print "Ingesting $docmets_filename\n";
 
-	    &g2futil::run_ingest($docmets_filename,$options);
+	    my $status = &g2futil::run_ingest($docmets_filename,$options);
+
+	    # if the document was ingested into Fedora successfully, index it with GSearch next
+	    if($status == 0) {
+		if(defined $hash_id) {
+		    my $pid = "$pid_namespace:$gs_col-$hash_id";
+		    # now update the fedoragsearch index with the newly ingested document
+		    &g2futil::run_update_index($fedoragsearch_webapp,$pid,$options) if defined $fedoragsearch_webapp;
+		}
+	    }
+
 	    print STDERR "</Build>\n" if $gli;
 
Index: main/trunk/greenstone2/bin/script/g2f-import.pl
===================================================================
--- main/trunk/greenstone2/bin/script/g2f-import.pl	(revision 26323)
+++ main/trunk/greenstone2/bin/script/g2f-import.pl	(revision 26324)
@@ -209,4 +209,14 @@
 	print "* Updating existing Greenstone $gs_col objects from Fedora $pid_namespace\n";
         print "***\n";
+
+	# set up fedoragsearch for updating the index upon ingesting documents
+	my $fedoragsearch_webapp = &g2futil::gsearch_webapp_folder();
+	
+	# need the username and password preset in order to run fedoraGSearch's RESTClient script
+	# this assumes that the fedoragsearch authentication details are the same as for fedora
+	if (defined $fedoragsearch_webapp) {	
+	    $ENV{'fgsUserName'} = $options->{'username'};
+	    $ENV{'fgsPassword'} = $options->{'password'};
+	}
 
 	# readdir
@@ -243,4 +253,8 @@
 
 		if ($dsinfo_status == 0) {
+		    # first remove the doc from the gsearch index before removing it from the fedora repository
+		    print "  deleting $pid from GSearch index\n";
+		    &g2futil::run_delete_from_index($fedoragsearch_webapp,$pid,$options) if defined $fedoragsearch_webapp;
+
 		    print "  $pid being updated.\n";	    
 		    &g2futil::run_purge($pid,$options);
Index: main/trunk/greenstone2/perllib/g2futil.pm
===================================================================
--- main/trunk/greenstone2/perllib/g2futil.pm	(revision 26323)
+++ main/trunk/greenstone2/perllib/g2futil.pm	(revision 26324)
@@ -59,5 +59,5 @@
     my $script_ext = ($ENV{'GSDLOS'} =~ m/^windows/) ? ".bat" : ".sh";
 
-    if ($prog =~ m/^fedora-/) {
+    if ($prog =~ m/^fedora-/ || $prog =~ m/^run[A-Z]*Client/) { # fedora or fedoragsearch script
 	$prog .= $script_ext;
     }
@@ -168,4 +168,83 @@
     return $status;
 }
+
+# runs fedora gsearch's runRESTClient.sh: updateIndex deletePID <PID>
+sub run_delete_from_index
+{
+    my ($fedoragsearch_webapp,$pid,$options) = @_;
+
+    my $verbosity = $options->{'verbosity'};
+
+    my $hostname = $options->{'hostname'};
+    my $port     = $options->{'port'};
+    my $username = $options->{'username'};
+    my $password = $options->{'password'};
+    my $protocol = $options->{'protocol'};
+
+    my $server = "$hostname:$port";
+    #$ENV{'fgsUserName'} = $options->{'username'};
+    #$ENV{'fgsPassword'} = $options->{'password'};    
+
+    #my $prog = &util::filename_cat($ENV{'FEDORA_GSEARCH'}, "runRESTClient.sh");
+    my $prog = &util::filename_cat($fedoragsearch_webapp, "client", "runRESTClient.sh");
+
+    my $gsearch_commands = "updateIndex deletePID";
+    my $arguments = "$server $gsearch_commands $pid";    
+
+    my $status = run_cmd($prog,$arguments,$verbosity);
+
+    return $status;
+}
+
+# runs fedora gsearch's runRESTClient.sh: updateIndex fromPID <PID>
+sub run_update_index
+{
+    my ($fedoragsearch_webapp,$pid,$options) = @_;
+
+    my $verbosity = $options->{'verbosity'};
+
+    my $hostname = $options->{'hostname'};
+    my $port     = $options->{'port'};
+    my $username = $options->{'username'};
+    my $password = $options->{'password'};
+    my $protocol = $options->{'protocol'};
+
+    my $server = "$hostname:$port";
+    #$ENV{'fgsUserName'} = $options->{'username'};
+    #$ENV{'fgsPassword'} = $options->{'password'};    
+
+    #my $prog = &util::filename_cat($ENV{'FEDORA_GSEARCH'}, "runRESTClient.sh");
+    my $prog = &util::filename_cat($fedoragsearch_webapp, "client", "runRESTClient.sh");
+    
+    my $gsearch_commands = "updateIndex fromPID";
+    my $arguments = "$server $gsearch_commands $pid";    
+
+    my $status = run_cmd($prog,$arguments,$verbosity);
+
+    return $status;
+}
+
+sub gsearch_webapp_folder
+{   
+    my $fedoragsearch_webapp = undef;
+    
+    # if GS3, first look for a fedoragsearch webapp installed in Greenstone's tomcat
+    if(defined $ENV{'GSDL3SRCHOME'}) {
+	$fedoragsearch_webapp = &util::filename_cat($ENV{'GSDL3SRCHOME'},"packages","tomcat","webapps","fedoragsearch");	
+	return $fedoragsearch_webapp if (&util::dir_exists($fedoragsearch_webapp));
+    }
+
+    # next look for a fedoragsearch webapp installed in Fedora's tomcat
+    if(defined $ENV{'FEDORA_HOME'}) {
+	$fedoragsearch_webapp =  &util::filename_cat($ENV{'FEDORA_HOME'},"tomcat","webapps","fedoragsearch");
+	return $fedoragsearch_webapp if (&util::dir_exists($fedoragsearch_webapp));
+    }
+
+    ## check for a user-defined $ENV{'FEDORA_GSEARCH'} variable first, which points to a gsearch webapp folder??
+
+    # assume no fedoragsearch
+    return $fedoragsearch_webapp; # undef
+}
+
 
 sub run_ingest
