Lucene使用文件擴展名標識不同的索引文件。如.fnm文件存儲域Fields名稱及其屬性,.fdt存儲文檔各項域數據,.fdx存儲文檔在fdt中的偏移位置即其索引文件,.frq存儲文檔中term位置數 據,.tii文件存儲term字典,.tis文件存儲term頻率數據,.prx存儲term接近度數據,.nrm存儲調節因子數據,另外 segments_X文件存儲當前最新索引片段的信息,其中X為其最新修改版本,segments.gen存儲當前版本即X值。
?
本系列文章將詳細介紹的這些文件的數據存儲細節。下面的圖描述了一個典型的lucene索引文件列表:
它們的關系圖則如下所示:
?
?
其中, Segments是一個比較特殊的結構:
- 一個索引可以包含多個段,段與段之間是獨立的,添加新文檔可以生成新的段,不同的段可以合并。
- 如上圖,具有相同前綴文件的屬同一個段,圖中共兩個段 "_0" 和 "_1"。
- segments.gen和segments_5是段的元數據文件,也即它們保存了段的屬性信息
?
?
《索引文件格式》專題用例
?
在后面詳細介紹每個索引文件的時候,都會使用一個例子中的數據進行分析。而這個例子就是《 索引創建(5):索引數據池及內存數據細節 》中在內存中所建立好的那個倒排索引的例子。這里再次詳細說明一下,后面將不再對這個例子做出說明:
?
(1)待索引文件集合一共四篇文檔,分別是
文檔名 |
文檔路徑 | 文檔內容 |
lucene 1 | E:\實驗\content\lucene 1.txt |
lucene lucene lucene lucene lucene term .
|
lucene 2 | E:\實驗\content\lucene 2.txt | lucene lucene lucene lucene lucene term term. |
lucene 3 | E:\實驗\content\lucene 3.txt | term term term lucene lucene lucene lucene lucene. |
lucene 4 | E:\實驗\content\lucene 4.txt | term |
?
(2)內存源數據組織形式(Document/Fields) 參見《 索引創建(1):IndexWriter索引器 》中的索引創建代碼:
- for ?(每個文本文件)?{???????
- ????????? //Lucene的文檔結構?? ??
- ?????????Document?doc?=? new ?Document();?????????????????????????
- ????????? //文件名稱,可查詢,不分詞?? ??
- ?????????String?fileName=file.getName().substring( 0 ,file.getName().indexOf( "." ));????
- ?????????doc.add( new ?Field( "name" ,fileName,?Field.Store.YES,?Field.Index.NOT_ANALYZED));??????
- ?????????? //文件路徑,可查詢,不分詞?? ??
- ?????????String?filePath=file.getPath();????
- ?????????doc.add( new ?Field( "path" ,?filePath,?Field.Store.YES,?Field.Index.NOT_ANALYZED));????
- ???????? //文件內容,需要檢索?? ??
- ?????????doc.add( new ?Field( "content" ,? new ?FileReader(file)));????????????????
- ????????? //使用索引器對Document文檔建索引?? ??
- ????????standardWriter.addDocument(doc);??????
- }?????
for (每個文本文件) { //Lucene的文檔結構 Document doc = new Document(); //文件名稱,可查詢,不分詞 String fileName=file.getName().substring(0,file.getName().indexOf(".")); doc.add(new Field("name",fileName, Field.Store.YES, Field.Index.NOT_ANALYZED)); //文件路徑,可查詢,不分詞 String filePath=file.getPath(); doc.add(new Field("path", filePath, Field.Store.YES, Field.Index.NOT_ANALYZED)); //文件內容,需要檢索 doc.add(new Field("content", new FileReader(file))); //使用索引器對Document文檔建索引 standardWriter.addDocument(doc); }
這樣,其數據源在Lucene的內存結構Document, Field表示如下:
?
真實文檔名 |
Document對象 |
lucene 1 | doc1 |
lucene 2 | doc2 |
lucene 3 | doc3 |
lucene 4 | doc4 |
?
每個document包含的Field信息如下(以doc1舉例):
域 | 域名 | 域數據值 |
是否被索引 (Indexed) |
是否被存儲 (Stored) |
Field1 | "name" |
"lucene 1"
|
???? Y | ??????? N |
Field2 | "path" |
"E:\實驗\content\lucene 1.txt"
|
???? Y | ??????? N |
Field3 | "content" | lucene lucene lucene lucene lucene term . | ???? Y | ??????? N |
?
(3)內存索引表的結構如:《 索引創建 (5):索引數據池及內存數據細節 》中所述。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
