Index: trunk/gsdl3/bin/script/convert_coll_from_gs2.pl
===================================================================
--- trunk/gsdl3/bin/script/convert_coll_from_gs2.pl	(revision 13843)
+++ trunk/gsdl3/bin/script/convert_coll_from_gs2.pl	(revision 13912)
@@ -175,12 +175,20 @@
     
     #indexes
+    # maps index name to shortname
     my $indexmap = {};
+    # keeps the order for indexes
+    my @indexlist = ();
     my $firstindex = "";
     my $first = 1;
-    if (defined $buildcfg->{'indexmap'}) {
-	my $indexmap_t = $buildcfg->{'indexmap'};
+    my $maptype = "indexfieldmap";
+    if ($buildtype eq "mg") {
+	$maptype = "indexmap";
+    }
+    if (defined $buildcfg->{$maptype}) {
+	my $indexmap_t = $buildcfg->{$maptype};
 	foreach my $i (@$indexmap_t) {
 	    my ($k, $v) = $i =~ /^(.*)\-\>(.*)$/;
 	    $indexmap->{$k} = $v;
+	    push @indexlist, $k;
 	    if ($first) {
 		$firstindex = $v;
@@ -189,22 +197,14 @@
 	}
     } else {
-	print STDERR "indexmap not defined";
-    }
+	print STDERR "$maptype not defined";
+    }
+    # we use the shortname for default index
     my $defaultindex;
-    if ($buildtype eq "mg") {
-	if (defined $collectcfg->{'defaultindex'}) {
-	    $defaultindex = $collectcfg->{'defaultindex'};
-	    $defaultindex = $indexmap->{$defaultindex};
-	} else {
-	    # use the first one
-	    $defaultindex = $firstindex;
-	}
-    } 
-    elsif ($buildtype eq "mgpp") {
-	$defaultindex = "idx";
-    }
-    elsif ($buildtype eq "lucene") {
-	# lucene not implemented yet
-	$defaultindex = "idx";
+    if (defined $collectcfg->{'defaultindex'}) {
+	$defaultindex = $collectcfg->{'defaultindex'};
+	$defaultindex = $indexmap->{$defaultindex};
+    } else {
+	# use the first one
+	$defaultindex = $firstindex;
     }
     
@@ -215,6 +215,5 @@
     $collwriter->startTag('search');
     foreach my $i (keys %$indexmap) {
-	my $shortname = $indexmap->{$i};
-	$collwriter->startTag('index', 'name'=>$shortname);
+	$collwriter->startTag('index', 'name'=>$i);
 	#find the coll meta stuff
 	my $indexdisplay = ".$i";
@@ -224,5 +223,4 @@
 	}
 	$collwriter->endTag('index');
-	
     }
 
@@ -246,5 +244,11 @@
     my @levels = ();
     my $defaultlevel;
-    my $service_name = "";
+    my $service_type = "MG";
+    if ($buildtype eq 'mgpp') {
+	$service_type = "MGPP";
+    } elsif ($buildtype eq "lucene") {
+	$service_type = "Lucene";
+    }
+
     #do the retrieve service
     # assume mgpp or mg 
@@ -271,10 +275,5 @@
 	    }
 	}
-	if ($buildtype eq 'mgpp') {
-	    $service_name = "MGPP";
-	} else {
-	    $service_name = "Lucene";
-	}
-	$buildwriter->startTag('serviceRack', 'name'=>"GS2".$service_name."Retrieve");
+	$buildwriter->startTag('serviceRack', 'name'=>"GS2".$service_type."Retrieve");
 	$buildwriter->emptyTag('defaultLevel', 'name'=>$defaultlevel);
 
@@ -282,5 +281,5 @@
     } elsif ($buildtype eq "mg") {
 	$buildwriter->startTag('serviceRack', 'name'=>'GS2MGRetrieve');
-	$buildwriter->emptyTag('defaultIndex', 'name'=>$defaultindex);
+	$buildwriter->emptyTag('defaultIndex', 'shortname'=>$defaultindex);
 	
     }
@@ -399,7 +398,38 @@
    
     # do the search service
