Lucene

这篇博客介绍了如何使用Lucene进行索引构建,包括创建Document对象,添加Field如name、content、size和path,并将它们分析和存储。接着展示了建立索引的过程,使用IndexWriter添加Document到索引中。在搜索部分,通过QueryParser解析查询表达式,使用IndexSearcher查找匹配的文档,并打印出相关字段信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

─ Index: sequence of documents (a.k.a. Directory)
─ Document: sequence of fields
─ Field: named sequence of terms
─ Term: a text string (e.g., a word)

 

Building:

 

  Document doc = new Document();
  doc.add(new Field("name", file.getName(), Store.YES, Index.ANALYZED));
  doc.add(new Field("content", readFileContent(file), Store.YES, Index.ANALYZED));
  doc.add(new Field("size", NumberTools.longToString(file.length()), Store.YES, Index.NOT_ANALYZED));
  doc.add(new Field("path", file.getAbsolutePath(), Store.YES, Index.NOT_ANALYZED));
  return doc;

 

 

  // 建立索引
  IndexWriter indexWriter = ne

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值