我想用lucene做一个全文检索,但是在第一步构造IndexReader时老是出错,报:ERROR opening the Index - contact sysadmin!
这是什么原因,我应如何才能正确构造?

解决方案 »

  1.   

    IndexReader indexReader = IndexReader.open(strIndexPath);
    检查strIndexPath路径是否正确,好像必须是绝对路径
      

  2.   

    我的路径是这样取的:IndexReader indexreader = new IndexReader.open(application.getRealPath("").concat("/ywzx/indexf"));结果就报错。
    另:那位高手能不能讲讲如何对现有文件存储建立一个indexFile,我在调用IndexWriter时,得到的一个segments是个空的文件,什么也没有。如能给出到此步的实现代码,将不胜感谢。
      

  3.   

    String strHead = "./ywzx/indexf";
    String strIndexPath= application.getRealPath(strHead);
    //--------------IndexWriter
    Analyzer analyzer = new ChineseAnalyzer();
    boolean isHasPath = (strIndexPath存在) ? false : true;
    //()
    IndexWriter indexWriter 
        = new IndexWriter(strIndexPath, 
                          new ChineseAnalyzer(), 
                          isHasPath);
      

  4.   

    我写的代码如下,请高手们看看:
    //进入文件系统的全文检索
    Vector flist = new Vector();
    String strHead = "./ywzx/indexf";
    String fpath= application.getRealPath(strHead);
    File fpaths = new File(fpath,".");
    String[] list = fpaths.list();
    String indexPath = fpath;
    org.apache.lucene.index.IndexWriter writer;
    //用指定的语言分析器构造一个新的写索引器(第3个参数表示是否为追加索引)
    writer = new org.apache.lucene.index.IndexWriter(indexPath, new org.apache.lucene.analysis.SimpleAnalyzer(), false);
    for (int i=0; i<list.length; i++)

    String str3 = list[i].substring(list[i].indexOf(".")+1).trim();
    if(str3.equals("txt"))
    {     
    //out.println("Indexing file " + list[i]);
    InputStream is = new FileInputStream(fpath+"/"+list[i]);
    //构造包含2个字段Field的Document对象
    //一个是路径path字段,不索引,只存储
    //一个是内容body字段,进行全文索引,并存储
    org.apache.lucene.document.Document doc = new org.apache.lucene.document.Document();
    doc.add(org.apache.lucene.document.Field.UnIndexed("path",fpath+"/"+list[i]));
    doc.add(org.apache.lucene.document.Field.Text("body", (Reader) new InputStreamReader(is)));
    //将文档写入索引
    writer.addDocument(doc);is.close();
    }
    };
    //关闭写索引器
    writer.close();ps:就是这个地方,fpath下是存有我要检索的文件,当我运行上面的程序时,就出错,而且生成的segments也为空,我现在不知如何进行上面这个过程了,请你们看看。看错在那?再次谢谢了。
      

  5.   


    writer.close();
    放到finally里面,也许被异常跳过去了
      

  6.   

    你怎么没有用递归啊?
    如果fpaths下面没有txt文件而是一些文件夹,当然在index目录下就是空的了。