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

lucene问题急求
package   TestLucene;
import   java.io.File;
import   org.apache.lucene.document.Document;
import   org.apache.lucene.index.Term;
import   org.apache.lucene.search.Hits;
import   org.apache.lucene.search.IndexSearcher;
import   org.apache.lucene.search.TermQuery;
import   org.apache.lucene.store.FSDirectory;
/**
  *   This   class   is   used   to   demonstrate   the  
  *   process   of   searching   on   an   existing  
  *   Lucene   index
  *
  */
public   class   TxtFileSearcher   {
public   static   void   main(String[]   args)   throws   Exception{
        String   queryStr   =   "lucene ";
        //This   is   the   directory   that   hosts   the   Lucene   index
                File   indexDir   =   new   File( "D:\\luceneIndex ");
                FSDirectory   directory   =   FSDirectory.getDirectory(indexDir,false);
                IndexSearcher   searcher   =   new   IndexSearcher(directory);
                if(!indexDir.exists()){
                System.out.println( "The   Lucene   index   is   not   exist ");
                return;
                }
                Term   term   =   new   Term( "contents ",queryStr.toLowerCase());
                TermQuery   luceneQuery   =   new   TermQuery(term);
                Hits   hits   =   searcher.search(luceneQuery);
                for(int   i   =   0;   i   <   hits.length();   i++){
                Document   document   =   hits.doc(i);
                System.out.println( "File:   "   +   document.get( "path "));
                }
}
}
为什么我运行会出现
Exception   in   thread   "main "   java.io.FileNotFoundException:   no   segments*   file   found:   files:
at   org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:485)
at   org.apache.lucene.index.IndexReader.open(IndexReader.java:147)
at   org.apache.lucene.index.IndexReader.open(IndexReader.java:142)
at   org.apache.lucene.search.IndexSearcher. <init> (IndexSearcher.java:48)
at   TxtFileIndexer.main(TxtFileIndexer.java:23)
错,急求


------解决方案--------------------
no segments* file found: files:

第一次运行 把参数改为 true 试试