Index: /trunk/gsdl/perllib/cfgread.pm
===================================================================
--- /trunk/gsdl/perllib/cfgread.pm	(revision 68)
+++ /trunk/gsdl/perllib/cfgread.pm	(revision 69)
@@ -28,5 +28,5 @@
 #   '^(this|that)$'
 sub read_cfg_file {
-    my ($filename, $stringexp, $arrayexp) = @_;
+    my ($filename, $stringexp, $arrayexp, $hashexp) = @_;
     my ($line);
     my $data = {};
@@ -41,4 +41,9 @@
 		} elsif ($key =~ /$arrayexp/) {
 		    push (@{$data->{$key}}, @$line);
+
+		} elsif ($key =~ /$hashexp/) {
+		    my $k = shift @$line;
+		    my $v = shift @$line;
+		    $data->{$key}->{$k} = $v;
 		}
 	    }
@@ -56,5 +61,5 @@
 #   '^(this|that)$'
 sub write_cfg_file {
-    my ($filename, $data, $stringexp, $arrayexp) = @_;
+    my ($filename, $data, $stringexp, $arrayexp, $hashexp) = @_;
 
     if (open (COLCFG, ">$filename")) {
@@ -64,4 +69,8 @@
 	    } elsif ($key =~ /$arrayexp/) {
 		&write_cfg_line ('COLCFG', [$key, @{$data->{$key}}]);
+	    } elsif ($key =~ /$hashexp/) {
+		foreach $k (keys (%{$data->{$key}})) {
+		    &write_cfg_line ('COLCFG', [$key, $k, $data->{$key}->{$k}]);
+		}
 	    }
 	}
Index: /trunk/gsdl/perllib/colcfg.pm
===================================================================
--- /trunk/gsdl/perllib/colcfg.pm	(revision 68)
+++ /trunk/gsdl/perllib/colcfg.pm	(revision 69)
@@ -13,4 +13,6 @@
 # {'beta'}->string
 # {'key'}->string
+# {'subcollection'}->hash of key-value pairs
+# {'indexsubcollections'}->array of strings
 # {'indexes'}->array of strings
 # {'defaultindex'}->string
@@ -22,5 +24,6 @@
     return &cfgread::read_cfg_file ($filename, 
 		    '^(creator|public|beta|key|defaultindex)$', 
-		    '^(maintainer|indexes|plugins)$');
+		    '^(maintainer|indexsubcollections|indexes|plugins)$',
+		    '^(subcollection)$');
 }
 
@@ -30,5 +33,6 @@
     &cfgread::write_cfg_file($filename, $data,
 		    '^(creator|public|beta|key|defaultindex)$', 
-		    '^(maintainer|indexes|plugins)$');
+		    '^(maintainer|subcollection|indexsubcollections|indexes|plugins)$',
+		    '^(subcollection)$');
 }
 
Index: /trunk/gsdl/perllib/mgbuilder.pm
===================================================================
--- /trunk/gsdl/perllib/mgbuilder.pm	(revision 68)
+++ /trunk/gsdl/perllib/mgbuilder.pm	(revision 69)
@@ -41,4 +41,15 @@
 
 
+    # sort out subcollection indexes
+    if (defined $self->{'collect_cfg'}->{'indexsubcollections'}) {
+	my $indexes = $self->{'collect_cfg'}->{'indexes'};
+	$self->{'collect_cfg'}->{'indexes'} = [];
+	foreach $subcollection (@{$self->{'collect_cfg'}->{'indexsubcollections'}}) {
+	    foreach $index (@$indexes) {
+		push (@{$self->{'collect_cfg'}->{'indexes'}}, "$index:$subcollection");
+	    }
+	}
+    }
+
     # get the list of plugins for this collection
     my @plugins = (); # some good choice of plugins .... ????
