static void BuildIndex(String datafile, int mode) throws Throwable {
		
		//init the index
		for(int i = 0;i < num_ip; i++)
			jclient.initServer(i, Index.BUILD);
		
		BufferedReader buf = new BufferedReader(new InputStreamReader(new FileInputStream(datafile)));
		String line;	
		int id = 0;
		while ((line = buf.readLine()) != null) {
			//for insertion the key is elementID
			strKey strkey = new strKey(String.valueOf(id));
			String values[] = null;
			if(mode == Index.STRING_BUILD)
				values = DataProcessor.process(2, line).split(" ");
			else if(mode == Index.SIFT_BUILD)
				values = line.split(" ");
			else
				System.out.println("Type error");
			
			for (int i = 0; i < values.length; i++) {
				//for insertion the value is grams and dim+value
				strValue strvalue = null;
				if(mode == Index.SIFT_BUILD)
					strvalue = new strValue(i+"+"+values[i]);
				else if(mode == Index.STRING_BUILD)
					strvalue = new strValue(values[i]);
				else
					System.out.println("Type error when adding document");
				jclient.addPair(strkey, strvalue, mode);
			}
			id++;
		}	
		for(int i = 0;i < num_ip; i++)
			jclient.closeIndexwriter(i);
	}