Index: trunk/gsdl/perllib/mgppbuilder.pm
===================================================================
--- trunk/gsdl/perllib/mgppbuilder.pm	(revision 4810)
+++ trunk/gsdl/perllib/mgppbuilder.pm	(revision 4811)
@@ -48,4 +48,14 @@
 $maxdocsize = 12000;
 
+%level_map = ('document'=>'Doc',
+	      'section'=>'Sec',
+	      'paragraph'=>'Para',
+	      'Doc'=>'_textdocument_',
+	      'Sec'=>'_textsection_',
+	      'Para'=>'_textparagraph_');
+
+#$doc_level = "Doc";
+#$sec_level = "Sec";
+#$para_level = "Para";
 
 %wanted_index_files = ('td'=>1,
@@ -64,4 +74,5 @@
 # change this so a user can add their own ones in via a file or cfg
 #add AND, OR, NOT NEAR to this list - these cannot be used as field names
+#also add the level names (Doc, Sec, Para)
 %static_indexfield_map = ('Title'=>'TI',
 			  'TI'=>1,
@@ -89,5 +100,8 @@
 			  'OR'=>1,
 			  'NOT'=>1,
-			  'NEAR'=>1);
+			  'NEAR'=>1,
+			  'Doc'=>1,
+			  'Sec'=>1,
+			  'Para'=>1);
 
 sub new {
@@ -170,10 +184,25 @@
     # get the levels (Section, Paragraph) for indexing and compression
     $self->{'levels'} = {};
+    $self->{'levelorder'} = ();
     if (defined $self->{'collect_cfg'}->{'levels'}) {
         foreach $level ( @{$self->{'collect_cfg'}->{'levels'}} ){
+	    $level =~ tr/A-Z/a-z/;
             $self->{'levels'}->{$level} = 1;
+	    push (@{$self->{'levelorder'}}, $level);
         }
-    }  
-
+    } else { # default to document
+	$self->{'levels'}->{'document'} = 1;
+	push (@{$self->{'levelorder'}}, 'document');
+    }
+    
+    $self->{'doc_level'} = "document";
+    if (! $self->{'levels'}->{'document'}) {
+	if ($self->{'levels'}->{'section'}) {
+	    $self->{'doc_level'} = "section";
+	} else {
+	    die "you must have either document or section level specified!!\n";
+	}
+    }
+    print $outhandle "doclevel = ". $self->{'doc_level'}."\n";
     # get the list of plugins for this collection
     my $plugins = [];
@@ -274,10 +303,14 @@
 
 
-    # define the section names for mgpasses
+    # define the section names and possibly the doc name for mgpasses
     # the compressor doesn't need to know about paragraphs - never want to 
     # retrieve them
     my $mgpp_passes_sections = "";
