-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathutils (1).py
35 lines (30 loc) · 847 Bytes
/
utils (1).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
def print_result(result):
""" Print results with colorful formatting """
for i,item in enumerate(result):
print(f'item {i}')
for key in item.keys():
print(f"{key}:{item.get(key)}")
print()
print()
### Revised version
def keyword_search(query,
client,
results_lang='en',
properties = ["title","url","text"],
num_results=3):
where_filter = {
"path": ["lang"],
"operator": "Equal",
"valueString": results_lang
}
response = (
client.query.get("Articles", properties)
.with_bm25(
query=query
)
.with_where(where_filter)
.with_limit(num_results)
.do()
)
result = response['data']['Get']['Articles']
return result