def fields_data(self, user, name, engine='solr'): from search.api_engines import get_engine api = get_engine(user, engine) try: schema_fields = api.fields(name) schema_fields = schema_fields['schema']['fields'] except Exception, e: LOG.warn('/luke call did not succeed: %s' % e) fields = api.schema_fields(name) schema_fields = Collection2._make_luke_from_schema_fields(fields)
def search(request): response = {} collection = json.loads(request.POST.get('collection', '{}')) query = json.loads(request.POST.get('query', '{}')) facet = json.loads(request.POST.get('facet', '{}')) query['download'] = 'download' in request.POST fetch_result = 'fetch_result' in request.POST if collection: try: if fetch_result: response = get_engine(request.user, collection).fetch_result(collection, query, facet) else: response = get_engine(request.user, collection).query(collection, query, facet) except RestException, e: try: message = json.loads(e.message) response['error'] = message['error'].get('msg', message['error']['trace']) except Exception, e2: LOG.exception('failed to extract json message: %s' % force_unicode(e2)) LOG.exception('failed to parse json response: %s' % force_unicode(e)) response['error'] = force_unicode(e)
def nested_documents(request): result = {'status': -1, 'message': 'Error'} response = {} collection = json.loads(request.POST.get('collection', '{}')) query = {'qs': [{'q': '_root_:*'}], 'fqs': [], 'start': 0, 'limit': 0} try: response = get_engine(request.user, collection).query(collection, query) result['has_nested_documents'] = response['response']['numFound'] > 0 result['status'] = 0 except Exception, e: LOG.exception('Failed to list nested documents') result['message'] = force_unicode(e)
def get_collections(request): result = {'status': -1, 'message': ''} try: collection = json.loads(request.POST.get('collection')) show_all = json.loads(request.POST.get('show_all')) result['collection'] = get_engine(request.user, collection).datasets(show_all=show_all) result['status'] = 0 except Exception, e: if 'does not have privileges' in str(e): result['status'] = 0 result['collection'] = [json.loads(request.POST.get('collection'))['name']] else: result['message'] = force_unicode(e)
def get_stats(request): result = {'status': -1, 'message': 'Error'} try: collection = json.loads(request.POST.get('collection', '{}')) query = json.loads(request.POST.get('query', '{}')) analysis = json.loads(request.POST.get('analysis', '{}')) field = analysis['name'] facet = analysis['stats']['facet'] result['stats'] = get_engine(request.user, collection).stats(collection['name'], [field], query, facet) result['status'] = 0 result['message'] = '' except Exception, e: LOG.exception('Failed to get stats for field') result['message'] = force_unicode(e) if 'not currently supported' in result['message']: result['status'] = 1 result['message'] = _('This field type does not support stats')
def get_document(request): result = {'status': -1, 'message': 'Error'} try: collection = json.loads(request.POST.get('collection', '{}')) doc_id = request.POST.get('id') if doc_id: result['doc'] = get_engine(request.user, collection).get(collection['name'], doc_id) if result['doc']['doc']: result['status'] = 0 result['message'] = '' else: result['status'] = 1 result['message'] = _('No document was returned by Solr.') else: result['message'] = _('This document does not have any index id.') result['status'] = 1 except Exception, e: result['message'] = force_unicode(e)
def index_fields_dynamic(request): result = {'status': -1, 'message': 'Error'} try: name = request.POST['name'] engine = request.POST['engine'] dynamic_fields = get_engine(request.user, engine).luke(name) result['message'] = '' result['fields'] = [ Collection2._make_field(name, properties) for name, properties in dynamic_fields['fields'].iteritems() if 'dynamicBase' in properties ] result['gridlayout_header_fields'] = [ Collection2._make_gridlayout_header_field({'name': name, 'type': properties.get('type')}, True) for name, properties in dynamic_fields['fields'].iteritems() if 'dynamicBase' in properties ] result['status'] = 0 except Exception, e: result['message'] = force_unicode(e)
def new_search(request, is_embeddable=False): engine = request.GET.get('engine', 'solr') collections = get_engine(request.user, engine).datasets() if not collections: return no_collections(request) collection = Collection2(user=request.user, name=collections[0], engine=engine) query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0} template = 'search.mako' if is_embeddable: template = 'search_embeddable.mako' return render( template, request, { 'collection': collection, 'query': query, 'initial': json.dumps({ 'collections': collections, 'layout': [ { "size": 2, "rows": [{ "widgets": [] }], "drops": ["temp"], "klass": "card card-home card-column span2" }, { "size": 10, "rows": [{ "widgets": [{ "size": 12, "name": "Filter Bar", "widgetType": "filter-widget", "id": "99923aef-b233-9420-96c6-15d48293532b", "properties": {}, "offset": 0, "isLoading": True, "klass": "card card-widget span12" }] }, { "widgets": [{ "size": 12, "name": "Grid Results", "widgetType": "resultset-widget", "id": "14023aef-b233-9420-96c6-15d48293532b", "properties": {}, "offset": 0, "isLoading": True, "klass": "card card-widget span12" }] }], "drops": ["temp"], "klass": "card card-home card-column span10" }, ], 'is_latest': LATEST.get(), 'engines': get_engines(request.user) }), 'is_owner': True, 'can_edit_index': can_edit_index(request.user) })
def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_type): properties = { 'sort': 'desc', 'canRange': False, 'stacked': False, 'limit': 10, 'mincount': 0, 'isDate': False, 'aggregate': {'function': 'unique', 'ops': [], 'percentiles': [{'value': 50}]} } if widget_type in ('tree-widget', 'heatmap-widget', 'map-widget'): facet_type = 'pivot' elif widget_type == 'gradient-map-widget': facet_type = 'nested' properties['facets'] = [] properties['domain'] = {'blockParent': [], 'blockChildren': []} properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 10, 'aggregate': {'function': 'unique', 'ops': [], 'percentiles': [{'value': 50}]}} properties['scope'] = 'world' properties['limit'] = 100 else: api = get_engine(user, collection) range_properties = _new_range_facet(api, collection, facet_field, widget_type) if range_properties: facet_type = 'range' properties.update(range_properties) properties['initial_gap'] = properties['gap'] properties['initial_start'] = properties['start'] properties['initial_end'] = properties['end'] else: facet_type = 'field' if widget_type in ('bucket-widget', 'pie2-widget', 'timeline-widget', 'tree2-widget', 'text-facet-widget', 'hit-widget'): if widget_type == 'text-facet-widget': properties['type'] = facet_type if widget_type == 'hit-widget': facet_type = 'function' else: facet_type = 'nested' properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 10, 'aggregate': {'function': 'unique', 'ops': [], 'percentiles': [{'value': 50}]}} properties['facets'] = [] properties['domain'] = {'blockParent': [], 'blockChildren': []} if widget_type == 'pie2-widget': properties['scope'] = 'stack' properties['timelineChartType'] = 'bar' elif widget_type == 'tree2-widget': properties['scope'] = 'tree' properties['facets_form']['limit'] = 5 properties['isOldPivot'] = True else: properties['scope'] = 'stack' properties['timelineChartType'] = 'bar' if widget_type in ('tree-widget', 'heatmap-widget', 'map-widget'): properties['mincount'] = 1 properties['facets'] = [] properties['stacked'] = True properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 5} if widget_type == 'map-widget': properties['scope'] = 'world' properties['limit'] = 100 else: properties['scope'] = 'stack' if widget_type == 'heatmap-widget' else 'tree' if widget_type == 'histogram-widget': properties['enableSelection'] = True properties['timelineChartType'] = 'bar' properties['extraSeries'] = [] return { 'id': facet_id, 'label': facet_label, 'field': facet_field, 'type': facet_type, 'widgetType': widget_type, 'properties': properties, # Hue 4+ 'template': { "showFieldList": True, "showGrid": False, "showChart": True, "chartSettings" : { 'chartType': 'pie' if widget_type == 'pie2-widget' else ('timeline' if widget_type == 'timeline-widget' else ('gradientmap' if widget_type == 'gradient-map-widget' else 'bars')), 'chartSorting': 'none', 'chartScatterGroup': None, 'chartScatterSize': None, 'chartScope': 'world', 'chartX': None, 'chartYSingle': None, 'chartYMulti': [], 'chartData': [], 'chartMapLabel': None, }, "fieldsAttributes": [], "fieldsAttributesFilter": "", "filteredAttributeFieldsAll": True, "fields": [], "fieldsSelected": [], "leafletmap": {'latitudeField': None, 'longitudeField': None, 'labelField': None}, # Use own? 'leafletmapOn': False, 'isGridLayout': False, "hasDataForChart": True, "rows": 25, }, 'queryResult': {} }