Lucene 学习 3 Field

来源:互联网 发布:j2ee设计开发编程指南 编辑:程序博客网 时间:2024/04/29 15:16


上一篇实现了最简单的 Helloworld ,这一篇将介绍很重要的一个类 Field。

作为创建索引的第一步,就是向 document 中添加 field。


如果你使用 SVN 的话,可以到  https://svn.apache.org/repos/asf/lucene/dev/trunk/lucene,把 lucene 的源码下载下来。

有源码在手,学习上多少有些帮助。



疑惑

 Document doc = new Document(); doc.add(new StringField("path", file.getPath(), Field.Store.YES));       

这是上篇中的一小段代码,StringField 的第三个参数是什么作用?

另外 StringField 又该在什么情况下使用呢? 有没有其他的 "Field" 呢?



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, or any field that you intend to use for sorting *  or access through the field cache. */


这是源码中对 StringField 的介绍,几个关键点是:

被索引,不分词,完整的值会被保存下来,适合于国家或 id 这样的字段。


索引是为了被查询,所以一般都是索引的。

不被索引的 field 不能被查询,只能作为其他 field 的附属物,比如 url。

分词是指用分词器将文本文档分割成更小的单元,每个单元都可以被搜索。

与分词对应的,就是完整保留下整个值,对于 Id 或者国家名而言,分割之后毫无意义。


一篇很好的文章

http://blog.itpub.net/28624388/viewspace-766381/




0 0