lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Muetze303 <Muetze...@gmx.li>
Subject Re: FileNotFoundException segments
Date Thu, 07 Jul 2005 11:32:37 GMT
probably the dir exists, but the index inside the dir is broken or not 
complete and you are trying to use it instead of creating a new one?!

bib_lucene bib wrote:

>Hi All
> 
>can someone please help me on the error in my web application...
> 
>I am using tomcat , the path for index dir is obtained from jsp page using application.getRealPath("/")+"download/compName"
> 
>I want to index when the file gets uploaded.
>I am getting this error...
> 
>java.io.FileNotFoundException: C:\tomcat\webapps\myApp\download\compName\segmen
>s (The system cannot find the file specified)
>        at java.io.RandomAccessFile.open(Native Method)
>        at java.io.RandomAccessFile.<init>(RandomAccessFile.java:204)
>        at org.apache.lucene.store.FSInputStream$Descriptor.<init>(FSDirectory.
>ava:376)
>        at org.apache.lucene.store.FSInputStream.<init>(FSDirectory.java:405)
>        at org.apache.lucene.store.FSDirectory.openFile(FSDirectory.java:268)
>        at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:40)
>        at org.apache.lucene.index.IndexWriter$1.doBody(IndexWriter.java:233)
>        at org.apache.lucene.store.Lock$With.run(Lock.java:109)
>        at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:228)
>        at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:193)
>        at com.rs.upload.FileIndexer.indexDocument(FileIndexer.java:43)
> 
> 
>This directory C:\tomcat\webapps\myApp\download\compName\  exist in the file system.
> 
>Here is the program I wrote 
>/*
> * Created on Jul 6, 2005
> *
> * TODO To change the template for this generated file go to
> * Window - Preferences - Java - Code Style - Code Templates
> */
>package com.rs.upload;
>import java.util.Hashtable;
>import java.util.Iterator;
>import java.io.*;
>import org.apache.lucene.index.IndexWriter;
>import org.apache.lucene.analysis.standard.*;
>import org.apache.lucene.document.*;
>/**
> * @author
> *
> * This will index the documents as and when documents are uploaded.
> * 
> */
>public class FileIndexer {
> 
> public static void indexDocument(String fileName, Hashtable fields, String indexDir)
throws IOException{
>  
>  // Find if the index already exists
>  boolean exists = true;
>  File indexFile = null;
>  if ((indexFile = new File(indexDir)).exists() && indexFile.isDirectory())
>  {
>       exists = false;
>       System.out.println("Index does not exist");
>  }
>  else 
>  {
>        exists = true;
>        System.out.println("Index does exist");
>  }
>  System.out.println("Index Directory:"+indexDir);
>  IndexWriter writer = null;
>  try {
>   writer = new IndexWriter(indexFile, new StandardAnalyzer(), exists);
>  } catch (IOException e) {
>   // TODO Auto-generated catch block
>   e.printStackTrace();
>  }
>  writer.mergeFactor = 20;
>  
>  File candidateFile = new File(fileName);
>  indexFile(writer,candidateFile,fields);
> }
> 
> private static void indexFile(IndexWriter writer, File f, Hashtable fields) throws IOException{
>  
>  if( f.isHidden() || !f.exists() || !f.canRead()){
>   return;
>  }
>  
>  System.out.println("Indexing file :"+ f.getCanonicalPath());
>  Document doc = new Document();
>  doc.add(Field.Text("contents", new FileReader(f)));
>  doc.add(Field.Keyword("filename",f.getCanonicalPath()));
>  
>  Iterator it = fields.keySet().iterator();
>  String element = "";
>     while (it.hasNext()) {
>        element =  (String)it.next();
>        doc.add(Field.Keyword(element,(String)fields.get(element)));
>     }
>     writer.addDocument(doc);
> }
>}
> 
>
>		
>---------------------------------
> Sell on Yahoo! Auctions  - No fees. Bid on great items.
>  
>

---------------------------------------------------------------------
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