我下载了新的lucene,版本号是5.2.1结果跟着教程编写时会报错,上网查看是也不太明白,
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_43);
IndexWriterConfig indexconfig = new IndexWriterConfig(Version.LUCENE_43, analyzer);
directory = FSDirectory.open(new File("D://index/test"));
这条语句在编写时报错,上边两个勉强解决,directory 这个open一直在报错
- 极客学院_ASMITA 2015年06月30日 回答 #1楼
从字面来看,你的少了个/啊
是D://index//test
- 0 评论
- 小鸡慢慢 2015年06月30日 回答 #2楼
Lucene是Apache下的开源项目,每一个版本更新都会有很大的改动,这个系列的课程基于的Lucene版本是4.3.1,如果你使用5.2.1这个版本,请参考官网对应的API。个人建议没有必要使用这么新的版本,目前在公司内使用的版本多数都是4.0之前的。
问题解决:
5.2.0的API地址:http://lucene.apache.org/core/5_2_0/core/index.html
修改之后的使用方法如下:
<span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="com" style="color: rgb(136, 0, 0);">// Store the index in memory:</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="typ" style="color: rgb(102, 0, 102);">Directory</span><span class="pln" style="color: rgb(0, 0, 0);"> directory </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="typ" style="color: rgb(102, 0, 102);">RAMDirectory</span><span class="pun" style="color: rgb(102, 102, 0);">();</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="com" style="color: rgb(136, 0, 0);">// To store an index on disk, use this instead:</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="com" style="color: rgb(136, 0, 0);">//Directory directory = FSDirectory.open("/tmp/testindex");</span>
- 0 评论
- 小鸡慢慢 2015年08月12日 回答 #5楼
由于Lucene的版本更新比较快,而且每个版本都有很大的改动,建议学习这门课程的时候尽量可以选择4.3.1这个版本,避免出现未知名的BUG,在理解Lucene是如何工作之后,可以试着去接触下最新版本;目前自己了解的情况是现在多数公司使用的Lucene还停留的3.x,使用4.x都很少,大家也没有必要一定要追求最新版本。Lucene 4.3.1源码的下载地址:http://archive.apache.org/dist/lucene/java/4.3.1/
- 0 评论