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]
}

index.go的更多相关文章

  1. MySQL 优化之 ICP (index condition pushdown:索引条件下推)

    ICP技术是在MySQL5.6中引入的一种索引优化技术.它能减少在使用 二级索引 过滤where条件时的回表次数 和 减少MySQL server层和引擎层的交互次数.在索引组织表中,使用二级索引进行 ...

  2. 在v-for中利用index来对第一项添加class(vue2.0)

    <li v-for="(el,index) in event" v-bind:class="{ 'm-swipe-active': !index}"> ...

  3. Ubuntu-server 下Apache2 配置.htaccess 隐藏thinkPHP项目index.php

    需要开启Apache2的rewrite模块 1.打开/etc/apache2/apache2.conf 将文件中的AllowOverride None改为AllowOverride All 2.修改m ...

  4. SQL Server-聚焦强制索引查询条件和Columnstore Index(九)

    前言 本节我们再来穿插讲讲索引知识,后续再讲数据类型中的日期类型,简短的内容,深入的理解,Always to review the basics. 强制索引查询条件 前面我们也讲了一点强制索引查询的知 ...

  5. directx12中vetex buffer、index buffer和constant buffer绑定piple line的时机

    类别 时机 函数 建Heap vetex buffer 在Draw函数中 ID3D12GraphicsCommandList::IASetVertexBuffer 否 index buffer 在Dr ...

  6. URL_MODEL 2 不能访问 在APACHE服务器上的访问方式上去除index.php

    thinkphp URL_MODEL=2,访问链接http://i.cnblogs.com/Online/index.html  报错: Not Found The requested URL /on ...

  7. index+match函数在压实度中对盒号盒质量随机不重复的最佳使用

    首先按照升序排列好盒号和盒质量,使其一一对应, 盒号    盒重量    随机值rand()     随机值大小排列rank 1         2001       0.01             ...

  8. [LeetCode] Random Pick Index 随机拾取序列

    Given an array of integers with possible duplicates, randomly output the index of a given target num ...

  9. Zend Framework 项目 index.php 的问题

    默认生成的Zend项目在public目录下会自动生成一个.htaccess文件,这是用来实现伪静态,即隐藏index.php这个唯一入口文件的. 但是,搭建项目时遇到一个问题:URL中如果不加inde ...

  10. 0103MySQL中的B-tree索引 USINGWHERE和USING INDEX同时出现

    转自博客http://www.amogoo.com/article/4 前提1,为了与时俱进,文中数据库环境为MySQL5.6版本2,为了通用,更为了避免造数据的痛苦,文中所涉及表.数据,均来自于My ...

随机推荐

  1. Java Socket:Java-NIO-Selector

    Selector 的出现,大大改善了多个 Java Socket的效率.在没有NIO的时候,轮询多个socket是通过read阻塞来完成,即使是非阻塞模式,我们在轮询socket是否就绪的时候依然需要 ...

  2. SQL 逻辑优化 case when 转为 union all

    通常数据库的优化从硬件层面去考虑可分为4个方面: CPU:即降低计算复杂度,如减少sql各类聚合函数,窗口函数,case when等. IO :(较少查询结果集过程中对数据的访问量.数据优化很大程度从 ...

  3. JavaScript中对象数组 作业 题目如下

    var BaiduUsers = [], WechatUsers = []; var User = function(id, name, phone, gender, age, salary) { t ...

  4. ffmpeg 的 tbr tbc 和 tbn的意义

    tbn = the time base in AVStream that has come from the container tbc = the time base in AVCodecConte ...

  5. No module named zope.interface error的解决

    明明安装了 zope.interface,还是出现标题错误,错误语句是 from zope.interface import ooxx 根据 http://stackoverflow.com/ques ...

  6. Lintcode400 Maximum Gap solution 题解

    [题目描述] Given an unsorted array, find the maximum difference between the successive elements in its s ...

  7. 非正则表达式检验邮箱格式是否合法(Java代码实现)

    一.邮箱格式需满足以下要求 1. 有且只有一个@                        2. @不能放在开头,也不能放在结尾                        3. @之后必须有. ...

  8. vue-awesome-swiper 的使用

    第一步 :  cnpm i vue-awesome-swiper --save (已经安装淘宝镜像 / 否则用 npm) 第二部:  在main.js 中 导入: import VueAwesomeS ...

  9. 前端工程化(三)---Vue的开发模式

    从0开始,构建前后端分离应用 导航 前端工程化(一)---工程基础目录搭建 前端工程化(二)---webpack配置 前端工程化(三)---Vue的开发模式 前端工程化(四)---helloWord ...

  10. Map集合的便利学习总结

    1.Map提供了三种便利方式 1)遍历所有key. Set<K>  keySet()  该方法会将当前Map中所有key存入一个Set集合后返回. 2)遍历所有的key-value对 Se ...