+    $buildwriter->startTag('serviceRack', 'name'=>'GS2'.$service_type.'Search');
+    $buildwriter->emptyTag('defaultIndex', 'shortname'=>$defaultindex);
+    $buildwriter->startTag('indexList');
+    #for each index
+    foreach my $i (@indexlist) {
+	my $index = $indexmap->{$i};
+	$buildwriter->emptyTag('index', 'name'=>$i, 'shortname'=>$index);
+    }	
+    $buildwriter->endTag('indexList');
+    if (defined $indexstem) {
+	$buildwriter->emptyTag('indexStem', 'name'=>$indexstem);
+    } 
+    
+    # index options
+    if ($buildtype eq 'mg' || $buildtype eq 'mgpp') {
+	$buildwriter->startTag('indexOptionList');
+	my $stemindexes = 3; # default is stem and casefold
+	if (defined $buildcfg->{'stemindexes'} && $buildcfg->{'stemindexes'} =~ /^\d+$/ ) {
+	    $stemindexes = $buildcfg->{'stemindexes'};
+	}
+	$buildwriter->emptyTag('indexOption', 'name'=>'stemIndexes', 'value'=>$stemindexes);
+	
+	my $maxnumeric = 4; # default
+	if (defined $buildcfg->{'maxnumeric'} && $buildcfg->{'maxnumeric'} =~ /^\d+$/) {
+	    $maxnumeric = $buildcfg->{'maxnumeric'};
+	}
+	$buildwriter->emptyTag('indexOption', 'name'=>'maxnumeric', 'value'=>$maxnumeric);
+	
+	$buildwriter->endTag('indexOptionList');
+    }
+
     if ($buildtype eq 'mgpp' || $buildtype eq 'lucene') {
 		
-	$buildwriter->startTag('serviceRack', 'name'=>'GS2'.$service_name.'Search');
+	# level info
 	$buildwriter->emptyTag('defaultLevel', 'name'=>$defaultlevel);
 	$buildwriter->startTag('levelList');
@@ -409,26 +439,4 @@
 	$buildwriter->endTag('levelList');
 	
-	#fieldlist
-	my $fieldmap = {};
-	my $fieldlist = ();
-	if (defined $buildcfg->{'indexfields'}) {
-	    push @$fieldlist, @{$buildcfg->{'indexfields'}};
-	    if (defined $buildcfg->{'indexfieldmap'}) {
-		my $fieldmap_t = $buildcfg->{'indexfieldmap'};
-		foreach my $f (@$fieldmap_t) {
-		    my ($k, $v) = $f =~ /^(.*)\-\>(.*)$/;
-		    $fieldmap->{$k} = $v;
-		}
-	    }
-	    $buildwriter->startTag('fieldList');
-	    foreach my $f (@$fieldlist) {
-		my $field = $fieldmap->{$f};
-		$buildwriter->emptyTag('field', 'shortname'=>$field, 'name'=>$f);
-	    }	
-	    $buildwriter->endTag('fieldList');
-	} else {
-	    print STDERR "indexfieldmap not defined";
-	}
-
 	# do the search types if there
 	if (defined $collectcfg->{'searchtype'}) {
@@ -450,37 +458,7 @@
 	    $buildwriter->endTag('searchTypeList');
 	}
-    } elsif ($buildtype eq 'mg') {
-	$buildwriter->startTag('serviceRack', 'name'=>'GS2MGSearch');
-    }
-    
-    if (defined $indexstem) {
-	$buildwriter->emptyTag('indexStem', 'name'=>$indexstem);
     } 
-
-    # index options
-    if ($buildtype eq 'mg' || $buildtype eq 'mgpp') {
-	$buildwriter->startTag('indexOptionList');
-	my $stemindexes = 3; # default is stem and casefold
-	if (defined $buildcfg->{'stemindexes'} && $buildcfg->{'stemindexes'} =~ /^\d+$/ ) {
-	    $stemindexes = $buildcfg->{'stemindexes'};
-	}
-	$buildwriter->emptyTag('indexOption', 'name'=>'stemIndexes', 'value'=>$stemindexes);
-	
-	my $maxnumeric = 4; # default
-	if (defined $buildcfg->{'maxnumeric'} && $buildcfg->{'maxnumeric'} =~ /^\d+$/) {
-	    $maxnumeric = $buildcfg->{'maxnumeric'};
-	}
-	$buildwriter->emptyTag('indexOption', 'name'=>'maxnumeric', 'value'=>$maxnumeric);
-	
-	$buildwriter->endTag('indexOptionList');
-    }
-    $buildwriter->emptyTag('defaultIndex', 'name'=>$defaultindex);
-    $buildwriter->startTag('indexList');
-    #for each index
-    foreach my $i (keys %$indexmap) {
-	my $index = $indexmap->{$i};
-	$buildwriter->emptyTag('index', 'name'=>$index);
-    }	
-    $buildwriter->endTag('indexList');
+    
+
     
     $buildwriter->endTag('serviceRack');
