public void fillMatrix(final File folder) throws FileNotFoundException,
   UnsupportedEncodingException {
        docNumber = folder.list().length;
        for (final File fileEntry : folder.listFiles()) {
            if (fileEntry.isDirectory()) {
                fillMatrix(fileEntry);
                docNumber += fileEntry.list().length;
            } 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 firstName = content.substring(
                        content.indexOf("<first-name>")+12,
                        content.indexOf("</first-name>"));
                String lastName = content.substring(
                        content.indexOf("<last-name>")+11,
                        content.indexOf("</last-name>"));
                this.addToMatrix(firstName.toLowerCase(), FREE_DOC_ID);
                this.addToMatrix(lastName.toLowerCase(), FREE_DOC_ID);
                this.addToDoubleWordIndex(firstName.toLowerCase(), FREE_DOC_ID);
                this.addToDoubleWordIndex(lastName.toLowerCase(), FREE_DOC_ID);

                String [] bookTitle = content.substring(
                        content.indexOf("<book-title>")+12,
                        content.indexOf("</book-title>")).split(" ");
                for (int i = 0; i < bookTitle.length; i++) {
                    this.addToMatrix(bookTitle[i].toLowerCase(), FREE_DOC_ID);
                    this.addToDoubleWordIndex(bookTitle[i].toLowerCase(), FREE_DOC_ID);
                    this.addToDoubleWordIndex(bookTitle[i].toLowerCase(), FREE_DOC_ID);
                }

                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-1; i++) {
                        this.addToMatrix(line[i], FREE_DOC_ID);
                        this.addToCoordIndex(line[i], FREE_DOC_ID, i);
                        this.addToDoubleWordIndex(line[i]+" "+line[i+1], FREE_DOC_ID);
                    }
                 this.addToMatrix(line[line.length-1], FREE_DOC_ID);
                 this.addToCoordIndex(line[line.length-1], FREE_DOC_ID, line.length-1);
                    FREE_DOC_ID++;
                }
            }
        createInvertIndex();
    }