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. CF708A Letters Cyclic Shift 模拟

    You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly ...

  2. 20.包含min函数的栈

    题目描述:   定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1)). 思路分析:   设置两个栈,一个push,一个放置最小元素. 代码: impor ...

  3. kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  4. 使用cookie实现自动登录

    一.从登录——>主页面,进行的过程是,输入 用户名和密码,以及验证码,点击“登录”跳转到Activity.jsp login1.action(跳转到登录页面) /** 跳转到login(有积分排 ...

  5. poi进行excle操作

    一 excle导出: 所需要jar包 <dependency> <groupId>org.apache.poi</groupId> <artifactId&g ...

  6. zookeeper客户端使用第三方(zkclient)封装的Api操作节点

    1.引入依赖 <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</a ...

  7. c#缓存帮助类

    public static class CacheHelper { static object _lockObj = new object(); private static Dictionary&l ...

  8. http 和 https 的区别

    参考:http://www.cnblogs.com/wqhwe/p/5407468.html HTTP:是互联网上应用最为广泛的一种网络协议,是一个客户端和服务器端请求和应答的标准(TCP),用于从W ...

  9. eclipse中找不到base64包的解决方法

    eclipse中找不到base64包的解决方法 2017年08月26日 11:05:26 yzp_leo 阅读数:634 标签: javaeclipsebase64更多 个人分类: 日记   ecli ...

  10. 如何使用java代码进行视频格式的转换(FLV)

    如何使用java代码进行视频格式的转换(FLV) 一,前言 在给网页添加视频播放功能后,发现上传的视频有各种格式,那么就需要将他么转换成FLV,以很好的支持在线视频播放. 公司一直在使用中,配合使用, ...