Lucene 6.1.0中存在的field种类如下(后缀是Field):

下面介绍几个常用的Field类型:

TextField

A field that is indexed and tokenized, without term vectors. For example this would be used on a 'body' field, that contains the bulk of a document's text.
是一个会自动被索引和分词的字段。一般被用在文章的正文部分。

StringField

A field that is indexed but not tokenized: the entire String value is indexed as a single token. For example this might be used for a 'country' field or an 'id' field. If you also need to sort on this field, separately add a SortedDocValuesField to your document.
StringField会被索引,但是不会被分词,即会被当作一个完整的token处理,一般用在“国家”或者“ID”.

StoredField

A field whose value is stored so that IndexSearcher.doc(int) and IndexReader.document() will return the field and its value.
也就是一个默认会被存储的Field。

举个例子
(下面是对新闻数据进行索引的过程,数据存储在MySQL数据库中,title列存文章标题,content存正文,url存文章所在的链接,author是文章的作者):

Field field = null;
if (rs.getString("title") != null) {
field = new TextField("title", rs.getString("title"), Field.Store.YES);
document.add(field);
}
if (rs.getString("content") != null) {
field = new TextField("content", rs.getString("content"), Field.Store.NO);
document.add(field);
}
if (rs.getString("url") != null) {
field = new StringField("url", rs.getString("url"), Field.Store.YES);
document.add(field);
}
if (rs.getString("author") != null) {
field = new TextField("author", rs.getString("author"), Field.Store.YES);
document.add(field);
}
writer.addDocument(document);

第一个参数是设置field的name,第二个是value,第三个是选择是否存储,如果存储的话在检索的时候可以返回值。
一般对于文章正文都不需要存储,在检索的时候只需要返回文章的标题和url即可。

lucene中Field简介的更多相关文章

  1. lucene中Field简析

    http://blog.csdn.net/zhaoxiao2008/article/details/14180019 先看一段lucene3代码 Document doc = new Document ...

  2. lucene中Field.Index,Field.Store详解

    lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...

  3. 【转载】lucene中Field.Index,Field.Store详解

    lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...

  4. lucene中Field.Index,Field.Store的一些设置

    lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...

  5. Lucene 的 Field 域和索引维护

    一.Field 域 1.Field 属性 Field 是文档中的域,包括 Field 名和 Field 值两部分,一个文档可以包括多个 Field,Document 只是 Field 的一个承载体,F ...

  6. lucene中FSDirectory、RAMDirectory的用法

    package com.ljq.one; import java.io.BufferedReader;import java.io.File;import java.io.FileInputStrea ...

  7. 【Lucene3.6.2入门系列】第03节_简述Lucene中常见的搜索功能

    package com.jadyer.lucene; import java.io.File; import java.io.IOException; import java.text.SimpleD ...

  8. Lucene中的 Query对象

    "Lucene中的 Query对象": 检 索前,需要对检索字符串进行分析,这是由queryparser来完成的.为了保证查询的正确性,最好用创建索引文件时同样的分析器. quer ...

  9. lucene 中关于Store.YES 关于Store.NO的解释

    总算搞明白 lucene 中关于Store.YES  关于Store.NO的解释了 一直对Lucene Store.YES不太理解,网上多数的说法是存储字段,NO为不存储. 这样的解释有点郁闷:字面意 ...

随机推荐

  1. [TJOI2017]DNA (FFT)

    [Luogu3763] FFT做字符串匹配即可,详见代码 // luogu-judger-enable-o2 #include<cstdio> #include<cstring> ...

  2. Jenkins自动化CI CD流水线之5--pipeline

    一.概览 二.安装 在对jenkins进行初始化安装时,默认已经安装了jenkins的相关插件,如下图所示: 三.实操 新建任务: 编写pipeline脚本: 我们可以借助流水线语法去做. test流 ...

  3. Linux内核硬件访问技术

    ① 驱动程序控制设备,主要是通过访问设备内的寄存器来达到控制目的.因此我们讨论如何访问硬件,就成了如何访问这些寄存器. ② 在Linux系统中,无论是内核程序还是应用程序,都只能使用虚拟地址,而芯片手 ...

  4. 信息领域热词分析系统--python过滤

    利用python过滤去没用的词语,过滤的词语存储在停用文件中. #创建停用词表 def stopwordlist(): stopwords=[line.strip() for line in open ...

  5. python 数据可视化---Anscombe’s quartet

    import seaborn as sns sns.set(style="ticks") # Load the example dataset for Anscombe's qua ...

  6. vue proxyTable 接口跨域请求调试(五)

    在不同域之间访问是比较常见,在本地调试访问远程服务器....这就是有域问题. VUE解决通过proxyTable: 在 config/index.js 配置文件中 dev: { env: requir ...

  7. javassist fr8.0破解

    主要是破解连接数的. 已破解的jar:http://download.csdn.net/download/wolf12/9834152 public static void main(String[] ...

  8. Hadoop Intro - Configure 01

    hadoop配置文件详解.安装及相关操作   一.      Hadoop伪分布配置 1. 在conf/hadoop-env.sh文件中增加:export JAVA_HOME=/home/Java/j ...

  9. 性能测试工具LoadRunner12-LR之Virtual User Generator 脚本编写验证步骤以及LR常见错误处理方法

    验证脚本比较好的流程: Generate:录制或开发脚本 SUSI(Single User Single Iteration,单用户单循环):运行录制生成的脚本,解决可能存在的关键问题 SUMI(Si ...

  10. JavaScript DOM基础总结

    上个月在进行百度三面时候,面试官提问JavaScript DOM方法,我回答的有点少,前面太关注JavaScript 兼容性,框架方面,JavaScript 原生DOM基础没有记牢,心中有点遗憾.下来 ...