Index: main/trunk/greenstone2/perllib/buildcolutils.pm
===================================================================
--- main/trunk/greenstone2/perllib/buildcolutils.pm	(revision 27562)
+++ main/trunk/greenstone2/perllib/buildcolutils.pm	(revision 27563)
@@ -404,4 +404,13 @@
   if ($self->{'sections_index_document_metadata'} !~ /^(never|always|unless_section_metadata_exists)$/) {
     $self->{'sections_index_document_metadata'} = 'never';
+  }
+
+  if ($self->{'sections_sort_on_document_metadata'} !~ /\S/ && defined $collectcfg->{'sections_sort_on_document_metadata'})
+  {
+    $self->{'sections_sort_on_document_metadata'} = $collectcfg->{'sections_sort_on_document_metadata'};
+  }
+
+  if ($self->{'sections_sort_on_document_metadata'} !~ /^(never|always|unless_section_metadata_exists)$/) {
+    $self->{'sections_sort_on_document_metadata'} = 'never';
   }
 
@@ -463,4 +472,5 @@
   my $remove_empty_classifications = $self->{'remove_empty_classifications'};
   my $sections_index_document_metadata = $self->{'sections_index_document_metadata'};
+  my $sections_sort_on_document_metadata = $self->{'sections_sort_on_document_metadata'};
   my $site        = $self->{'site'};
   my $store_metadata_coverage = $self->{'store_metadata_coverage'};
@@ -602,4 +612,8 @@
     {
       $this_builder->set_sections_index_document_metadata($sections_index_document_metadata);
+    }
+    if ($this_buildertype eq "lucenebuilder" && $sections_sort_on_document_metadata ne "never")
+    {
+      $this_builder->set_sections_sort_on_document_metadata($sections_sort_on_document_metadata);
     }
 
Index: main/trunk/greenstone2/perllib/colcfg.pm
===================================================================
--- main/trunk/greenstone2/perllib/colcfg.pm	(revision 27562)
+++ main/trunk/greenstone2/perllib/colcfg.pm	(revision 27563)
@@ -53,5 +53,6 @@
 # {'maxnumeric'}->string
 # {'separate_cjk'}->string
-# {'sections_index_document_metadata'}->string (always, unless_section_metadata_exists)
+# {'sections_index_document_metadata'}->string (never, always, unless_section_metadata_exists)
+# {'sections_sort_on_document_metadata'}->string (never, always, unless_section_metadata_exists)
 # {'languagemetadata'} -> string
 # {'maintainer'}->array of strings
@@ -180,5 +181,5 @@
 					q/sortmeta|removesuffix|removeprefix|create_images|/ .
 					q/maxnumeric|languagemetadata|/ .
-					q/no_strip_html|index|sections_index_document_metadata|/ .
+					q/no_strip_html|index|sections_index_document_metadata|sections_sort_on_document_metadata|/ .
 					q/store_metadata_coverage|indexname|indexlevel)$/,
 				    q/(maintainer|languages|indexsubcollections|orthogonalbuildtypes|/ .
@@ -202,5 +203,5 @@
 				 q/sortmeta|removesuffix|removeprefix|create_images|/ .
 				 q/maxnumeric|languagemetadata/ .
-				 q/no_strip_html|index|sections_index_document_metadata)$/.
+				 q/no_strip_html|index|sections_index_document_metadata|sections_sort_on_document_metadata)$/.
 			         q/store_metadata_coverage)$/,
 			     q/^(maintainer|languages|indexsubcollections|orthogonalbuildtypes|/ .
Index: main/trunk/greenstone2/perllib/lucenebuilder.pm
===================================================================
--- main/trunk/greenstone2/perllib/lucenebuilder.pm	(revision 27562)
+++ main/trunk/greenstone2/perllib/lucenebuilder.pm	(revision 27563)
@@ -92,4 +92,11 @@
 # /** new() **/
 
+sub set_sections_sort_on_document_metadata {
+    my $self = shift (@_);
+    my ($index) = @_;
+  
+    $self->{'buildproc'}->set_sections_sort_on_document_metadata($index);
+}
+
 sub is_incremental_capable
 {
Index: main/trunk/greenstone2/perllib/lucenebuildproc.pm
===================================================================
--- main/trunk/greenstone2/perllib/lucenebuildproc.pm	(revision 27562)
+++ main/trunk/greenstone2/perllib/lucenebuildproc.pm	(revision 27563)
@@ -78,4 +78,11 @@
 }
 
+sub set_sections_sort_on_document_metadata {
+    my $self= shift (@_);
+    my ($index_type) = @_;
+    
+    $self->{'sections_sort_on_document_metadata'} = $index_type;
+}
+
 sub set_sortfields {
     my $self = shift (@_);
@@ -360,4 +367,9 @@
 	    
 		my @section_metadata = @{$doc_obj->get_metadata ($section, $submeta)};
+		    if ($section ne $doc_obj->get_top_section() && defined ($self->{'sections_sort_on_document_metadata'})) {
+			if ($self->{'sections_sort_on_document_metadata'} eq "always" || ( scalar(@section_metadata) == 0 && $self->{'sections_sort_on_document_metadata'} eq "unless_section_metadata_exists")) {
+			    push (@section_metadata, @{$doc_obj->get_metadata ($doc_obj->get_top_section(), $submeta)});
+			}
+		    }
 		push (@metadata_list, @section_metadata);
 	    }
@@ -365,5 +377,5 @@
 	    foreach my $item (@metadata_list) {
 		&ghtml::htmlsafe($item);
-		$new_text .= "$item ";
+		$new_text .= "$item";
 	    }
 	    if ($new_text =~ /\S/) {
Index: main/trunk/greenstone2/perllib/strings.properties
===================================================================
--- main/trunk/greenstone2/perllib/strings.properties	(revision 27562)
+++ main/trunk/greenstone2/perllib/strings.properties	(revision 27563)
@@ -127,6 +127,7 @@
 buildcol.no_text:Don't store compressed text. This option is useful for minimizing the size of the built indexes if you intend always to display the original documents at run time (i.e. you won't be able to retrieve the compressed text version).
 
-buildcol.sections_index_document_metadata:Index document level metadata at section level
-buildcol.sections_index_document_metadata.never:Don't index any document metadata at section level.
+buildcol.sections_index_document_metadata:Add document level metadata at section level for indexing
+buildcol.sections_sort_on_document_metadata:(Lucene only) Add document level metadata at section level for sorting
+buildcol.sections_index_document_metadata.never:Don't add any document metadata at section level.
 buildcol.sections_index_document_metadata.always:Add all specified document level metadata even if section level metadata of that name exists.
 buildcol.sections_index_document_metadata.unless_section_metadata_exists:Only add document level metadata if no section level metadata of that name exists.
