def depatech_published_data_crawl_handler(request): """Crawl published-data at MTC depa.tech""" # Get hold of query expression and filter query = SmartBunch({ 'expression': request.params.get('expression', ''), 'filter': request.params.get('filter', ''), }) log.info('query: {}'.format(query)) if should_be_quoted(query.expression): query.expression = '"%s"' % query.expression # constituents: abstract, biblio and/or full-cycle constituents = request.matchdict.get('constituents', 'full-cycle') #print 'constituents:', constituents chunksize = int(request.params.get('chunksize', '5000')) try: result = depatech_crawl(constituents, query, chunksize) return result except Exception as ex: request.errors.add('depatech-crawl', 'crawl', str(ex)) log.error(request.errors) log.error('query="{0}", exception:\n{1}'.format(query, _exception_traceback()))
def depatech_published_data_search_handler(request): """Search for published-data at MTC depa.tech""" # Get hold of query expression and filter expression = request.params.get('expression', '') filter = request.params.get('filter', '') query = SmartBunch({ 'syntax': 'lucene', 'expression': expression, 'filter': filter, }) if expression.startswith('DEPAROM V1.0') or expression.startswith('deparom:'): query.syntax = 'deparom' log.info('Query: {}'.format(query)) # Parse expression, extract and propagate keywords to user interface if query.syntax == 'lucene': parser = DepaTechParser(query.expression) keywords_to_response(request, parser) # TODO: Parse DEPAROM query expression and extract keywords # Fixup query: wrap into quotes if cql string is a) unspecific, b) contains spaces and c) is still unquoted if should_be_quoted(query.expression): query.expression = '"%s"' % query.expression # Lazy-fetch more entries # TODO: get from patzilla.access.depatech limit = 250 offset_local = int(request.params.get('range_begin', 0)) offset_remote = int(offset_local / limit) * limit # Compute query options, like # - limit # - sorting # - whether to remove family members options = SmartBunch() options.update({ 'limit': limit, 'offset': offset_remote, }) # Propagate request parameters to search options parameters request_to_options(request, options) try: data = depatech_search(query, options) #print data.prettify() # debugging return data except LoginException as ex: request.errors.add('depatech-search', 'login', ex.details) log.warn(request.errors) except SyntaxError as ex: request.errors.add('depatech-search', 'expression', str(ex.msg)) log.warn(request.errors) except SearchException as ex: message = ex.get_message() request.errors.add('depatech-search', 'search', message) log.warn(request.errors) except NoResultsException as ex: # Forward response to let the frontend recognize zero hits request.response.status = HTTPNotFound.code return ex.data except OperationFailure as ex: message = str(ex) request.errors.add('depatech-search', 'internals', message) log.error(request.errors) except Exception as ex: message = handle_generic_exception(request, ex, 'depatech-search', query) request.errors.add('depatech-search', 'search', message)
def ificlaims_published_data_search_handler(request): """Search for published-data at IFI CLAIMS Direct""" # Get hold of query expression and filter query = SmartBunch({ 'expression': request.params.get('expression', ''), 'filter': request.params.get('filter', ''), }) log.info('Query: {}'.format(query)) # Parse expression, extract and propagate keywords to user interface parser = IFIClaimsParser(query.expression) propagate_keywords(request, parser) # Fixup query: wrap into quotes if cql string is a) unspecific, b) contains spaces and c) is still unquoted if should_be_quoted(query.expression): query.expression = '"%s"' % query.expression # Lazy-fetch more entries # TODO: get from patzilla.access.ificlaims limit = 250 offset_local = int(request.params.get('range_begin', 0)) offset_remote = int(offset_local / limit) * limit # Compute query options, like # - limit # - sorting # - whether to remove family members options = SmartBunch() options.update({ 'limit': limit, 'offset': offset_remote, }) # Propagate request parameters to search options parameters request_to_options(request, options) try: data = ificlaims_search(query, options) #print data.prettify() # debugging return data except LoginException as ex: request.errors.add('ificlaims-search', 'login', ex.details) log.warn(request.errors) except SyntaxError as ex: request.errors.add('ificlaims-search', 'expression', unicode(ex.msg)) log.warn(request.errors) except SearchException as ex: message = ex.get_message() request.errors.add('ificlaims-search', 'search', message) log.warn(request.errors) except NoResultsException as ex: # Forward response to let the frontend recognize zero hits request.response.status = HTTPNotFound.code return ex.data except OperationFailure as ex: message = unicode(ex) request.errors.add('ificlaims-search', 'internals', message) log.error(request.errors) except Exception as ex: message = handle_generic_exception(request, ex, 'ificlaims-search', query) request.errors.add('ificlaims-search', 'search', message)