免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1376 | 回复: 0
打印 上一主题 下一主题

Lucene Field [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-27 11:03 |只看该作者 |倒序浏览

Lucene 2.0以后API接口发生了不少的变化。其中比较重要的是Field。

Field没了Keyword、UnIndexed、UnStored、Text这几个静态成员,只能用
Field(String, String, Store, Index)构造函数生成实例
Field类一共有5种构造函数:

[url=file:///G:/lucene-2.0.0/lucene-2.0.0/docs/api/org/apache/lucene/document/Field.html#Field(java.lang.String, byte[], org.apache.lucene.document.Field.Store)]Field[/url]
(
String
name, byte[] value,
Field.Store
store)
           Create a stored field with binary value.

Field
(
String
name,
Reader
reader)
           Create a tokenized and indexed field that is not stored.

Field
(
String
name,
Reader
reader,
Field.TermVector
termVector)
           Create a tokenized and indexed field that is not stored, optionally with storing term vectors.

Field
(
String
name,
String
value,
Field.Store
store,
Field.Index
index)
           Create a field by specifying its name, value and how it will be saved in the index.

Field
(
String
name,
String
value,
Field.Store
store,
Field.Index
index,
Field.TermVector
termVector)
           Create a field by specifying its name, value and how it will be saved in the index.
其中:
Field.Store 表示“是否存储”,即该Field内的信息是否要被原封不动的保存在索引中。
Field.Index 表示“是否索引”,即在这个Field中的数据是否在将来检索时需要被用户检索到,一个“不索引”的Field通常仅是提供辅助信息储存的功能。
Field.TermVector 表示“是否切词”,即在这个Field中的数据是否需要被切词。
通常,参数用Reader,表示在文本流数据源中获取数据,数据量一般会比较大。像链接地址URL、文件系统路径信息、时间日期、人名、居民身份证、电话号码等等通常将被索引并且完整的存储在索引中,但一般不需要切分词,通常用上面的第四个构造函数,第三四个参数分别为
Field.Store
.YES,
Field.Index
.YES。而长文本通常可用第3个构造函数。引用[http://blog.csdn.net/colasnail/archive/2007/03/21/1536417.aspx]

1.       2.0 以前的版本
Keyword: Field 的值将被保存到索引文件,为Field的值建立索引,建立索引时不需要分词。 对应Field.Store.YES, Field.Index.UN_TOKENIZED
UnIndexed: Field 的值将被保存到索引文件,不为Field的值建立索引,因此不能通过该Field搜索文档。对应Field.Store.YES, Field.Index.NO
UnStored: Field 的值不被保存到索引文件,将Field的值分词后建立索引。对应Field.Store.NO, Field.Index.TOKENIZED
Text: Field 的值分词后建立索引。如果参数为String值将被保存,为Reader值不被保存 。对应Field.Store.YES, Field.Index.TOKENIZED
2.       2.0 版本
用几个内部类的组合来区分Field的具体类型。
Store
²        COMPRESS: 压缩保存。用于长文本或二进制数据
²        YES :保存
²        NO :不保存
Index
²        NO :不 建索引
²        TOKENIZED :分词, 建索引
²        UN_TOKENIZED :不分词, 建索引
²        NO_NORMS :不分词, 建索引。但是Field的值不像通常那样被保存,而是只取一个byte,这样节约存储空间
TermVector
²        NO : 不保存term vectors
²        YES : 保存term vectors。
²        WITH_POSITIONS : 保存term vectors。(保存值和token位置信息)
²        WITH_OFFSETS : 保存term vectors。(保存值和Token的offset)WITH_POSITIONS_OFFSETS:保存term vectors。(保存值和token位置信息和Token的offset)


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8780/showart_707961.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP