Source code for biothings.web.api.es.handlers.query_handler



from biothings.web.api.es.handlers.base_handler import ESRequestHandler
from biothings.web.api.handler import BadRequest


[docs]class QueryHandler(ESRequestHandler): ''' Request handlers for requests to the query endpoint ''' name = 'query'
[docs] def prepare(self): """ Perform a quick check to ensure required arguments are present. """ if self.request.method == 'GET': args = self.request.arguments if 'q' not in args and 'scroll_id' not in args: raise BadRequest( missing={'or': ['q', 'scroll_id']} ) super().prepare()
[docs] def pre_query_builder_hook(self, options): ''' Set GA tracking object. ''' if self.request.method == 'GET': self.ga_event_object({'total': 0}) elif self.request.method == 'POST': self.ga_event_object({'qsize': len(options.esqb.q)}) return options
[docs] def pre_finish_hook(self, options, res): ''' TODO ''' if self.request.method == 'GET': if options.esqb.fetch_all: self.ga_event_object_ret['action'] = 'fetch_all' self.ga_event_object({'total': res.get('total', 0)}) # TODO DSL rewrite return res