Index: /gsdl/trunk/perllib/basebuilder.pm
===================================================================
--- /gsdl/trunk/perllib/basebuilder.pm	(revision 14933)
+++ /gsdl/trunk/perllib/basebuilder.pm	(revision 14934)
@@ -368,4 +368,6 @@
     $self->{'buildproc'}->zero_reset(); 
 
+    $self->{'buildproc'}->{'mdprefix_fields'} = {};
+
     if ($self->{'keepold'}) {
 	# create flat classify structure, ready for new docs to be added
@@ -377,9 +379,10 @@
 
    
+    &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'}, 
+		   "", {}, $self->{'buildproc'}, $self->{'maxdocs'},0, $self->{'gli'});
+
     # this has changed to only output collection meta if its 
     # not in the config file
     $self->output_collection_meta($handle);
-    &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'}, 
-		   "", {}, $self->{'buildproc'}, $self->{'maxdocs'},0, $self->{'gli'});
     
     # output classification information
@@ -562,10 +565,54 @@
 }
 
-# default is to output an empty [collection] entry
+
+
+sub output_collection_meta_start {
+    my $self = shift(@_);
+    my ($handle) = @_;
+    
+    print $handle "[collection]\n";
+
+}  
+
+sub output_collection_meta_sets {
+    my $self = shift(@_);
+    my ($handle) = @_;
+
+    my $mdprefix_fields = $self->{'buildproc'}->{'mdprefix_fields'};
+
+    foreach my $prefix (keys %$mdprefix_fields)
+    {
+	print $handle "<metadataset>$prefix\n";
+
+	foreach my $field (keys %{$mdprefix_fields->{$prefix}})
+	{
+	    my $val = $mdprefix_fields->{$prefix}->{$field};
+
+	    print $handle "<metadatalist-$prefix>$field\n";
+	    print $handle "<metadatafreq-$prefix-$field>$val\n";
+	}
+
+    }
+
+}  
+
+sub output_collection_meta_end {
+    my $self = shift(@_);
+    my ($handle) = @_;
+    
+    print $handle ('-' x 70) . "\n";;
+
+}  
+
+
+# default is to output the metadata sets (prefixes) used in collection
+
 sub output_collection_meta {
     my $self = shift(@_);
     my ($handle) = @_;
-    
-    print $handle "[collection]\n". ('-' x 70) . "\n";;
+
+    $self->output_collection_meta_start($handle);
+    $self->output_collection_meta_sets($handle);
+    $self->output_collection_meta_end($handle);
 
 }  
Index: /gsdl/trunk/perllib/basebuildproc.pm
===================================================================
--- /gsdl/trunk/perllib/basebuildproc.pm	(revision 14933)
+++ /gsdl/trunk/perllib/basebuildproc.pm	(revision 14934)
@@ -297,4 +297,34 @@
 }
 
+
+
+sub infodb_metadata_stats
+{
+    my $self = shift (@_);
+    my ($field) = @_;
+
+    # Keep some statistics relating to metadata sets used and
+    # frequency of particular metadata fields within each set
+
+    # Union of metadata prefixes and frequency of fields
+    # (both scoped for this document alone, and across whole collection)
+    
+    if ($field =~ m/^(.+)\.(.*)$/) {
+	my $prefix = $1;
+	my $core_field = $2;
+
+	$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}++;
+    }
+
+}
+
+
 sub infodb {
     my $self = shift (@_);
@@ -351,4 +381,7 @@
     my $first = 1;
     my $url = "";
+
+    $self->{'doc_mdprefix_fields'} = {};
+
     while (defined $section) {
 	# update a few statistics
@@ -412,8 +445,31 @@
 		if (!defined $self->{'dontgdbm'}->{$field}) {
 		    print $handle "<$field>$value\n";
+
+		    if ($section eq "")
+		    {
+			$self->infodb_metadata_stats($field);
+		    }
 		}
 	    }
 	}
 
+	if ($section eq "")
+	{
+	    my $doc_mdprefix_fields = $self->{'doc_mdprefix_fields'};
+
+	    foreach my $prefix (keys %$doc_mdprefix_fields)
+	    {
+		print $handle "<metadataset>$prefix\n";
+
+		foreach my $field (keys %{$doc_mdprefix_fields->{$prefix}})
+		{
+		    my $val = $doc_mdprefix_fields->{$prefix}->{$field};
+
+		    print $handle "<metadatalist-$prefix>$field\n";
+		    print $handle "<metadatafreq-$prefix-$field>$val\n";
+		}
+
+	    }
+	}
 
 	# If doc_obj reconstructed from GDBM file then no need to 
Index: /gsdl/trunk/perllib/lucenebuildproc.pm
===================================================================
--- /gsdl/trunk/perllib/lucenebuildproc.pm	(revision 14933)
+++ /gsdl/trunk/perllib/lucenebuildproc.pm	(revision 14934)
@@ -398,4 +398,9 @@
 # /** process() **/
 
+
+# Following methods seem to be no different to those defined in basebuildproc.pm
+# From inspection, it looks like these ones can be removed
+
+
 sub get_num_docs {
     my $self = shift (@_);
Index: /gsdl/trunk/perllib/mgppbuilder.pm
===================================================================
--- /gsdl/trunk/perllib/mgppbuilder.pm	(revision 14933)
+++ /gsdl/trunk/perllib/mgppbuilder.pm	(revision 14934)
@@ -634,6 +634,7 @@
 
     # do the collection info
-    print $handle "[collection]\n";
-    
+    $self->output_collection_meta_start($handle);
+    $self->output_collection_meta_sets($handle);
+
     # first do the collection meta stuff - everything without a dot
     my $collmetadefined = 0;
@@ -701,9 +702,7 @@
 	}
     }
-    print $handle $lang_entry;
-    # end the collection entry
-    print $handle "\n" . ('-' x 70) . "\n";        
-
-
+    print $handle "$lang_entry\n";
+
+    $self->output_collection_meta_end($handle);
 }
 
