def depatisnet_published_data_search_handler(request): """Search for published-data at DEPATISnet""" #pprint(request.params) # CQL query string query = request.params.get('expression', '') log.info('query raw: ' + query) # lazy-fetch more entries up to maximum of depatisnet # TODO: get from patzilla.access.dpma.depatisnet request_size = 250 if int(request.params.get('range_begin', 0)) > request_size: request_size = 1000 # Compute query options, like # - limit # - sorting # - whether to remove family members options = {} options.update({'limit': request_size}) # propagate request parameters to search options parameters request_to_options(request, options) # transcode CQL query query_object, query = cql_prepare_query(query) log.info('query cql: ' + query) # propagate keywords to highlighting component propagate_keywords(request, query_object) try: return dpma_published_data_search(query, options) except SyntaxError as ex: request.errors.add('depatisnet-search', 'expression', str(ex.msg)) 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 Exception as ex: message = handle_generic_exception(request, ex, 'depatisnet-search', query) request.errors.add('depatisnet-search', 'search', message)
def prepare_search(request): #pprint(request.params) # CQL expression string expression = request.params.get('expression', '').strip() # Compute expression syntax syntax_cql = asbool( request.params.get('query_data[modifiers][syntax-cql]')) syntax_ikofax = asbool( request.params.get('query_data[modifiers][syntax-ikofax]')) syntax = 'cql' if syntax_ikofax or expression.startswith('ikofax:'): expression = expression.replace('ikofax:', '') syntax = 'ikofax' log.info(u'DEPATISnet query: {}, syntax: {}'.format(expression, syntax)) # Compute query options, like # - limit # - sorting # - whether to remove family members options = {} options.update({'syntax': syntax}) # propagate request parameters to search options parameters request_to_options(request, options) # Transcode query expression if syntax == 'cql': search = cql_prepare_query(expression) elif syntax == 'ikofax': search = ikofax_prepare_query(expression) else: request.errors.add('depatisnet-search', 'expression', u'Unknown syntax {}'.format(syntax)) # Propagate keywords to highlighting component keywords_to_response(request, search=search) return search, options
def depatisnet_published_data_crawl_handler(request): """Crawl published-data at DEPATISnet""" # CQL query string query = request.params.get('expression', '') log.info('query raw: ' + query) query_object, query = cql_prepare_query(query) propagate_keywords(request, query_object) chunksize = 1000 # Compute query options, like # - limit # - sorting # - whether to remove family members options = {} options.update({'limit': chunksize}) # propagate request parameters to search options parameters request_to_options(request, options) log.info('query cql: ' + query) try: result = dpma_published_data_search(query, options) return result except SyntaxError as ex: request.errors.add('depatisnet-search', 'expression', str(ex.msg)) log.warn(request.errors) except Exception as ex: http_response = None if hasattr(ex, 'http_response'): http_response = ex.http_response log.error(u'DEPATISnet crawler error: query="{0}", reason={1}\nresponse:\n{2}\nexception:\n{3}'.format( query, ex, http_response, _exception_traceback())) message = u'An exception occurred while processing your query<br/>Reason: {}'.format(ex) request.errors.add('depatisnet-search', 'crawl', message)
def sip_published_data_search_handler(request): """Search for published-data at SIP""" #request.errors.add('sip-search', 'login', "SIP data source disabled, please use alternative data source.") #return # XML query expression query = request.params.get('expression', '') log.info('Raw query: ' + query) # fixup query: wrap into quotes if cql string is a) unspecific, b) contains spaces and c) is still unquoted if should_be_quoted(query): query = '"%s"' % query #propagate_keywords(request, query_object) # lazy-fetch more entries up to maximum of SIP # TODO: get from patzilla.access.sip limit = 250 offset_local = int(request.params.get('range_begin', 1)) offset_remote = int(offset_local / limit) * limit # Compute query options, like # - limit # - sorting # - whether to remove family members # - whether to return all family members options = SmartBunch() options.update({ 'limit': limit, 'offset': offset_remote, }) # Propagate request parameters to search options parameters request_to_options(request, options) # currently not handled by search handler, it's already handled on xml expression builder level #if asbool(request.params.get('query_data[modifiers][family-full]')): # options.update({'feature_family_full': True}) try: data = sip_published_data_search(query, options) #print ' SIPsearch response:'; print data.prettify() # debugging return data except LoginException as ex: request.errors.add('sip-search', 'login', ex.sip_info) except SyntaxError as ex: request.errors.add('sip-search', 'expression', str(ex.msg)) log.warn(request.errors) except SearchException as ex: message = ex.get_message() request.errors.add('sip-search', 'search', message) log.error(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) message = re.sub(u'namespace: .*', u'', message) request.errors.add('sip-search', 'internals', message) log.error(request.errors)
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)