当前位置:网站首页>搜索 正排索引 和 倒排索引 区别
搜索 正排索引 和 倒排索引 区别
2022-07-05 15:48:00 【软件工程小施同学】
一、什么是正排索引(forward index)?
简言之,由key查询实体的过程,使用正排索引。
例如,用户表:
t_user(uid, name, passwd, age, sex)
由uid查询整行的过程,就是正排索引查询。
画外音:时间复杂度可以认为是O(1)。
二、什么是倒排索引(inverted index)?
与正排索引相反,由item查询key的过程,使用倒排索引。
对于网页搜索,倒排索引可以理解为:
Map<item, list<url>>
能够由查询词快速找到包含这个查询词的网页的数据结构。
画外音:时间复杂度也是O(1)。
举个例子,假设有3个网页:
url1 -> “我爱北京”
url2 -> “我爱到家”
url3 -> “到家美好”
这是一个正排索引:
Map<url, page_content>。
分词之后:
url1 -> {我,爱,北京}
url2 -> {我,爱,到家}
url3 -> {到家,美好}
这是一个分词后的正排索引:
Map<url, list<item>>。
分词后倒排索引:
我 -> {url1, url2}
爱 -> {url1, url2}
北京 -> {url1}
到家 -> {url2, url3}
美好 -> {url3}
由检索词item快速找到包含这个查询词的网页Map<item, list<url>>就是倒排索引。
画外音:明白了吧,词到url的过程,是倒排索引。
正排索引和倒排索引是spider和build_index系统提前建立好的数据结构,为什么要使用这两种数据结构,是因为它能够快速的实现“用户网页检索”需求。
画外音,业务需求决定架构实现,查询起来都很快。
边栏推荐
- 异常com.alibaba.fastjson.JSONException: not match : - =
- 详解SQL中Groupings Sets 语句的功能和底层实现逻辑
- 事务回滚异常
- The new version of effect editor is online! 3D rendering, labeling, and animation, this time an editor is enough
- 后台系统发送验证码功能
- 漫画:什么是分布式事务?
- obj解析为集合
- 《21天精通TypeScript-3》-安装搭建TypeScript开发环境.md
- 移动办公时如何使用frp内网穿透+teamviewer方式快速连入家中内网主机
- Mistakes made when writing unit tests
猜你喜欢

项目中批量update

Which keywords will conflict with the abstract keyword

Background system sending verification code function

单商户 V4.4,初心未变,实力依旧!

scratch五彩糖葫芦 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月

Five common negotiation strategies of consulting companies and how to safeguard their own interests

Why should we learn mathematical modeling?

Defining strict standards, Intel Evo 3.0 is accelerating the upgrading of the PC industry
Intel 13th generation Raptor Lake processor information exposure: more cores, larger cache

vulnhub-FirstBlood
随机推荐
求解汉诺塔问题【修改版】
助力数字经济发展,夯实数字人才底座—数字人才大赛在昆成功举办
Arduino controls a tiny hexapod 3D printing robot
The difference between abstract classes and interfaces
Record a 'very strange' troubleshooting process of cloud security group rules
Is it safe for Guotai Junan to open an account online
Today's sleep quality record 79 points
17.[STM32]仅用三根线带你驱动LCD1602液晶
Modify PyUnit_ Time makes it support the time text of 'xx~xx months'
降本40%!Redis多租户集群的容器化实践
国泰君安网上开户安全吗
Cs231n notes (top) - applicable to 0 Foundation
list集合根据对象某属性求和,最大值等
Cs231n notes (medium) -- applicable to 0 Foundation
Record the pits encountered in the raspberry pie construction environment...
Migrate /home partition
漫画:什么是八皇后问题?
新春限定丨“牛年忘烦”礼包等你来领~
APICloud云调试解决方案
yarn 常用命令