lucene3.6.1 中Field.Index,Field.Store释义

本文详细介绍了Elasticsearch中不同字段类型的索引方式,包括不分词、分词及禁用规范等设置,帮助读者理解如何根据需求选择合适的字段索引选项。

Norms 是调节因子,为文档打分使用,不使用会节约一部分存储,

基本含义是

NO_NORMS: 不打分

NOT_ANALYZED:不分词

NO:不建立索引

ANALYZED
Index the tokens produced by running the field's value through an Analyzer.

索引经过分词器处理的字段值

ANALYZED_NO_NORMS
Expert: Index the tokens produced by running the field's value through an Analyzer, and also separately disable the storing of norms.

索引经过分词器处理的字段值,分别禁用存储规范

NO
Do not index the field value.

不索引该字段值

NOT_ANALYZED
Index the field's value without using an Analyzer, so it can be searched.

不使用分词器索引字段值,因此它可以被搜查

NOT_ANALYZED_NO_NORMS
Expert: Index the field's value without an Analyzer, and also disable the indexing of norms.

不使用分词器索引字段,也禁用索引调节因子

Enum Constant Summary

NO
Do not store the field value in the index.

不存储在索引中的字段值

YES
Store the original field value in the index.

存储在索引中的原始字段值

package com.boe.cim.teacher.luence; import java.nio.file.Paths; import java.util.List; import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.IntField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import com.boe.cim.teacher.pojo.RequirementInfo; /** * @author hyh * @description 创建文档索引 */ public class LuceneIndexRequirement { private Directory dir; /** *实例化indexerWriter * @return * @throws Exception */ private IndexWriter getWriter()throws Exception{ //中文分词器 SmartChineseAnalyzer analyzer=new SmartChineseAnalyzer(); IndexWriterConfig iwc=new IndexWriterConfig(analyzer); IndexWriter writer=new IndexWriter(dir, iwc); return writer; } /** * 获取indexreDir * @param indexreDir * @throws Exception */ public void index(String indexreDir,List<RequirementInfo> listRequirement)throws Exception{ dir=FSDirectory.open(Paths.get(indexreDir)); IndexWriter writer=getWriter(); for(int i=0;i<listRequirement.size();i++){ Document doc=new Document(); RequirementInfo requirement = listRequirement.get(i); //StringField 只索引不分词 doc.add(new StringField("id",String.valueOf(requirement.getId()), Field.Store.YES)); doc.add(new StringField("requirement", requirement.getRequirement(), Field.Store.YES)); doc.add(new StringField("department",requirement.getDepartment(),Field.Store.YES)); doc.add(new StringField("liaisonman", requirement.getLiaisonman(), Field.Store.YES)); doc.add(new StringField("requirementtype", Integer.toString(requirement.getRequirementtype()), Field.Store.YES)); doc.add(new TextField("requirementbackground", requirement.getRequirementbackground(), Field.Store.YES)); doc.add(new TextField("requirementcontents", requirement.getRequirementcontents(), Field.Store.YES)); // writer.deleteDocuments(new Term("id",String.valueOf(teacher.getId()))); writer.updateDocument(new Term("id",String.valueOf(requirement.getId())), doc); } writer.close(); } } 上述代码是否正确
最新发布
08-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值