前言
学习的资料是 lucene 4.10 版本,比较沉旧,查阅最新的 lucene 版本 6.6 的官方文档,整理出以下几个使用中的不同。
从浅入深依次为 (注:不是根据版本先后)
IndexWriterConfig 的构造方法
Directory 的生成方法 FSDirectory.open()
legacyXXField 与legacyNumericRangeQuery 的废弃
BooleanQuery() 方法的改变
setBoost()方法的废除
中文分词器的改进
下面,就让我详细的整理出不同。
1.IndexWriterConfig
以下是 IndexWriterConfig 4.10 的源码部分
public IndexWriterConfig(Version matchVersion, Analyzer analyzer) {
super(analyzer, matchVersion);
}
//这里的version 一般要写为
Version 类中
public static final Version LATEST;
而 IndexWriterConfig 6.6 中
//无参构造方法
public IndexWriterConfig() {
this(new StandardAnalyzer());
}
//有参构造方法
public IndexWriterConfig(Analyzer analyzer) {
super(analyzer);
this.writer = new SetOnce();
}
可以看出,在 6.6 版本中 version 不再是必要的,并且,存在无参构造方法,可以直接使用默认的 StandardAnalyzer 分词器。
2.Directory
正常创建 Directory 类的方法如下
Directory di = FSdirectory.open();
以下是 IndexWriterConfig 4.10 的源码部分
public static FSDirectory open(File path) throws IOException {
return open(path, (LockFactory)null);
}
这里可以看出 open 方法 用的参数类型 为File
而 IndexWriterConfig 6.6 中
public static FSDirectory open(Path path) throws IOException {
return open(path, FSLockFactory.getDefault());
}
open 方法使用了 Path 类,这个类是 NIO 中的类,可以提高查询的效率。
由 File 转化为 Path 的 方法
--->
File file = new File (absolutePath);
Path path = file.toPath()
3.legacyXXField 与legacyNumericRangeQuery
1. 分析
PointValues replaces NumericField (LUCENE-6917)
PointValues provides faster ind