-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtests.py
59 lines (47 loc) · 1.53 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import gofound
def add_document():
"""
添加索引
"""
client = gofound.Client(url="http://127.0.0.1:5678/api")
res = client.add_document(1000, "探访海南自贸港“样板间”", {
"content": "洋浦经济开发区地处海南西北部洋浦半岛,是21世纪海上丝绸之路与西部陆海新通道的交汇节点。是国务院1992年批准设立的。我国第一个由外商成片开发、享受保税区政策的国家级开发区",
})
print(res)
def search():
"""
搜索
"""
client = gofound.Client(url="http://127.0.0.1:5678/api")
res = client.query("探访海南自贸港", page=1, limit=10, order="desc")
print(res)
# 遍历数据
if res.get('state'):
documents = res.get('data').get('documents')
if documents:
for item in documents:
print(item)
def highlight():
"""
关键词高亮
"""
client = gofound.Client(url="http://127.0.0.1:5678/api")
res = client.query("探访海南自贸港", page=1, limit=10, order="desc", highlight={'preTag': '<span>', 'postTag': '</span>'})
print(res)
# 遍历数据
if res.get('state'):
documents = res.get('data').get('documents')
if documents:
for item in documents:
print(item)
def remove():
"""
删除索引
"""
client = gofound.Client(url="http://127.0.0.1:5678/api")
res = client.remove_document(1000)
print(res)
if __name__ == '__main__':
add_document()
search()
remove()