zoukankan      html  css  js  c++  java
  • index.go

    package types

    type DocumentIndex struct {
        // 文本的DocId
        DocId uint64

        // 文本的关键词长
        TokenLength float32

        // 加入的索引键
        Keywords []KeywordIndex
    }

    // 反向索引项,这实际上标注了一个(搜索键,文档)对。
    type KeywordIndex struct {
        // 搜索键的UTF-8文本
        Text string

        // 搜索键词频
        Frequency float32

        // 搜索键在文档中的起始字节位置,按照升序排列
        Starts []int
    }

    // 索引器返回结果
    type IndexedDocument struct {
        DocId uint64

        // BM25,仅当索引类型为FrequenciesIndex或者LocationsIndex时返回有效值
        BM25 float32

        // 关键词在文档中的紧邻距离,紧邻距离的含义见computeTokenProximity的注释。
        // 仅当索引类型为LocationsIndex时返回有效值。
        TokenProximity int32

        // 紧邻距离计算得到的关键词位置,和Lookup函数输入tokens的长度一样且一一对应。
        // 仅当索引类型为LocationsIndex时返回有效值。
        TokenSnippetLocations []int

        // 关键词在文本中的具体位置。
        // 仅当索引类型为LocationsIndex时返回有效值。
        TokenLocations [][]int
    }

    // 方便批量加入文档索引
    type DocumentsIndex []*DocumentIndex

    func (docs DocumentsIndex) Len() int {
        return len(docs)
    }
    func (docs DocumentsIndex) Swap(i, j int) {
        docs[i], docs[j] = docs[j], docs[i]
    }
    func (docs DocumentsIndex) Less(i, j int) bool {
        return docs[i].DocId < docs[j].DocId
    }

    // 方便批量删除文档索引
    type DocumentsId []uint64

    func (docs DocumentsId) Len() int {
        return len(docs)
    }
    func (docs DocumentsId) Swap(i, j int) {
        docs[i], docs[j] = docs[j], docs[i]
    }
    func (docs DocumentsId) Less(i, j int) bool {
        return docs[i] < docs[j]
    }

  • 相关阅读:
    linux中和salt中的fqdn测试小节
    centos7离线安装rpm包自动解决依赖
    (转)mysql创建表时反引号的作用
    mysql更新一个表里的字段等于另一个表某字段的值
    Navicat permium工具连接Oracle的配置
    IA64与x64的区别
    vsphere和vmware快照的不足之处
    mysql查看某库表大小
    sql之left join、right join、inner join的区别(转)
    读锁和写锁
  • 原文地址:https://www.cnblogs.com/zhangboyu/p/7461643.html
Copyright © 2011-2022 走看看