我想用lucene做一个全文检索,但是在第一步构造IndexReader时老是出错,报:ERROR opening the Index - contact sysadmin!
这是什么原因,我应如何才能正确构造?
这是什么原因,我应如何才能正确构造?
解决方案 »
- 一个奇怪的路径问题,求高手!
- ActionForm校验返回error后如何使页面URL不变?
- 关于web重新部署需重启tomcat的问题。
- 如何在jsp的web页面上,实现多线程的上传文件?
- 如何将一个很长的数值分成很多个很短的数值?高手求助
- 请问用java怎样做一个离线工具,就是说指定一个链接,能把上面的图片样式表等的信息都下下来
- 请问如下JSP应该怎么改
- <a href="/test.ini"></a>怎么点击之后直接打开文件,但我现在不能让他打开,只能下载。怎么做啊?
- 图片上传的问题 高手请进
- quartz中一个job包含多个trigger时并发问题
- 新手提问:如何把http://java.sun.com/j2se/1.4.2/docs/api/ 上的java帮助文档全部下载?马上结贴
- 关于lucene的搜索问题
检查strIndexPath路径是否正确,好像必须是绝对路径
另:那位高手能不能讲讲如何对现有文件存储建立一个indexFile,我在调用IndexWriter时,得到的一个segments是个空的文件,什么也没有。如能给出到此步的实现代码,将不胜感谢。
String strIndexPath= application.getRealPath(strHead);
//--------------IndexWriter
Analyzer analyzer = new ChineseAnalyzer();
boolean isHasPath = (strIndexPath存在) ? false : true;
//()
IndexWriter indexWriter
= new IndexWriter(strIndexPath,
new ChineseAnalyzer(),
isHasPath);
//进入文件系统的全文检索
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也为空,我现在不知如何进行上面这个过程了,请你们看看。看错在那?再次谢谢了。
writer.close();
放到finally里面,也许被异常跳过去了
如果fpaths下面没有txt文件而是一些文件夹,当然在index目录下就是空的了。