public void buildIndexes(final File folder) throws FileNotFoundException,
    UnsupportedEncodingException, IOException, ClassNotFoundException {
        for (final File fileEntry : folder.listFiles()) {
            if (fileEntry.isDirectory()) {
                buildIndexes(fileEntry);
            } else {
                docIdList.add(fileEntry.getName());
                BufferedReader in = new BufferedReader(
                    new InputStreamReader(new FileInputStream(
                        fileEntry.getAbsoluteFile()), "UTF-8"));
                String content = new Scanner(in).useDelimiter("\\Z").next();
                String body = content.substring(content.indexOf("<body>")+6,
                        content.indexOf("</body>"));
                body = body.replaceAll("</v><v>", " ");
                body = body.replaceAll("\\<.*?\\>", "");
                body = body.replaceAll("\n", " ");
                body = body.replaceAll("[\\W]", " ");

                String[] line = body.split(" ");
                for (int i = 0; i < line.length; i++) {
                    addTerm(line[i].toLowerCase(), FREE_DOC_ID);
                }
                FREE_DOC_ID++;
            }
        }
        calculateTfIdf();
        createVectors();
        clustering();
    }