lucene代码分析4

2021SC@SDUSC
Lucene作为一个检索引擎主要保存七种类型的数据: PostingList,TermDict,StoredField ,DocValue, TermVector, Norms,PointValue, 前四种是所有检索引擎都会保存的数据,后三种是Lucene特有的数据,实际上,StoredField就是我们所说的正排数据,它是一种行式存储,类似于mysql中的行数据,StoredField承担存储最原始的数据的角色重要性不言而喻,之所以先讲这块也是因为它最简单,但是在讲StoredField的时候会包含很多Lucene的基础知识点,彻底搞明白了StoredField,也就基本搞懂了index的流程, 以及一些编码方式(比如vint, packedInt, delta存储等技巧)
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.;
import org.apache.lucene.index.
;
import org.apache.lucene.search.*;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;

public class demo {

public static void main(String[] args) throws IOException{
    MAIN();
}

public static void MAIN() throws IOException {
    // 指定analyzer
    StandardAnalyzer analyzer = new StandardAnalyzer();

    // 指定目录
    Directory directory = FSDirectory.open(Paths.get("tempPath"));
    // 指定config
    IndexWriterConfig config = new IndexWriterConfig(analyzer);
    // 建立IndexWriter
    IndexWriter w = new IndexWriter(directory, config);
    // 创建document
    Document doc = new Document();
    doc.add(new TextField("title", "Lucene in action", Field.Store.YES));
    doc.add(new StringField("isbn", "193398817", Field.Store.YES));
    doc.add(new StoredField("visit", 5));
    doc.add(new SortedNumericDocValuesField("visit", 5));
    // 添加document到indexWriter
    w.addDocument(doc);
   // 落盘flush
    w.close()

}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值