(一)最近用Lucene開發全文檢索。《Lucene in Action》這本書用的是Lucene 1.4。我自己下的是最新的2.1。然后就發現了很多不同的地方。
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種構造函數:
Field(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以前的版本
UnIndexed: Field的值將被保存到索引文件,不為Field的值建立索引,因此不能通過該Field搜索文檔。 UnStored: Field的值不被保存到索引文件,將Field的值分詞后建立索引
tags:Lucene Lucene.net Field Field.store Field.UnStored Field.Keyword Field.Text
- Text: Field的值分詞后建立索引。如果參數為String值將被保存,為Reader值不被保存
用幾個內部類的組合來區分Field的具體類型。
- Store
- Index
- TermVector
comefrom:http://hi.baidu.com/gw_noah/blog/item/0646fbc4c3418daa8226ac0c.html