--- ../terrier-2.2-orig/src/uk/ac/gla/terrier/applications/HadoopIndexing.java	2008-12-27 17:27:02.000000000 +0000
+++ src/uk/ac/gla/terrier/applications/HadoopIndexing.java	2009-01-22 23:11:22.000000000 +0000
@@ -35,6 +35,9 @@
 import org.apache.hadoop.mapred.FileOutputFormat;
 import org.apache.hadoop.mapred.JobClient;
 import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.JobID;
+import org.apache.hadoop.mapred.RunningJob;
+import org.apache.hadoop.mapred.TaskID;
 import org.apache.hadoop.mapred.lib.NullOutputFormat;
 import org.apache.log4j.Logger;
 
@@ -117,7 +120,7 @@
 		
 		if (args.length==2 && args[0].equals("-p")) 
 		{
-			logger.info("Partitioned Mode, "+Integer.parseInt(args[1])+" output indicies.");
+			logger.info("Partitioned Mode, "+Integer.parseInt(args[1])+" output indices.");
 			conf.setPartitionerClass(ByMapPartitioner.class);
 			conf.setNumReduceTasks(Integer.parseInt(args[1]));
 		} 
@@ -126,13 +129,34 @@
 			conf.setNumReduceTasks(1);
 		}
 
+		JobID jobId = null;
 		try{
-			JobClient.runJob(conf);
+			RunningJob rj = JobClient.runJob(conf);
+			jobId = rj.getID();
 		} catch (Exception e) { 
 			logger.error("Problem running job", e);
 		}
+		if (jobId != null)
+		{
+			deleteTaskFiles(ApplicationSetup.TERRIER_INDEX_PATH, jobId);
+		}
 		System.out.println("Time Taken = "+((System.currentTimeMillis()-time)/1000)+" seconds");
 		jf.close();
 	}
 
+	public static void deleteTaskFiles(String path, JobID job)
+	{
+		String[] fileNames = Files.list(path);
+		for(String filename : fileNames)
+		{
+			String periodParts[] = filename.split("\\.");
+			try{
+				TaskID tid = TaskID.forName(periodParts[0]);
+				if (tid.getJobID().compareTo(job) == 0)
+				{
+					Files.delete(path + "/" + filename); 
+				}
+			} catch (Exception e) {}
+		}	
+	}
 }
--- ../terrier-2.2-orig/src/uk/ac/gla/terrier/indexing/hadoop/Hadoop_BasicSinglePassIndexer.java	2008-12-27 17:27:02.000000000 +0000
+++ src/uk/ac/gla/terrier/indexing/hadoop/Hadoop_BasicSinglePassIndexer.java	2009-01-22 23:05:04.000000000 +0000
@@ -504,7 +504,7 @@
 
 	/** finishes the reduce step, by closing the lexicon and inverted file output,
  	  * building the lexicon hash and index, and merging the document indices created
-	  * by the map tasks. All temporary map-phase files are deleted and the output index finalised */
+	  * by the map tasks. The output index finalised */
 	protected void closeReduce() throws IOException {
 		
 		if (! reduceStarted)
@@ -540,15 +540,12 @@
 					+Index.getLastIndexLoadError());
 		}
 		this.mergeDocumentIndex(sourceIndices);
-		//4. close the map phase indices, and delete them
+		//4. close the map phase indices
 		for(Index i : sourceIndices)
 		{
 			String path = i.getPath();
 			String prefix = i.getPrefix();
 			i.close();
-			Files.delete(path + ApplicationSetup.FILE_SEPARATOR + prefix + ".runs");
-			Files.delete(path + ApplicationSetup.FILE_SEPARATOR + prefix + ApplicationSetup.DOC_INDEX_SUFFIX);
-			Files.delete(path + ApplicationSetup.FILE_SEPARATOR + prefix + ".properties");
 		}
 		//5. finalise the lexicon
 		int numTerms;

