feat: - vector
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
# 倒排索引
|
||||
index = {}
|
||||
# 文档存储
|
||||
documents = {}
|
||||
|
||||
|
||||
def add_document(doc_id, content):
|
||||
documents[doc_id] = content
|
||||
for word in content.lower().split():
|
||||
if word not in index:
|
||||
index[word] = []
|
||||
if doc_id not in index[word]:
|
||||
index[word].append(doc_id)
|
||||
|
||||
|
||||
def serch(keyword):
|
||||
return index.get(keyword.lower(), [])
|
||||
|
||||
|
||||
add_document(1, "hello world")
|
||||
add_document(2, "world of python")
|
||||
add_document(3, "hello python")
|
||||
|
||||
print(index)
|
||||
print(documents)
|
||||
Reference in New Issue
Block a user