lucene中Field简介
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简介的更多相关文章
- lucene中Field简析
http://blog.csdn.net/zhaoxiao2008/article/details/14180019 先看一段lucene3代码 Document doc = new Document ...
- lucene中Field.Index,Field.Store详解
lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...
- 【转载】lucene中Field.Index,Field.Store详解
lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...
- lucene中Field.Index,Field.Store的一些设置
lucene在doc.add(new Field("content",curArt.getContent(),Field.Store.NO,Field.Index.TOKENIZE ...
- Lucene 的 Field 域和索引维护
一.Field 域 1.Field 属性 Field 是文档中的域,包括 Field 名和 Field 值两部分,一个文档可以包括多个 Field,Document 只是 Field 的一个承载体,F ...
- lucene中FSDirectory、RAMDirectory的用法
package com.ljq.one; import java.io.BufferedReader;import java.io.File;import java.io.FileInputStrea ...
- 【Lucene3.6.2入门系列】第03节_简述Lucene中常见的搜索功能
package com.jadyer.lucene; import java.io.File; import java.io.IOException; import java.text.SimpleD ...
- Lucene中的 Query对象
"Lucene中的 Query对象": 检 索前,需要对检索字符串进行分析,这是由queryparser来完成的.为了保证查询的正确性,最好用创建索引文件时同样的分析器. quer ...
- lucene 中关于Store.YES 关于Store.NO的解释
总算搞明白 lucene 中关于Store.YES 关于Store.NO的解释了 一直对Lucene Store.YES不太理解,网上多数的说法是存储字段,NO为不存储. 这样的解释有点郁闷:字面意 ...
随机推荐
- zabbix发送邮件脚本
#!/usr/bin/env python #-*- coding: UTF- -*- import os,sys reload(sys) sys.setdefaultencoding('utf8') ...
- 【STL基础】list
list 构造函数: //default: list<T> l; //空的list //fill: list<T> l(n); //n个元素, 元素默认初始化 list< ...
- 3D电影转2D普通电影,电脑上看
下了一些电影,打开发现是左右两个一样的画面,什么情况?原来这就是传说中的3D,怎么像正常电影一样的看呢?第一反应去搜3D眼镜,价钱倒是不贵,但是不应急呀,肿么办?以下是观看方法: 一.看电脑上有QQ影 ...
- C++_对象之间的关系与继承
派生类和基类之间的特殊关系是基于C++继承的底层模型的. 实际上,C++有3种继承方式:公有继承.保护继承.私有继承. 公有继承是最常见的关系,它建立一种is-a的关系,即派生类对象也是一种基类,可以 ...
- php返回数据格式
PHP返回HTML代码: header('Content-type:text/html; charset=utf-8'); PHP返回xml代码:header('content-type: t ...
- WCF的三种模式
WCF通信的3种模式 1.正常模式:客户端调取接口->等待服务响应->接受响应->执行客户端后面代码(wcf服务有入参,有返回值) 2.数据报模式:客户端调取接口->不等待响应 ...
- HikariPool连接池的使用
HikariDataSource datasource= new HikariDataSource( xxxx ); Connection cn = datasource.getConnection( ...
- vue(5)联动+tab页
来自:https://juejin.im/post/5a0c191f6fb9a04514639419 1.联动 新增 <input v-model="msg" /> & ...
- PHP rand 和 mt_rand
PHP mt_rand() 函数 定义和用法 mt_rand() 使用 Mersenne Twister 算法返回随机整数. 语法 mt_rand(min,max) 说明 如果没有提供可选参数 min ...
- leetcode 925. 长按键入
题目描述: 你的朋友正在使用键盘输入他的名字 name.偶尔,在键入字符 c 时,按键可能会被长按,而字符可能被输入 1 次或多次. 你将会检查键盘输入的字符 typed.如果它对应的可能是你的朋友的 ...