-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkubic_data.py
More file actions
102 lines (90 loc) · 3.43 KB
/
kubic_data.py
File metadata and controls
102 lines (90 loc) · 3.43 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from elasticsearch import Elasticsearch
import esAccount as esAcc
from kubic_user import *
def ESConnection():
ES = Elasticsearch(
[esAcc.host],
http_auth=(esAcc.id, esAcc.password),
scheme="https",
port=19200,
verify_certs=False
)
return ES, esAcc.index
ES, index = ESConnection()
def simple_search(request):
# search the keyword in the document
print(request)
response = ES.search(index=index, body={
"size": request['numOfCnt'],
"query": {
"multi_match": {
"query": request['keyword'],
"fields": ["post_title", "post_body", "fileName", "fileContent", "file_extracted_content"]
}
}
})
return response
def detailed_search(request):
query = {
"size": request['numOfCnt'],
"query": {
"bool": {
"must":[
{"wildcard": {"post_title": "*"+request['keyInTitle']+"*" }},
],
# "sort": [{"post_date": {"order" : "desc" #오름차순: asc, 내림차순: desc
# }}]
"filter": {"range": { "post_date": { "gte": request['startDate'], "lte": request['endDate'] }}}
},
}
}
if not request['keyInBody'] == "":
query['query']['bool']['must'].append({"wildcard": {"post_body": "*"+request['keyInBody']+"*" }})
if not request['writer'] == "":
query['query']['bool']['must'].append({"wildcard": {"post_writer": "*"+request['writer']+"*" }})
if not request['institution'] == "":
query['query']['bool']['must'].append({"wildcard": {"published_institution": "*"+request['institution']+"*" }})
print("query: ",query)
response = ES.search(index=esAcc.index, body=query)
# print("response:",str(response)[:30])
return response
def search_in_my_doc(request):
idList = getMyDocByEmail()
query = {
"size": request['numOfCnt'],
"query": {
"bool": {
"must":[ {"wildcard": {"post_title": "*"+request['keyInTitle']+"*" }},
],
# "sort": [{"post_date": {"order" : "desc" #오름차순: asc, 내림차순: desc
# }}]
"filter": [
# {"range": { "post_date": { "gte": request['startDate'], "lte": request['endDate'] }}},
{"terms": {"_id": idList}},
],
}
}
}
if not request['keyInBody'] == "":
query['query']['bool']['must'].append({"wildcard": {"post_body": "*"+request['keyInBody']+"*" }})
if not request['writer'] == "":
query['query']['bool']['must'].append({"wildcard": {"post_writer": "*"+request['writer']+"*" }})
if not request['institution'] == "":
query['query']['bool']['must'].append({"wildcard": {"published_institution": "*"+request['institution']+"*" }})
print("query: ",query)
response = ES.search(index=esAcc.index, body=query)
# print("response:",str(response)[:30])
return response
def retrieve_all(request):
query = {
"from" : request['page'] * request['numOfCnt'] +1,
"size": int(request['numOfCnt']),
}
response = ES.search(index=esAcc.index, body=query)
return response
def esSearch(searchType, request):
if searchType=='simple_search': return simple_search(request)
elif searchType=='detailed_search': return detailed_search(request)
elif searchType=='my_doc': return search_in_my_doc(request)
elif searchType == 'retrieve_all': return retrieve_all(request)
else: return None