Index: gsdl/trunk/perllib/basebuildproc.pm
===================================================================
--- gsdl/trunk/perllib/basebuildproc.pm	(revision 18463)
+++ gsdl/trunk/perllib/basebuildproc.pm	(revision 18469)
@@ -343,5 +343,5 @@
 {
     my $self = shift (@_);
-    my ($field) = @_;
+    my ($field,$edit_mode) = @_;
 
     # Keep some statistics relating to metadata sets used and
@@ -355,12 +355,28 @@
 	my $core_field = $2;
 
-	$self->{'doc_mdprefix_fields'}->{$prefix}->{$core_field}++;
-	$self->{'mdprefix_fields'}->{$prefix}->{$core_field}++;
+	if (($edit_mode eq "add") || ($edit_mode eq "reindex")) {
+	    $self->{'doc_mdprefix_fields'}->{$prefix}->{$core_field}++;
+	    $self->{'mdprefix_fields'}->{$prefix}->{$core_field}++;
+	}
+	else {
+	    # delete
+	    $self->{'doc_mdprefix_fields'}->{$prefix}->{$core_field}--;
+	    $self->{'mdprefix_fields'}->{$prefix}->{$core_field}--;
+	}
+
     }
     elsif ($field =~ m/^[[:upper:]]/) {
 	# implicit 'ex' metadata set
 
-	$self->{'doc_mdprefix_fields'}->{'ex'}->{$field}++;
-	$self->{'mdprefix_fields'}->{'ex'}->{$field}++;
+	if (($edit_mode eq "add") || ($edit_mode eq "reindex")) {
+
+	    $self->{'doc_mdprefix_fields'}->{'ex'}->{$field}++;
+	    $self->{'mdprefix_fields'}->{'ex'}->{$field}++;
+	}
+	else {
+	    # delete
+	    $self->{'doc_mdprefix_fields'}->{'ex'}->{$field}--;
+	    $self->{'mdprefix_fields'}->{'ex'}->{$field}--;
+	}
     }
 
@@ -425,5 +441,4 @@
 	# delete
 	$self->{'num_docs'} -= 1 unless ($doctype eq "classification");
-	return;
     }
 
@@ -448,6 +463,14 @@
 
 	# update a few statistics
-	$self->{'num_bytes'} += $doc_obj->get_text_length ($section);
-	$self->{'num_sections'} += 1 unless ($doctype eq "classification");
+	if (($edit_mode eq "add") || ($edit_mode eq "reindex")) {
+
+	    $self->{'num_bytes'} += $doc_obj->get_text_length ($section);
+	    $self->{'num_sections'} += 1 unless ($doctype eq "classification");
+	}
+	else {
+	    # delete
+	    $self->{'num_bytes'} -= $doc_obj->get_text_length ($section);
+	    $self->{'num_sections'} -= 1 unless ($doctype eq "classification");
+	}
 
 	# output the fact that this document is a document (unless doctype
@@ -488,5 +511,14 @@
 		# special case for URL metadata
 		if ($field =~ /^URL$/i) {
-		    &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $value, { 'section' => [ $section_OID ] });
+		    if (($edit_mode eq "add") || ($edit_mode eq "reindex")) {
+
+			&dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $value, { 'section' => [ $section_OID ] });
+		    }
+		    else {
+			# delete
+			&dbutil::delete_infodb_entry($self->{'infodbtype'}, $infodb_handle, $value);
+		    }
+
+		    
 		}
 
@@ -496,5 +528,5 @@
 		    if ($section eq "" && $self->{'store_metadata_coverage'} =~ /^true$/i)
 		    {
-			$self->infodb_metadata_stats($field);
+			$self->infodb_metadata_stats($field,$edit_mode);
 		    }
 		}
@@ -565,14 +597,35 @@
 	} 
 	
-	&dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $section_OID, \%section_infodb);
+	if (($edit_mode eq "add") || ($edit_mode eq "reindex")) {
+
+	    &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $section_OID, \%section_infodb);
+	}
+	else {
+	    # delete
+	    &dbutil::delete_infodb_entry($self->{'infodbtype'}, $infodb_handle, $section_OID);
+	}
+
 	
 	# output a database entry for the document number, except for Lucene (which no longer needs this information)
 	unless (ref($self) eq "lucenebuildproc")
 	{
-	    if ($self->{'db_level'} eq "document") {
-		&dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_docs'}, { 'section' => [ $doc_OID ] });
+	    if (($edit_mode eq "add") || ($edit_mode eq "reindex")) {
+		
+		if ($self->{'db_level'} eq "document") {
+		    &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_docs'}, { 'section' => [ $doc_OID ] });
+		}
+		else {
+		    &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_sections'}, { 'section' => [ $section_OID ] });
+		}
 	    }
 	    else {
-		&dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_sections'}, { 'section' => [ $section_OID ] });
+
+		if ($self->{'db_level'} eq "document") {
+		    &dbutil::delete_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_docs'});
+		}
+		else {
+		    &dbutil::delete_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_sections'});
+		}
+
 	    }
 	}
