Skip to content
Snippets Groups Projects
Commit a73b8430 authored by jan.bednarik's avatar jan.bednarik
Browse files

Sanitize query input.

parent 531715f5
No related branches found
No related tags found
No related merge requests found
import re
from elasticsearch import NotFoundError from elasticsearch import NotFoundError
import graphene import graphene
from graphene import relay from graphene import relay
...@@ -64,6 +65,7 @@ class Query(graphene.ObjectType): ...@@ -64,6 +65,7 @@ class Query(graphene.ObjectType):
def resolve_reports(self, info, query=''): def resolve_reports(self, info, query=''):
s = ReportDoc.search(using=info.context['es']) s = ReportDoc.search(using=info.context['es'])
if query != '': if query != '':
query = ' '.join(re.findall(r'(\b\w+)', query))
s = s.query('multi_match', query=query, fields=['title', 'body', 'received_benefit', 'provided_benefit']) s = s.query('multi_match', query=query, fields=['title', 'body', 'received_benefit', 'provided_benefit'])
s = s.sort('-published') s = s.sort('-published')
s = s[:20] s = s[:20]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment