-
Notifications
You must be signed in to change notification settings - Fork 1
/
event.py
108 lines (62 loc) · 1.84 KB
/
event.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
60
61
62
63
64
65
66
67
68
69
import boto3
import os
import json
from header import with_cors
@with_cors
def search(event,context):
client = boto3.client('cloudsearchdomain', endpoint_url=os.environ.get('CLOUDSEARCH_URL'))
args= event['queryStringParameters']
"""GET FIELDS OF QUERY GIVEN IN EVENT"""
idioma=args.get('idioma')
term=args.get('s')
centre=args.get('centre')
sector=args.get('sector_productiu')
investigador=args.get('nom_investigador')
"""TRANSFORMING DATA TO BUILD QUERY"""
if(centre!=None):
centre=centre.split(',')
if(sector!=None):
sector=sector.split(',')
if(investigador!=None):
investigador=investigador.split(',')
consulta="(and idioma:'%s' "%(idioma)
"""BUILDING QUERY"""
if term==None:
consulta+="(term ' ') "
else:
consulta+="(term '%s') "%(term)
if sector!=None:
consulta+="(or "
for i in sector:
element=i
consulta +="sector: '%s' "%element
print(consulta)
if centre!=None:
existe=consulta.find('or')
if(existe== -1):
consulta+="(or "
for i in centre:
element=i
consulta +="centre: '%s' "%element
if investigador!=None:
existe=consulta.find('or')
if(existe== -1):
consulta+="(or "
for i in investigador:
element=i
consulta +="investigadors: '%s' "%element
existe = consulta.find('or')
if (existe != -1):
consulta += ")"
consulta += "( not content_type:'fitxa') (not content_type:'grup')"
consulta+=")"
"""SEARCHING IN CLOUDSEARCH"""
response = client.search(
query=consulta,
queryParser='structured',
size=1000)
ret={
"statusCode":200,
"body": json.dumps(response)
}
return ret