def search_entities(request): """ For displaying results. """ interface = request.POST.get('interface', CATALOG.INTERFACE.get()) query_s = json.loads(request.POST.get('query_s', '')) query_s = smart_str(query_s) offset = request.POST.get('offset', 0) limit = int(request.POST.get('limit', 100)) raw_query = request.POST.get('raw_query', False) sources = json.loads(request.POST.get('sources') or '[]') if sources and not has_catalog_file_search(request.user): sources = ['sql'] query_s = query_s.strip() or '*' api = get_api(request=request, interface=interface) entities = api.search_entities(query_s, limit=limit, offset=offset, raw_query=raw_query, sources=sources) if not raw_query: _augment_highlighting(query_s, entities) response = { 'entities': entities, 'count': len(entities), 'offset': offset, 'limit': limit, 'query_s': query_s, 'status': 0 } return JsonResponse(response)
def search_entities_interactive(request): """ For search autocomplete. """ interface = request.POST.get('interface', CATALOG.INTERFACE.get()) query_s = json.loads(request.POST.get('query_s', '')) prefix = request.POST.get('prefix') offset = request.POST.get('offset', 0) limit = int(request.POST.get('limit', 25)) field_facets = json.loads(request.POST.get('field_facets') or '[]') sources = json.loads(request.POST.get('sources') or '[]') api = get_api(request=request, interface=interface) if sources and not has_catalog_file_search(request.user): sources = ['sql'] response = api.search_entities_interactive(query_s=query_s, limit=limit, offset=offset, facetFields=field_facets, facetPrefix=prefix, facetRanges=None, firstClassEntitiesOnly=None, sources=sources) if response.get('facets'): # Remove empty facets for fname, fvalues in list(response['facets'].items()): # Should be a CATALOG option at some point for hidding table with no access / asking for access. if interface == 'navigator' and NAVIGATOR.APPLY_SENTRY_PERMISSIONS.get( ): fvalues = [] else: fvalues = sorted([(k, v) for k, v in list(fvalues.items()) if v > 0], key=lambda n: n[1], reverse=True) response['facets'][fname] = OrderedDict(fvalues) if ':' in query_s and not response['facets'][fname]: del response['facets'][fname] _augment_highlighting(query_s, response.get('results')) response['status'] = 0 return JsonResponse(response)