Lucene6入门教程(五)版本改变

版本变化:
IndexWriterConfig 类的构造方法;
Directory类的生成方法 FSDirectory.open(),(Path,File);
Field类中的存储问题,Intpoint取代IntField;
BooleanQuery() 的构造方法改变;
PointValues 取代了NumericField,.legacyXXField废弃;
WhitespaceAnalyzer类的废弃;
现在,Luene已经是6.6版本了,与之前的2.9,3.5,4.5,5等各个版本,已经很有些不同了。学习4.0之前的教程,我可是吃过不少亏的。
具体变化:
(1)IndexWriterConfig 类的构造方法:
这个类主要是充当创造/在索引过程中更新指标的对象。
原来Lucene4.0之前

    writer = new IndexWriter(indexDirectory, 
             new StandardAnalyzer(Version.LUCENE_36),true,
                    IndexWriter.MaxFieldLength.UNLIMITED);

现在Lucene6

    Analyzer analyzer=new StandardAnalyzer(); 
       IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
        IndexWriter writer = new IndexWriter(dir, iwc);

(2)Directory类的生成方法 FSDirectory.open(),(Path,File);
这个类主要便是打开词盘中的文件,
原来Lucene4.0之前

Directory directory = FSDirectory.open(new File(“C:\”));

现在Lucene6

Directory directory = FSDirectory.open(Path.get(“C:\”));

(3)Field类中的存储问题,Intpoint取代IntField;
原来的IntField类主要是实现整形的域内操作,而现在它主要改为Intpoint了,
原来Lucene用

    import org.apache.lucene.document.IntField;
            document.add(new IntField("id", id[i], Field.Store.YES));  

现在Lucene6用,需要配合StoredField来存储,需要NumericDocValuesField和StoredField来排序

    import org.apache.lucene.document.IntPoint; 
            doc.add(new NumericDocValuesField("id", id[i]));//和下边排序 
            doc.add(new IntPoint("id", id[i])); 
            doc.add(new StoredField("id", id[i]));  //存储

(4)BooleanQuery() 的构造方法改变;
BooleanQuery()的作用范围是 private 的,只能在类的内部调用,最大的改变是多出了静态内部类 Builder ,加强了类自身的稳定性与安全性。
原来Lucene用

    BooleanQuery query = new BooleanQuery();
       for (Query subQuery : querys) {
             query.add(subQuery,Occur.SHOULD);
           } return query;

现在Lucene6用

     for (Query subQuery : querys) {
        new BooleanQuery.Builder().add(subQuery,Occur.SHOULD).build();
          }  return query;

(5)PointValues 取代了NumericField,.legacyXXField废弃
PointValues 更快,更小,更便于资源的利用,都被取代了legacy**,
原来Lucene

          document.add(new IntField("mouths", 1));
            writer.addDocument(document);
Query query = new NumericRangeQuery("mouths", 1, 8,false,false);
TopDocs docs = searcher.search(query, ...);

现在Lucene6

     document.add(new IntPoint("mouths", 1));
       writer.addDocument(document);
Query query = IntPoint.newRangeQuery("mouths", 1, 8);
TopDocs docs = searcher.search(query, ...);

(6)WhitespaceAnalyzer类的废弃;

参考:lucene6.6学习心得 https://segmentfault.com/a/1190000010367206

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值