You are opening a new overwriting IndexWriter for every
file, so only
the last one is indexed. You should open your IndexWriter
outside
the loop and close it afterwards.
Erik
On Apr 30, 2006, at 6:42 AM, Kostas V. wrote:
> 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
------------------------------------------------------------
---------
To unsubscribe, e-mail: java-user-unsubscribe lucene.apache.org
For additional commands, e-mail: java-user-help lucene.apache.org
|