index.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package types
  2. type DocumentIndex struct {
  3. // 文本的DocId
  4. DocId uint64
  5. // 文本的关键词长
  6. TokenLength float32
  7. // 加入的索引键
  8. Keywords []KeywordIndex
  9. }
  10. // 反向索引项,这实际上标注了一个(搜索键,文档)对。
  11. type KeywordIndex struct {
  12. // 搜索键的文本
  13. Text string
  14. // 搜索键词频
  15. Frequency float32
  16. // 搜索键在文档中的起始字节位置,按照升序排列
  17. Starts []int
  18. }
  19. // 索引器返回结果
  20. type IndexedDocument struct {
  21. DocId uint64
  22. // BM25,仅当索引类型为FrequenciesIndex或者LocationsIndex时返回有效值
  23. BM25 float32
  24. // 关键词在文档中的紧邻距离,紧邻距离的含义见computeTokenProximity的注释。
  25. // 仅当索引类型为LocationsIndex时返回有效值。
  26. TokenProximity int32
  27. // 紧邻距离计算得到的关键词位置,和Lookup函数输入tokens的长度一样且一一对应。
  28. // 仅当索引类型为LocationsIndex时返回有效值。
  29. TokenSnippetLocations []int
  30. // 关键词在文本中的具体位置。
  31. // 仅当索引类型为LocationsIndex时返回有效值。
  32. TokenLocations [][]int
  33. }