@@ -177,6 +188,6 @@
     
     foreach $index (@$indexes) {
-	my ($level, $fields) = split (":", $index);
-	my @fields = split (",", $fields);
+	my ($level, $fields, $subcollection) = split (":", $index);
+	my @fields = split (/,/, $fields);
 	splice (@fields, 2); # just want first two fields
 	
@@ -189,4 +200,20 @@
 	map {s/^(.).*?([bcdfghjklmnpqrstvwxyz]).*$/$1$2/i;} @fields;
 	$dirname .= join("", @fields);
+
+	# next comes a processed version of the subcollection if there is one.
+	# the processed version contains the first character and the next
+	# consonant if there's only one field, other wise the first character
+	# of the first two fields
+	if (defined ($subcollection) && $subcollection =~ /\w/) {
+	    @fields = split /,/, $subcollection;
+	    if (scalar @fields >= 2) {
+		splice (@fields, 2);
+		map {s/^(.).*$/$1/i;} @fields;
+		$dirname .= join("", @fields);
+	    } else {
+		$subcollection =~ s/^(.).*?([bcdfghjklmnpqrstvwxyz]).*$/$1$2/i;
+		$dirname .= $subcollection;
+	    }
+	}
 
 	# convert the directory name to lowercase
@@ -238,8 +265,20 @@
     $index_level = 3 if $index =~ /^paragraph/i;
 
+    # get the index expression if this index belongs
+    # to a subcollection
+    my $indexexparr = [];
+    my ($level, $fields, $subcollection) = split (":", $index);
+    my (@subcollections) = split /,/, $subcollection;
+
+    foreach $subcollection (@subcollections) {
+	if (defined ($self->{'collect_cfg'}->{'subcollection'}->{$subcollection})) {
+	    push (@$indexexparr, $self->{'collect_cfg'}->{'subcollection'}->{$subcollection});
+	} 
+    }
+    
     # set up the document processor
     $self->{'buildproc'}->set_output_handle ('mgbuilder::PIPEOUT');
     $self->{'buildproc'}->set_mode ('text');
-    $self->{'buildproc'}->set_index ($index);
+    $self->{'buildproc'}->set_index ($index, $indexexparr);
 
 
Index: /trunk/gsdl/perllib/mgbuildproc.pm
===================================================================
--- /trunk/gsdl/perllib/mgbuildproc.pm	(revision 68)
+++ /trunk/gsdl/perllib/mgbuildproc.pm	(revision 69)
@@ -24,4 +24,5 @@
     $self->{'mode'} = "text";
     $self->{'index'} = "section:text";
+    $self->{'indexexparr'} = [];
     $self->{'output_handle'} = "STDOUT";
     $self->{'num_docs'} = 0;
@@ -74,7 +75,8 @@
 sub set_index {
     my $self = shift (@_);
-    my ($index) = @_;
+    my ($index, $indexexparr) = @_;
 
     $self->{'index'} = $index;
+    $self->{'indexexparr'} = $indexexparr if defined $indexexparr;
 }
 
@@ -391,7 +393,37 @@
     my ($doc_obj) = @_;
     my $handle = $self->{'output_handle'};
+    my $indexed_doc = 1;
 
     # only output this document if it is one to be indexed
     return if ($doc_obj->get_doc_type() ne "indexed_doc");
+
+    # see if this document belongs to this subcollection
+    foreach $indexexp (@{$self->{'indexexparr'}}) {
+	$indexed_doc = 0;
+	my ($field, $exp, $options) = split /\//, $indexexp;
+	if (defined ($field) && defined ($exp)) {
+	    my ($bool) = $field =~ /^(.)/;
+	    $field =~ s/^.// if $bool eq '!';
+	    if ($field eq "filename") {
+		$field = $doc_obj->get_source_filename();
+	    } else {
+		$field = $doc_obj->get_metadata_element($doc_obj->get_top_section(), $field);
+	    }
+	    next unless defined $field;
+	    if ($bool eq '!') {
+		if ($options =~ /^i$/i) {
+		    if ($field !~ /$exp/i) {$indexed_doc = 1; last;}
+		} else {
+		    if ($field !~ /$exp/) {$indexed_doc = 1; last;}
+		}
+	    } else {
+		if ($options =~ /^i$/i) {
+		    if ($field =~ /$exp/i) {$indexed_doc = 1; last;}
+		} else {
+		    if ($field =~ /$exp/) {$indexed_doc = 1; last;}
+		}
+	    }
+	}
+    }
 
     # this is another document
@@ -412,23 +444,25 @@
 	# update a few statistics
 	$doc_section++;
-	$self->{'num_bytes'} += $doc_obj->get_text_length ($section);
 	$self->{'num_sections'} += 1;
-	
-	foreach $field (split (/,/, $fields)) {
-	    # only deal with this field if it doesn't start with top or
-	    # this is the first section
-	    my $real_field = $field;
-	    if (!($real_field =~ s/^top//) || ($doc_section == 1)) {
-		my $new_text = "";
-		if ($real_field eq "text") {
-		    $new_text = $doc_obj->get_text ($section);
-		    $new_text =~ s/[\cB\cC]//g;
-		    $new_text =~ s/(<p\b)/\cC$1/gi;
+
+	if ($indexed_doc) {
+	    $self->{'num_bytes'} += $doc_obj->get_text_length ($section);
+	    foreach $field (split (/,/, $fields)) {
+		# only deal with this field if it doesn't start with top or
+		# this is the first section
+		my $real_field = $field;
+		if (!($real_field =~ s/^top//) || ($doc_section == 1)) {
+		    my $new_text = "";
+		    if ($real_field eq "text") {
+			$new_text = $doc_obj->get_text ($section);
+			$new_text =~ s/[\cB\cC]//g;
+			$new_text =~ s/(<p\b)/\cC$1/gi;
+			
+		    } else {
+			$new_text = join ("\cC", @{$doc_obj->get_metadata ($section, $real_field)});
+		    }
 		    
-		} else {
-		    $new_text = join ("\cC", @{$doc_obj->get_metadata ($section, $real_field)});
-		}
-	    
-		$text .= "$new_text\cC";
+		    $text .= "$new_text\cC";
+		}
 	    }
 	}
