2012-07-24
Number and Date in Lucene 3.6.0
Lucene 早期只有一種文字欄位,當遇到數值類別的資料時,除了精確查詢外,不管是範圍查詢或者是排序都很難用,後來 Lucene 終於在 2.9.0 支援數值欄位,並且衍生支援日期欄位。
建立數值索引是用 NumericField 取代原本的 Field,查詢數值索引時改用 NumericRangeQuery。
另外,除了純數值欄位外,還有一種文數字混合的欄位,也就是字串裡有數值存在,這可以當作是一種文字來處理。
建立數值索引是用 NumericField 取代原本的 Field,查詢數值索引時改用 NumericRangeQuery。
另外,除了純數值欄位外,還有一種文數字混合的欄位,也就是字串裡有數值存在,這可以當作是一種文字來處理。
標籤:
Lucene
2012-07-20
Lock in Lucene 3.6.0
Lucene 更新索引檔的過程:
- IndexWriter.addDocument() 或 IndexWriter.deleteDocument()
- Flush Buffered documents - 達到門檻值才會觸發,或者 IndexWriter.commit() 會觸發 flush,或者 IndexWriter.close() 會觸發 IndexWriter.commit(),而 IndexWriter.commit() 再觸發 flush。
- IndexWriter.prepareCommit()
- IndexWriter.commit() 或 IndexWriter.rollback()
- IndexWriter.close()
標籤:
Lucene
2012-07-18
Boost and Norms in Lucene 3.6.0
這篇筆記源自於「Norms」這個陌生的字眼,還有「Boost」。
Lucene 查詢結果預設是用 score 做排序,分數愈高的排前面,分數的計算相當複雜,不過有兩個影響分數的因素:
用 TestCase 搭配 RAMDirectory 來測試。
Lucene 查詢結果預設是用 score 做排序,分數愈高的排前面,分數的計算相當複雜,不過有兩個影響分數的因素:
- Field 的值(字串)愈長,得到的分數愈低。
- 使用 Boost 為特定 Document 或 Field 加分。
用 TestCase 搭配 RAMDirectory 來測試。
標籤:
Lucene
2012-07-13
Hello Lucene 3.6.0
Lucene 不是一個應用程式,只是 Library,用來建立與查詢索引。
查詢要快,就要使用索引(Index),就像是書本後面常有的索引表,用索引表來找一個字遠比從書本第一頁找起一定快得多;作為一個 Information Retrieval(IR) Library,除了查詢功能外,還要有建立索引的功能。
建立索引 123
查詢索引 123
查詢要快,就要使用索引(Index),就像是書本後面常有的索引表,用索引表來找一個字遠比從書本第一頁找起一定快得多;作為一個 Information Retrieval(IR) Library,除了查詢功能外,還要有建立索引的功能。
建立索引 123
- Document - Document 由一堆 Field 組成,Field 由 name-value 組成,value 就是放索引文字的地方,name 自行定義,Document 可以看成是 Java 的 Map。
- Analyzer - 拆字,將 Document 裡的 Field value 拆成關鍵字。
- IndexWriter - 將關鍵字寫到索引檔,就是 Directory 裡。
查詢索引 123
- IndexSearcher - 用 IndexReader 開啟索引檔 Directory。
- Query - 以關鍵字建立 Query 物件。
- TopDocs - 將 Query 物件丟給 IndexSearch 去做查詢,得到結果 TopDocs。
標籤:
Lucene
訂閱:
文章 (Atom)