0
点赞
收藏
分享

微信扫一扫

sphinx索引分析——文件格式和字典是double array trie 检索树,索引存储 – 多路归并排序,文档id压缩 – Variable Byte Coding

1 概述

这是基于开源的sphinx全文检索引擎的架构代码分析,本篇主要描述index索引服务的分析。当前分析的版本 sphinx-2.0.4

2 index 功能

3 文件表

4 索引文件结构

4.1 spa 文件

存储文档属性,在extern文档信息存储模式下使用。

spa文件格式 => 属性值存储

item

item

item

item

item

docid

attr0

attr1

attr mva(spm file position)


spa文件格式 => 在文件的末尾存储每个属性的最大最小值

item

item

item

item

item

item

item

attr0 min

attr1 min


attr0 max

attr1 max

attr mva max


4.2 spi 文件

存储词列表,词id和指向spd文件的指针。

  • wordid 采用crc32编码
  • 每64个word插入一个检查点,重新开始存储wordid和spd文件偏移的差值
  • 保存doc的计数值,hit的计数值

spi文件格式 => 倒排索引存储

item

item

item

item

wordid(crc32)或vlb

spd文件偏移的差值

doc的计数值

hit的计数值

spi文件格式 => 文件的末尾存储文件内的检查点信息

item

item

item

checkpoint1 sWord len

sWord

在文件内的 offset

4.3 spd 文件

存储每个词id可匹配的文档id列表。

文件格式 => 只有一次命中的时候

item

item

item

item

docid vlb

hit count

hit field

hit position

文件格式 => 多次命中的时候

item

item

item

item

docid vlb

hit count

field mask

hit file(spp) position 差值

4.4 sph 文件

存储索引头信息。

格式0

item0

item1

item2

item3

item4

version

bits

docinfo mode

schema

min doc

格式1

item5

item6

item7

item8

item 9

ckpoint pos

ckpoint count

total doc

total bytes

index setting

格式2

item10

item 11

item12

item13

tokenizer

dictionary

kill list

min max index

4.5 spk 文件

存储kill-lists信息。

4.6 spm 文件

存储mva数据

  • 分块存储
  • 多路归并排序,创建spm文件

spm文件格式

item

item

item

docid

A a0,a1,a2 …

B b0,b1,b2 …

4.7 sps 文件

存储字符串属性

4.8 spp 文件

4.8.1 第一次扫描创建的命中文件(临时存储命中信息)

存储每个词的命中数。

  • 文件内分块存储
  • 块内同类递增排序,优先级为 wordid > docid > hitpos
  • 在wordid,docid相等的条件下,hitpos差分存储
  • 在wordid相等的条件下docid差分存储
  • wordid差分存储

hit block 的存储结构列表如下

item

item

item

item

item

wordid0

docid0

pos0, pos1, pos2 …

hitcount

field mask

 

docid1

pos0, pos1, pos2 …

hitcount

field mask

 

docid2

pos0, pos1, pos2 …

hitcount

field mask

wordid1

docid0

pos0, pos1, pos2 …

hitcount

field mask

 

docid1

pos0, pos1, pos2 …

hitcount

field mask






 

4.8.2 最终创建的spp文件格式

当doc切换后存储的第一个是hit position, 后面存储的是差值。

spp文件存储格式

item

hit position 差值

4.9 sps 文件

存储字符串属性数据。

举报

相关推荐

0 条评论