lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kostas V." <kvele...@gmail.com>
Subject RE: Index all the files in a directory
Date Sun, 30 Apr 2006 10:42:37 GMT
Dear Erick (and everyone who might read my post) hi and thank you very much
for your help.
I've tried your program but I do something wrong and it is only index the
last txt in the directory. If you could see my problem because I am new to
Java and Lucene as well. 
Thanks in advance

Kostas


public void parseAll() throws Exception {
            String sParentDir = "/database";

        indexTree(new File(sParentDir));
        }

        private void indexTree(File file) throws Exception {
            
        if (file.canRead()) {
        if (file.isDirectory()) {
        String[] files = file.list();
        if (files != null) {
        for (int idx = 0; idx < files.length; idx++) {
        indexTree(new File(file, files[idx]));
        }
        }
        } else {
        if (file.getName().toLowerCase().indexOf(".txt") == -1)
        return;
        String indexPath = "/portal-index";
        IndexWriter writer;
        GreekAnalyzer ana = new GreekAnalyzer();
        try {
            writer = new IndexWriter(indexPath, ana, true);
            
                 File indexFile = new File(""+file);
                 InputStream fis = new FileInputStream(indexFile);
                 
                Document doc = new Document();

                doc.add(Field.UnIndexed("path", indexFile.getPath()));
                doc.add(Field.UnIndexed("length",
                                        Long.toString(indexFile.length())));
                doc.add(Field.UnIndexed("modified",
                                        new Date(indexFile.lastModified()).
                                        toString()));
                doc.add(Field.Text("text", (Reader)new    
                               InputStreamReader(fis)));

                writer.addDocument(doc);
                writer.optimize();
                fis.close();
            
            writer.close();

    } catch (IOException ioe) {
            System.out.println(ioe);

        }
        }
        }
        }


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message