Index: /main/trunk/greenstone2/perllib/mgbuilder.pm
===================================================================
--- /main/trunk/greenstone2/perllib/mgbuilder.pm	(revision 28120)
+++ /main/trunk/greenstone2/perllib/mgbuilder.pm	(revision 28121)
@@ -205,5 +205,11 @@
 	    die "mgbuilder::compress_text - couldn't run $mg_compression_dict_exe\n";
 	}
-	system ("mg_compression_dict$exe -f \"$fulltextprefix\" -S -H -2 -k 5120 $osextra");
+	my $comp_dict_status = system ("mg_compression_dict$exe -f \"$fulltextprefix\" -S -H -2 -k 5120 $osextra");
+	if($comp_dict_status != 0) {
+	    print $outhandle "\nmgbuilder::compress_text - Warning: there's no compressed text\n";
+	    $self->{'notbuilt'}->{'compressedtext'} = 1;
+	    print STDERR "<Warning name='NoCompressedText'/>\n</Stage>\n" if $self->{'gli'};
+	    return;
+	}
 
 	# -b $maxdocsize sets the maximum document size to be 12 meg
@@ -456,4 +462,12 @@
 	my $hash_status = system ($hash_cmd);
 	print $outhandle "\nstatus from running hash_cmd: $hash_status\n" if ($self->{'verbosity'} >= 4);
+	# check that perf hash was generated - if not, don't carry on
+	if ($hash_status !=0) {
+	    print $outhandle "mgbuilder::build_index - Couldn't create index $index as there are too few words in the index.\n";
+	    print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
+	    $self->{'notbuilt'}->{$index}=1;
+	    return;
+	    
+	}
 
 	if (!-e "$mg_passes_exe" || 
@@ -493,5 +507,13 @@
 	my $weights_cmd = "mg_weights_build$exe -f \"$fullindexprefix\" -t \"$fulltextprefix\" $osextra";
 	print $outhandle "\ncmd: $weights_cmd\n" if ($self->{'verbosity'} >= 4);
-	system ($weights_cmd);
+	my $weights_status = system ($weights_cmd);
+	# check that it worked - if not, don't carry on
+	if ($weights_status !=0) {
+	    print $outhandle "mgbuilder::build_index - No Index: couldn't create weights file, error calling mg_weights_build.\n";
+	    print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
+	    $self->{'notbuilt'}->{$index}=1;
+	    return;
+	    
+	}
 
 	# create 'on-disk' stemmed dictionary
@@ -502,6 +524,13 @@
 	    die "mgbuilder::build_index - couldn't run $mg_invf_dict_exe\n";
 	}
-	system ("mg_invf_dict$exe -f \"$fullindexprefix\" $osextra");
-
+	my $invdict_status = system ("mg_invf_dict$exe -f \"$fullindexprefix\" $osextra");
+	# check that it worked - if not, don't carry on
+	if ($invdict_status !=0) {
+	    print $outhandle "mgbuilder::build_index - No Index: couldn't create on-disk stemmed dictionary, error calling mg_invf_dict.\n";
+	    print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
+	    $self->{'notbuilt'}->{$index}=1;
+	    return;
+	    
+	}
 
 	# creates stem index files for the various stemming methods
@@ -515,12 +544,31 @@
 	# so we generate them whatever, but don't advertise the fact
 	#if ($self->{'casefold'}) {
-	system ("mg_stem_idx$exe -b 4096 -s1 -f \"$fullindexprefix\" $osextra");
+#	system ("mg_stem_idx$exe -b 4096 -s1 -f \"$fullindexprefix\" $osextra");
 	#}
 	#if ($self->{'stem'}) {
-	system ("mg_stem_idx$exe -b 4096 -s2 -f \"$fullindexprefix\" $osextra");
+#	system ("mg_stem_idx$exe -b 4096 -s2 -f \"$fullindexprefix\" $osextra");
 	#}
 	#if ($self->{'casefold'} && $self->{'stem'}) {
-	system ("mg_stem_idx$exe -b 4096 -s3 -f \"$fullindexprefix\" $osextra");
+#	system ("mg_stem_idx$exe -b 4096 -s3 -f \"$fullindexprefix\" $osextra");
 	#}
+
+	# same as above: generate all the stem idexes. But don't bother stemming if
+	# casefolding failed, and don't try generating indexes for both if stemming failed
+	my $stem_index_status = system ("mg_stem_idx$exe -b 4096 -s1 -f \"$fullindexprefix\" $osextra");
+	if($stem_index_status != 0) {
+	    print $outhandle "\nCase folding failed: mg_stem_idx exit status $stem_index_status\n" if ($self->{'verbosity'} >= 4);
+	} else {
+	    $stem_index_status = system ("mg_stem_idx$exe -b 4096 -s2 -f \"$fullindexprefix\" $osextra");
+
+	    if($stem_index_status != 0) {
+		print $outhandle "\nStemming failed: mg_stem_idx exit status $stem_index_status\n" if ($self->{'verbosity'} >= 4);
+	    } else {
+		$stem_index_status = system ("mg_stem_idx$exe -b 4096 -s3 -f \"$fullindexprefix\" $osextra");
+
+		if($stem_index_status != 0) {
+		    print $outhandle "\nCasefolding and stemming failed: mg_stem_idx exit status $stem_index_status\n" if ($self->{'verbosity'} >= 4);
+		}
+	    }
+	}
 
 	# remove unwanted files
Index: /main/trunk/greenstone2/perllib/mgppbuilder.pm
===================================================================
--- /main/trunk/greenstone2/perllib/mgppbuilder.pm	(revision 28120)
+++ /main/trunk/greenstone2/perllib/mgppbuilder.pm	(revision 28121)
@@ -573,5 +573,5 @@
 	# check that it worked - if not, don't carry on
 	if ($weights_status !=0) {
-	    print $outhandle "mgppbuilder::build_index - No Index: couldn't create weights file, error calling mggp_weights_build.\n";
+	    print $outhandle "mgppbuilder::build_index - No Index: couldn't create weights file, error calling mgpp_weights_build.\n";
 	    print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
 	    $self->{'notbuilt'}->{$index}=1;
@@ -589,5 +589,5 @@
 	# check that it worked - if not, don't carry on
 	if ($invdict_status !=0) {
-	    print $outhandle "mgppbuilder::build_index - No Index: couldn't create on-disk stemmed dictionary, error calling mggp_invf_dict.\n";
+	    print $outhandle "mgppbuilder::build_index - No Index: couldn't create on-disk stemmed dictionary, error calling mgpp_invf_dict.\n";
 	    print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
 	    $self->{'notbuilt'}->{$index}=1;
