lucene-2.9.0 索引过程(一) TermsHashPerField

TermsHashPerField

 

一、类功能概述:

负责词项的索引过程,每个字段有相应的一个TermsHashPerField;当索引某字段词项时,使用对应TermsHashPerFieldadd()函数完成(一个)词项索引过程,并将索引内容(词项字符串/指针信息/位置信息等)存储于内存缓冲中

 

二、类成员说明:

 

2.1 final int streamCount;

如果需要记录词频和位置,此值为2(用两个int记录偏移指针),否则为1

 

// 代码如下

streamCount = consumer.getStreamCount(); // FreqProxTermsWriterPerField //

 

2.2 TermAttribute termAtt;

分词后的词项存储于此,因此索引时从termAtt中将词项取出

 

2.3  RawPostingList[]RawPostingList

代码如下

private RawPostingList[] postingsHash = new RawPostingList[postingsHashSize];

private RawPostingList p;

 

每个p记录了该词项的偏移地址、文档编号、文档频率(df)、位置信息

并存储在postingsHash中,下标是哈希值

 

保存了偏移地址

abstract class RawPostingList {

  int textStart;

  int intStart;

  int byteStart;

}

 

但实际上存储的是FreqProxTermsWriter.PostingList

意思很浅显,代码如下:

static final class PostingList extends RawPostingList {

    int docFreq;    // # times this term occurs in the current doc

    int lastDocID;  // Last docID where this term occurred

    int lastDocCode;  // Code for prior doc

    int lastPosition;    // Last position where this term occurred

  }

 

因此postingsHash存储的其实是

[0]= FreqProxTermsWriter$PostingList  (id=23)   

         byteStart= 0    

         docFreq= 1      

         intStart= 0       

         lastDocCode= 0       

         lastDocID= 0   

         lastPosition= 0         

         textStart= 0    

 

postingsHash存储的是该字段所有词项的一些索引信息,根据词项字符的编码值作为初始值hashpostingsHash

代码如下:

int hashPos = code & postingsHashMask;

 

如果出现地址冲突,以固定步长递增编码值,查找空位置,填入p,此步长为

 

final int inc = ((code>>8)+code)|1;

 

代码如下

 

do {

        code += inc;

        hashPos = code & postingsHashMask ;

        p = postingsHash[hashPos];

} while (p != null && !postingEquals(tokenText, tokenTextLen));

 

 

另外,如果postingsHash的使用率超过一半(使用率可调),将扩展之

代码如下

      if (numPostings == postingsHashHalfSize)

        rehashPostings(2*postingsHashSize);

 

2.2 字符串缓冲

 

以下三个是存储索引内容的缓冲,最终还是从DocumentsWriter中获得,此缓冲中的索引结构并不是最终写入磁盘的索引内容结构

intPool = perThread.intPool;

charPool = perThread.charPool

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值