日期:2014-05-18  浏览次数:20747 次

求救:lucene索引文件时出错
我索引文件的函数如下:
    private   static   void   indexFile(IndexWriter   writer,   File   f)
        throws   Exception   {

        if   (f.isHidden()   ||   !f.exists()   ||   !f.canRead())   {
            return;
        }    
              //读句子加入索引  
              InputStreamReader     read   =   new   InputStreamReader   (new   FileInputStream(f), "UTF-8 ");
BufferedReader   reader=new   BufferedReader(read);
String   line;
Document   doc   =   new   Document();
while   ((line   =   reader.readLine())   !=   null)  
{
    addDoc(writer, "sen ",line);
}
        writer.optimize();
        writer.close();
    }
private   static   void   addDoc(IndexWriter   writer,   String   FIELD_NAME,String   text)   throws   IOException
{
                      Document   d   =   new   Document();
                      Field   f   =   new   Field(FIELD_NAME,   text   ,   Field.Store.YES,   Field.Index.TOKENIZED,     Field.TermVector.WITH_POSITIONS_OFFSETS);
                      d.add(f);
                      writer.addDocument(d);

}
我索引一个文件(文件不大)时没有报错,当文件过多或者文件过大时就报错:
Exception   in   thread   "main "   java.io.IOException:   Cannot   rename   D:\Tomcat   5.0\webapps\search\index\segments.new   to   D:\Tomcat   5.0\webapps\search\index\segments
at   org.apache.lucene.store.FSDirectory.renameFile(FSDirectory.java:294)
at   org.apache.lucene.index.SegmentInfos.write(SegmentInfos.java:95)
at   org.apache.lucene.index.IndexWriter$4.doBody(IndexWriter.java:726)
at   org.apache.lucene.store.Lock$With.run(Lock.java:99)
at   org.apache.lucene.index.IndexWriter.mergeSegments(IndexWriter.java:724)
at   org.apache.lucene.index.IndexWriter.mergeSegments(IndexWriter.java:686)
at   org.apache.lucene.index.IndexWriter.maybeMergeSegments(IndexWriter.java:674)
at   org.apache.lucene.index.IndexWriter.addDocument(IndexWriter.java:479)
at   org.apache.lucene.index.IndexWriter.addDocument(IndexWriter.java:462)
at   index.IndexManager.addDoc(IndexManager.java:146)
at   index.IndexManager.indexFile(IndexManager.java:125)
at   index.IndexManager.indexDirectory(IndexManager.java:84)
at   index.IndexManager.index(IndexManager.java:64)
at   index.IndexManager.run(IndexManager.java:43)
at   search.SearchManager.main(SearchManager.java:49)
Caused   by:   java.io.FileNotFoundException:   D:\Tomcat   5.0\webapps\search\index\segments   (拒绝访问。)
at