描述
创建给定文档的反向索引
确保数据不包含标点符号.
样例
出一个包括id与内容的文档list(我们提供了document类).
返回一个反向索引(hashmap的key是单词, value是文档的id).
例 1:
输入:
[
{
“id”: 1,
“content”: “This is the content of document 1 it is very short”
},
{
“id”: 2,
“content”: “This is the content of document 2 it is very long bilabial bilabial heheh hahaha …”
},
]
输出:
{
“This”: [1, 2],
“is”: [1, 2],
…
}
例 2:
输入:
[
{
“id”: 1,
“content”: “you are young”
},
{
“id”: 2,
“content”: “you are handsome”
},
]
输出:
{
“are”: [1, 2],
…
}
思路
遍历每个content的每个字符串,插入到map中,并且更新map的vector
代码
1 | /** |
-------------end of filethanks for reading-------------