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为不存储. 这样的解释有点郁闷:字面意 ...
随机推荐
- The requested profile "account" could not be activated because it does not exist 无法maven install的 解决办法,勾选红框选择的选项即可
- 2-28 if...else
- laytpl....
switch 语句.. <ul class='mui-table-view'> <!--switch 语句 ...--> {{# switch(d['event']){ cas ...
- Codeforces-B-Game with string(模拟栈)
Two people are playing a game with a string ss, consisting of lowercase latin letters. On a player's ...
- Go语言基础之10--面向对象编程2之方法
一.方法的定义 之前我们学习了结构体(struct),其仅仅是对数据的封装,并没有行为方法,还不是一个完全的面向对象的思路,所以现在我们来学习在结构体的基础上如何去定义一个方法.结构体(类)+方法=完 ...
- thymeleaf总结
thymeleaf 基本功能是将 th:xxx的内容替换html标签的内容 原标签的内容会被替换掉,原内容只是前端用来显示demo的 和freemarker, velocity的重要区别是,它们的自定 ...
- 浏览器存储localStorage、sessionStorage、cookie
localStorage和sessionStorage浏览器支持IE8+(测试IE8不行): localStorage:用于长久保存整个网站的数据,保存的数据没有过期时间,直到手动去除 session ...
- java源文件组成部分
class HelloWorld{ public static void main(String[ ] args) { System.out.print("HelloWorld!!!&quo ...
- 386. Lexicographical Numbers 把1--n按字典序排序
https://leetcode.com/problems/lexicographical-numbers/description/ 前20个是 1, 10, 11, 12, 13, 14, .... ...
- SETI ACdream - 1430 后缀自动机求不相交子串
http://blog.csdn.net/gatevin/article/details/45875343 题目是求不重叠的不同子串个数 一般来说, endpos集合包含了子串结尾位置,结尾在&quo ...