design search engine: how to split data in disk and memory

do we choose the first 1k post list for each keyword to store in memory. Or we choose some hot documents whose corresponding posting list be in memory?

I had the same question.
From what I heard in the class, the disk will persist all documents, it has the full set of all documents.
The memory will have only part of the documents(partitioned by document).
The data in ram needs to be partitioned by document because if partition by term the posting list can be too large to fit into memory.

Store first Xk posting list for each keyword.

why we partition by document for posting list in memory?

还有一点不明白的是为啥in memory的部分需要shard by document,直接用redis的sorted set吧一个keyword对应的posting list都存在value里面不就好了?redis value的limit是512mb,而内存中我们只存up to 1000 的长度的posting list

直接用 redis sorted set 的缺点有二:一是没办法优化取交集和取并集 (shard by document 可以单机完成再合并),二是没办法 efficient 更新 posting list

更新posting list中的某一个doc id的时间是O(logn)吧,不够efficient吗?
你说的shard by document是指存在server内存的部分吗?我记得你课上讲了需要设计一个类似redis的service来存内存那部分,是不是同一台机器即存posting list在内存也处理交集并集的运算?如果用redis cluster也可以实现的吧,把redis instance和query service运行在同样一部分机器上,另外redis instance也可以设置sharding key的吧?

更新 posting list 不 efficient 在于需要先把 posting list 全部读出来然后写 application code 来做二分查询,因为 redis 不原生支持该操作。
用 redis cluster 没办法支持 shard by document,得在 application code 里先把 posting list 按照 document 分开再写进 redis,所以说需要写一个类似 redis 的缓存,或者在 redis 基础上做些延伸。原生 redis 没有这个功能的。

你看redis tutorial文档(https://www.tutorialspoint.com/redis/redis_sorted_sets.htm)的话,redis sorted set是支持add和delete的操作的。
redis seems support partition as well Partitioning: how to split data among multiple Redis instances. – Redis

你如果是用 sorted set 倒确实是可以的,我之前的假设是存 keyword: [1, 4, 6, 7] 这样的数据,用 sorted set 的话是 keyword: [(1,1), (4,4), (6,6), (7,7)] 或者直接是 keyword: [(1,url_1), (4,url_4), (6,url_6), (7,url_7)] ,优化上有会有点差距,但功能是可以的。
Redis 支持的 Partition 是按照 key 来分,而不是根据 value 来分。你可以看一下文档。

通过稍微复杂一点的方法还是可以的,比如key是“new”的话,假如parition成十份,那每个partion上的key可以是"new_1", “new_2”, … 或者“new_machine1", “new_machine2”, …

这样做的问题是数据结构跟底层存储方式强绑定。如果改变机器数量或者某台机器当机就不太好办了。

这个也可以解决,上面的machine1,machine2可以是在consistent hash环上机器的id