-    if ($self->{'levels'}->{'Section'}) {
-	$mgpp_passes_sections .= "-K Section ";
+    my ($doc_level) = $self->{'doc_level'};
+    $mgpp_passes_sections .= "-J " . %level_map->{$doc_level};
+    foreach $level (keys %{$self->{'levels'}}) {
+	if ($level ne $doc_level && $level ne "paragraph") {
+	    $mgpp_passes_sections .= "-K " . %level_map->{$level};
+	}
     }
 	
@@ -543,8 +576,12 @@
 
     # define the section names for mgpasses
+    # define the section names and possibly the doc name for mgpasses
     my $mgpp_passes_sections = "";
-    foreach $level (keys (%{$self->{'levels'}})) {
-	if ($level eq "Section" || $level eq "Paragraph") {
-	    $mgpp_passes_sections .= "-K $level ";
+    my ($doc_level) = $self->{'doc_level'};
+    $mgpp_passes_sections .= "-J " . %level_map->{$doc_level} ." ";
+    
+    foreach $level (keys %{$self->{'levels'}}) {
+	if ($level ne $doc_level) {
+	    $mgpp_passes_sections .= "-K " . %level_map->{$level}. " ";
 	}
     }
@@ -773,5 +810,5 @@
 	} # foreach collmeta key
     }
-    #add the indexfieldmap macros to [collection]
+    #add the index field macros to [collection]
     # eg <TI>Title
     #    <SU>Subject
@@ -779,5 +816,4 @@
     $field_entry="";
     foreach $longfield (@{$self->{'build_cfg'}->{'indexfields'}}){
-	print $outhandle "doing long field $longfield\n";
 	$shortfield = $self->{'buildproc'}->{'indexfieldmap'}->{$longfield};
 	next if $shortfield eq 1;
@@ -786,5 +822,4 @@
 	my $collmeta = ".$longfield";
 	if ($collmetadefined && defined $self->{'collect_cfg'}->{'collectionmeta'}->{$collmeta}) {
-	    print $outhandle "coll meta $collmeta defined\n";
 	    $metadata_entry = $self->create_language_db_map($collmeta, $shortfield);
 	    $field_entry .= $metadata_entry;
@@ -801,4 +836,19 @@
     print $handle $field_entry;
     
+    # now add the level names
+    $level_entry = "";
+    foreach $level (@{$self->{'collect_cfg'}->{'levels'}}) {
+	my $collmeta = ".$level"; # based on the original specification
+	$level =~ tr/A-Z/a-z/; # make it lower case
+	my $levelid = %level_map->{$level}; # find the actual value we used in the index
+	if ($collmetadefined && defined $self->{'collect_cfg'}->{'collectionmeta'}->{$collmeta}) {
+	    $metadata_entry = $self->create_language_db_map($collmeta, $levelid);
+	    $level_entry .= $metadata_entry;
+	} else {
+	    # use the default macro
+	    $level_entry .= "<$levelid>" . %level_map->{$levelid} . "\n";
+	}
+    }
+    print $handle $level_entry;
     #end the collection entry
     print $handle "\n" . ('-' x 70) . "\n";
@@ -835,13 +885,10 @@
     my $metadata_entry = "";
     my $default="";
-    print $outhandle "crate for meta $metaname\n";
     #iterate through the languages
     foreach $lang (keys (%{$self->{'collect_cfg'}->{'collectionmeta'}->{$metaname}})) {
-	print $outhandle "lang=$lang\n";
 	if ($first) {
 	    $first=0;
 	    #set the default default to the first entry
 	    $default=$self->{'collect_cfg'}->{'collectionmeta'}->{$metaname}->{$lang};
-	    print $outhandle "defualt = $default\n";
 	}
 	if ($lang =~ /default/) {
@@ -983,4 +1030,16 @@
     $build_cfg->{'buildtype'} = "mgpp"; #do we need this??
     
+    # store the level info
+    my @indexlevels = ();
+    foreach $l (@{$self->{'levelorder'}}) {
+	push (@indexlevels, %level_map->{$l});
+    }
+    $build_cfg->{'indexlevels'} = \@indexlevels;
+    
+    if ($self->{'levels'}->{'section'}) {
+	$build_cfg->{'textlevel'} = %level_map->{'section'};
+    } else {	
+	$build_cfg->{'textlevel'} = %level_map->{'document'};
+    }
     # store the number of documents and number of bytes
     $build_cfg->{'numdocs'} = $self->{'buildproc'}->get_num_docs();
@@ -1012,6 +1071,6 @@
     # write out the build information
     &cfgread::write_cfg_file("$self->{'build_dir'}/build.cfg", $build_cfg,
-			     '^(builddate|buildtype|numdocs|numbytes)$', 
-                             '^(indexmap|subcollectionmap|languagemap|indexfieldmap|notbuilt|indexfields)$');
+			     '^(builddate|buildtype|numdocs|numbytes|textlevel)$', 
+                             '^(indexmap|subcollectionmap|languagemap|indexfieldmap|notbuilt|indexfields|indexlevels)$');
     
 }
Index: trunk/gsdl/perllib/mgppbuildproc.pm
===================================================================
--- trunk/gsdl/perllib/mgppbuildproc.pm	(revision 4810)
+++ trunk/gsdl/perllib/mgppbuildproc.pm	(revision 4811)
@@ -42,4 +42,8 @@
 }
 
+#this must be the same as in mgppbuilder
+%level_map = ('document'=>'Doc',
+	      'section'=>'Sec',
+	      'paragraph'=>'Para');
 
 sub new {
@@ -298,5 +302,5 @@
     #level not Section
     my $docs_only = 1;
-    if ($self->{'levels'}->{'Section'}) {
+    if ($self->{'levels'}->{'section'}) {
 	$docs_only = 0;
     }
@@ -543,20 +547,21 @@
     my ($documenttag) = "";
     my($documentendtag) = "";
-    #if ($self->{'levels'}->{'Document'}) {
-	$documenttag = "\n<Document>\n";
-	$documentendtag = "</Document>\n";
-    #}
+    if ($self->{'levels'}->{'document'}) {
+	$documenttag = "\n<". %level_map->{'document'} . ">\n";
+	$documentendtag = "\n</". %level_map->{'document'} . ">\n";
+    }
     my ($sectiontag) = "";
-    if ($self->{'levels'}->{'Section'}) {
-	$sectiontag = "\n<Section>\n";
+    if ($self->{'levels'}->{'section'}) {
+	$sectiontag = "\n<". %level_map->{'section'} . ">\n";
     }
     my ($paratag) = "";
-    if ($self->{'levels'}->{'Paragraph'}) {
+    if ($self->{'levels'}->{'paragraph'}) {
 	if ($self->{'strip_html'}) {
-	    $paratag = "<Paragraph>";
+	    $paratag = "<". %level_map->{'paragraph'} . ">";
 	} else {
 	    print $outhandle "Paragraph level can not be used with no_strip_html!. Not indexing Paragraphs.\n";
 	}
     }
+
     my $doc_section = 0; # just for this document
     
