`
qindongliang1922
  • 浏览: 2188666 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
7265517b-f87e-3137-b62c-5c6e30e26109
证道Lucene4
浏览量:117664
097be4a0-491e-39c0-89ff-3456fadf8262
证道Hadoop
浏览量:126072
41c37529-f6d8-32e4-8563-3b42b2712a50
证道shell编程
浏览量:60032
43832365-bc15-3f5d-b3cd-c9161722a70c
ELK修真
浏览量:71400
社区版块
存档分类
最新评论

Lucene4.3进阶开发之见龙在田(十)

阅读更多
转载请务必注明,原创地址,谢谢配合!
http://qindongliang1922.iteye.com/

继前几篇,si,gen,_N,fdx,fdt,fnm之后,今天散仙要介绍的是Term dictionary,这也是Lucene一个非常重要的索引文件。

Term dictionary的概述,项词典包含了Lucene中所有索引的字段的term,也包含了该term所对应的文档编号和一个基于该term词频的指针和其他一些相邻数据。


下面进入正题,与项词典紧密关联的索引格式有4类,

Term Dictionary==>.tim  项词典
Term Index     ==>.tip  项索引
Frequencies    ==>.frq  项词频
Positions      ==>.prx  项位置


Term Dictionary

项词典文件,包含了每个字段的被分词后的term列表,以及一些静态统计属性
比如词频和指针定位到词频和位置通过在词频文件和位置文件之间的跳表进行访问,
详细可以参照BlockTreeTermsWriter这个类。


项词典可以插进任何的链表实现里,链表的读写实际上是一个编码和解码的过程,链表元数据,和项元数据,描述如下:

Postings Metadata --> Header, SkipInterval, MaxSkipLevels, SkipMinimum

Term Metadata --> FreqDelta, SkipDelta?, ProxDelta?

Header --> CodecHeader

SkipInterval,MaxSkipLevels,SkipMinimum --> Uint32

SkipDelta,FreqDelta,ProxDelta --> VLong

(1)头部是一个链表编码头存储的版本信息
(2)跳幅是TermDocs存储在跳跃表的一小部分,通常被用于提速DocIdSetIterator.advance(int).更大的值导致更小的索引,更快的速度,但是某些情况下会提速很小,当在较小的值时候,会导致更大的索引,
(3)跳跃的最大级别,存储在词频文件中,较小的值,在一份小的索引里,是起不到加速效果的,一些大值,在一些稍大的索引里,可以起到很大的加速,弄清楚词频文件的格式,将有助于我们理解它。
(4)较小的项词频,是为了跳过任何数据。

FreqDelta determines the position of this term's TermFreqs within the .frq file. In particular, it is the difference between the position of this term's data in that file and the position of the previous term's data (or zero, for the first term in the block).


ProxDelta determines the position of this term's TermPositions within the .prx file. In particular, it is the difference between the position of this term's data in that file and the position of the previous term's data (or zero, for the first term in the block. For fields that omit position data, this will be 0 since prox information is not stored.


SkipDelta determines the position of this term's SkipData within the .frq file. In particular, it is the number of bytes after TermFreqs that the SkipData starts. In other words, it is the length of the TermFreq data. SkipDelta is only stored if DocFreq is not smaller than SkipMinimum.



项索引.tip

项索引包含了一个索引可以访问项词典的数据,如果通过项索引可以任意的访问项词典文件,

词频文件.frq

词频文件记录了索引中的每个term所对应的文档列表,


FreqFile (.frq) --> Header, <TermFreqs, SkipData?> TermCount
Header --> CodecHeader
TermFreqs --> <TermFreq> DocFreq
TermFreq --> DocDelta[, Freq?]
SkipData --> <<SkipLevelLength, SkipLevel> NumSkipLevels-1, SkipLevel> <SkipDatum>
SkipLevel --> <SkipDatum> DocFreq/(SkipInterval^(Level + 1))
SkipDatum --> DocSkip,PayloadLength?,OffsetLength?,FreqSkip,ProxSkip,SkipChildLevelPointer?
DocDelta,Freq,DocSkip,PayloadLength,OffsetLength,FreqSkip,ProxSkip --> VInt
SkipChildLevelPointer --> VLong

TermFreqs是有序的通过term,在项词典中默认被排序,

DocDelta: if frequencies are indexed, this determines both the document number and the frequency. In particular, DocDelta/2 is the difference between this document number and the previous document number (or zero when this is the first document in a TermFreqs). When DocDelta is odd, the frequency is one. When DocDelta is even, the frequency is read as another VInt. If frequencies are omitted, DocDelta contains the gap (not multiplied by 2) between document numbers and no frequency information is stored.



For example, the TermFreqs for a term which occurs once in document seven and three times in document eleven, with frequencies indexed, would be the following sequence of VInts:

15, 8, 3

If frequencies were omitted (FieldInfo.IndexOptions.DOCS_ONLY) it would be this sequence of VInts instead:

7,4

DocSkip records the document number before every SkipInterval th document in TermFreqs. If payloads and offsets are disabled for the term's field, then DocSkip represents the difference from the previous value in the sequence. If payloads and/or offsets are enabled for the term's field, then DocSkip/2 represents the difference from the previous value in the sequence. In this case when DocSkip is odd, then PayloadLength and/or OffsetLength are stored indicating the length of the last payload/offset before the SkipIntervalth document in TermPositions.

PayloadLength indicates the length of the last payload.

OffsetLength indicates the length of the last offset (endOffset-startOffset).

FreqSkip and ProxSkip record the position of every SkipInterval th entry in FreqFile and ProxFile, respectively. File positions are relative to the start of TermFreqs and Positions, to the previous SkipDatum in the sequence.

For example, if DocFreq=35 and SkipInterval=16, then there are two SkipData entries, containing the 15 th and 31 st document numbers in TermFreqs. The first FreqSkip names the number of bytes after the beginning of TermFreqs that the 16 th SkipDatum starts, and the second the number of bytes after that that the 32 nd starts. The first ProxSkip names the number of bytes after the beginning of Positions that the 16 th SkipDatum starts, and the second the number of bytes after that that the 32 nd starts.

Each term can have multiple skip levels. The amount of skip levels for a term is NumSkipLevels = Min(MaxSkipLevels, floor(log(DocFreq/log(SkipInterval)))). The number of SkipData entries for a skip level is DocFreq/(SkipInterval^(Level + 1)), whereas the lowest skip level is Level=0.
Example: SkipInterval = 4, MaxSkipLevels = 2, DocFreq = 35. Then skip level 0 has 8 SkipData entries, containing the 3rd, 7th, 11th, 15th, 19th, 23rd, 27th, and 31st document numbers in TermFreqs. Skip level 1 has 2 SkipData entries, containing the 15th and 31st document numbers in TermFreqs.
The SkipData entries on all upper levels > 0 contain a SkipChildLevelPointer referencing the corresponding SkipData entry in level-1. In the example has entry 15 on level 1 a pointer to entry 15 on level 0 and entry 31 on level 1 a pointer to entry 31 on level 0.


位置信息.prx

位置文件包含每个term在document中的位置列表,如果字段中忽略了位置信息,那么这个文件将不会被记录。
ProxFile (.prx) --> Header, <TermPositions> TermCount
Header --> CodecHeader
TermPositions --> <Positions> DocFreq
Positions --> <PositionDelta,PayloadLength?,OffsetDelta?,OffsetLength?,PayloadData?> Freq
PositionDelta,OffsetDelta,OffsetLength,PayloadLength --> VInt
PayloadData --> bytePayloadLength


TermPostitons也是有序的基于term,默认排序在项词典中。

Positions entries are ordered by increasing document number (the document number is implicit from the .frq file).

PositionDelta is, if payloads are disabled for the term's field, the difference between the position of the current occurrence in the document and the previous occurrence (or zero, if this is the first occurrence in this document). If payloads are enabled for the term's field, then PositionDelta/2 is the difference between the current and the previous position. If payloads are enabled and PositionDelta is odd, then PayloadLength is stored, indicating the length of the payload at the current term position.

For example, the TermPositions for a term which occurs as the fourth term in one document, and as the fifth and ninth term in a subsequent document, would be the following sequence of VInts (payloads disabled):

4, 5, 4

PayloadData is metadata associated with the current term position. If PayloadLength is stored at the current position, then it indicates the length of this payload. If PayloadLength is not stored, then this payload has the same length as the payload at the previous position.

OffsetDelta/2 is the difference between this position's startOffset from the previous occurrence (or zero, if this is the first occurrence in this document). If OffsetDelta is odd, then the length (endOffset-startOffset) differs from the previous occurrence and an OffsetLength follows. Offset data is only written for


转载请务必注明,原创地址,谢谢配合!
http://qindongliang1922.iteye.com/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics