Lucene Field 1.*版本和2.*版本比较

来源:互联网 发布:翻译软件推荐 编辑:程序博客网 时间:2024/06/07 15:36

Field没了Keyword、UnIndexed、UnStored、Text这几个静态成员,只能用
Field(String, String, Store, Index)。
Keyword对应Field.Store.YES, Field.Index.UN_TOKENIZED,
UnIndexed 对应Field.Store.YES, Field.Index.NO,
UnStored对应Field.Store.NO, Field.Index.TOKENIZED,
Text对应Field.Store.YES, Field.Index.TOKENIZED。

FSDirectory.getDirectory的有两个参数的变成了depresed 了。现在要用只有一个参数的。

BooleanQuery的add方法也变了。原来是用两个boolean值组合的,现在 使用BooleanClause.Occur的几个静态成员了。

暂时就发现这点差异。[引自:http://syre.blogbus.com/logs/4736803.html]

(二)Field类一共有5种构造函数:

(String name, byte[] value, store)
           Create a stored field with binary value.(String name, Reader reader)
           Create a tokenized and indexed field that is not stored.(String name, Reader reader, termVector)
           Create a tokenized and indexed field that is not stored, optionally with storing term vectors.(String name, String value, store, index)
           Create a field by specifying its name, value and how it will be saved in the index.(String name, String value, store, index, 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、文件系统路径信息、时间日期、人名、居民身份证、电话号码等等通常将被索引并且完整的存储在索引中,但一般不需要切分词,通常用上面的第四个构造函数,第三四个参数分别为.YES, .YES。而长文本通常可用第3个构造函数。引用[http://blog.csdn.net/colasnail/archive/2007/03/21/1536417.aspx]

(三)1.      2.0以前的版本

UnIndexed: Field的值将被保存到索引文件,不为Field的值建立索引,因此不能通过该Field搜索文档。UnStored: Field的值不被保存到索引文件,将Field的值分词后建立索引

tags:Lucene Lucene.net Field Field.store Field.UnStored Field.Keyword Field.Text

  • Text: Field的值分词后建立索引。如果参数为String值将被保存,为Reader值不被保存
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)


记于2012.1.18     黯風夜隱

原创粉丝点击