Пример #1
0
def search(request):
    response = {}

    collection = json.loads(request.POST.get('collection', '{}'))
    query = json.loads(request.POST.get('query', '{}'))
    query['download'] = 'download' in request.POST
    # todo: remove the selected histo facet if multiq

    if collection['id']:
        hue_collection = Collection.objects.get(
            id=collection['id'])  # TODO perms

    if collection:
        try:
            response = SolrApi(SOLR_URL.get(),
                               request.user).query(collection, query)
            response = augment_solr_response(response, collection, query)
        except RestException, e:
            try:
                response['error'] = json.loads(e.message)['error']['msg']
            except:
                response['error'] = force_unicode(str(e))
        except Exception, e:
            raise PopupException(e, title=_('Error while accessing Solr'))

            response['error'] = force_unicode(str(e))
Пример #2
0
def get_timeline(request):
    result = {'status': -1, 'message': 'Error'}

    try:
        collection = json.loads(request.POST.get('collection', '{}'))
        query = json.loads(request.POST.get('query', '{}'))
        facet = json.loads(request.POST.get('facet', '{}'))
        qdata = json.loads(request.POST.get('qdata', '{}'))
        multiQ = request.POST.get('multiQ', 'query')

        if multiQ == 'query':
            label = qdata['q']
            query['qs'] = [qdata]
        elif facet['type'] == 'range':
            _prop = filter(lambda prop: prop['from'] == qdata,
                           facet['properties'])[0]
            label = '%(from)s - %(to)s ' % _prop
            facet_id = facet['id']
            # Only care about our current field:value filter
            for fq in query['fqs']:
                if fq['id'] == facet_id:
                    fq['properties'] = [_prop]
        else:
            label = qdata
            facet_id = facet['id']
            # Only care about our current field:value filter
            for fq in query['fqs']:
                if fq['id'] == facet_id:
                    fq['filter'] = [{'value': qdata, 'exclude': False}]

        # Remove other facets from collection for speed
        collection['facets'] = filter(
            lambda f: f['widgetType'] == 'histogram-widget',
            collection['facets'])

        response = SolrApi(SOLR_URL.get(),
                           request.user).query(collection, query)
        response = augment_solr_response(response, collection, query)

        label += ' (%s) ' % response['response']['numFound']

        result['series'] = {
            'label': label,
            'counts': response['normalized_facets'][0]['counts']
        }
        result['status'] = 0
        result['message'] = ''
    except Exception, e:
        result['message'] = unicode(str(e), "utf8")
Пример #3
0
def search(request):
    response = {}

    collection = json.loads(request.POST.get("collection", "{}"))
    query = json.loads(request.POST.get("query", "{}"))
    query["download"] = "download" in request.POST

    if collection:
        try:
            response = SolrApi(SOLR_URL.get(), request.user).query(collection, query)
            response = augment_solr_response(response, collection, query)
        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)
Пример #4
0
def search(request):
  response = {}

  collection = json.loads(request.POST.get('collection', '{}'))
  query = json.loads(request.POST.get('query', '{}'))
  query['download'] = 'download' in request.POST

  if collection:
    try:
      response = SolrApi(SOLR_URL.get(), request.user).query(collection, query)
      response = augment_solr_response(response, collection, query)
    except RestException, e:
      try:
        message = json.loads(e.message)['error']
        response['error'] = message.get('msg', message['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)
Пример #5
0
def get_timeline(request):
  result = {'status': -1, 'message': 'Error'}

  try:
    collection = json.loads(request.POST.get('collection', '{}'))
    query = json.loads(request.POST.get('query', '{}'))
    facet = json.loads(request.POST.get('facet', '{}'))
    qdata = json.loads(request.POST.get('qdata', '{}'))
    multiQ = request.POST.get('multiQ', 'query')

    if multiQ == 'query':
      label = qdata['q']
      query['qs'] = [qdata]
    elif facet['type'] == 'range':
      _prop = filter(lambda prop: prop['from'] == qdata, facet['properties'])[0]
      label = '%(from)s - %(to)s ' % _prop
      facet_id = facet['id']
      # Only care about our current field:value filter
      for fq in query['fqs']:
        if fq['id'] == facet_id:
          fq['properties'] = [_prop]
    else:
      label = qdata
      facet_id = facet['id']
      # Only care about our current field:value filter
      for fq in query['fqs']:
        if fq['id'] == facet_id:
          fq['filter'] = [qdata]

    # Remove other facets from collection for speed
    collection['facets'] = filter(lambda f: f['widgetType'] == 'histogram-widget', collection['facets'])

    response = SolrApi(SOLR_URL.get(), request.user).query(collection, query)
    response = augment_solr_response(response, collection, query)

    label += ' (%s) ' % response['response']['numFound']

    result['series'] = {'label': label, 'counts': response['normalized_facets'][0]['counts']}
    result['status'] = 0
    result['message'] = ''
  except Exception, e:
    result['message'] = unicode(str(e), "utf8")
Пример #6
0
def get_timeline(request):
    result = {"status": -1, "message": "Error"}

    try:
        collection = json.loads(request.POST.get("collection", "{}"))
        query = json.loads(request.POST.get("query", "{}"))
        facet = json.loads(request.POST.get("facet", "{}"))
        qdata = json.loads(request.POST.get("qdata", "{}"))
        multiQ = request.POST.get("multiQ", "query")

        if multiQ == "query":
            label = qdata["q"]
            query["qs"] = [qdata]
        elif facet["type"] == "range":
            _prop = filter(lambda prop: prop["from"] == qdata, facet["properties"])[0]
            label = "%(from)s - %(to)s " % _prop
            facet_id = facet["id"]
            # Only care about our current field:value filter
            for fq in query["fqs"]:
                if fq["id"] == facet_id:
                    fq["properties"] = [_prop]
        else:
            label = qdata
            facet_id = facet["id"]
            # Only care about our current field:value filter
            for fq in query["fqs"]:
                if fq["id"] == facet_id:
                    fq["filter"] = [{"value": qdata, "exclude": False}]

        # Remove other facets from collection for speed
        collection["facets"] = filter(lambda f: f["widgetType"] == "histogram-widget", collection["facets"])

        response = SolrApi(SOLR_URL.get(), request.user).query(collection, query)
        response = augment_solr_response(response, collection, query)

        label += " (%s) " % response["response"]["numFound"]

        result["series"] = {"label": label, "counts": response["normalized_facets"][0]["counts"]}
        result["status"] = 0
        result["message"] = ""
    except Exception, e:
        result["message"] = force_unicode(e)
Пример #7
0
def search(request):
  response = {}

  collection = json.loads(request.POST.get('collection', '{}'))
  query = json.loads(request.POST.get('query', '{}'))
  query['download'] = 'download' in request.POST

  if collection:
    try:
      response = SolrApi(SOLR_URL.get(), request.user).query(collection, query)
      response = augment_solr_response(response, collection, query)
    except RestException, e:
      try:
        response['error'] = json.loads(e.message)['error']['msg']
      except:
        response['error'] = force_unicode(str(e))
    except Exception, e:
      raise PopupException(e, title=_('Error while accessing Solr'))

      response['error'] = force_unicode(str(e))
Пример #8
0
def search(request):
  response = {}

  collection = json.loads(request.POST.get('collection', '{}'))
  query = json.loads(request.POST.get('query', '{}'))
  query['download'] = 'download' in request.POST

  if collection:
    try:
      response = SolrApi(SOLR_URL.get(), request.user).query(collection, query)
      response = augment_solr_response(response, collection, query)
    except RestException, e:
      try:
        response['error'] = json.loads(e.message)['error']['msg']
      except:
        response['error'] = force_unicode(str(e))
    except Exception, e:
      raise PopupException(e, title=_('Error while accessing Solr'))

      response['error'] = force_unicode(str(e))
Пример #9
0
def search(request):
  response = {}

  collection = json.loads(request.POST.get('collection', '{}'))
  query = json.loads(request.POST.get('query', '{}'))
  # todo: remove the selected histo facet if multiq

  if collection['id']:
    hue_collection = Collection.objects.get(id=collection['id']) # TODO perms

  if collection:
    try:
      response = SolrApi(SOLR_URL.get(), request.user).query(collection, query)
      response = augment_solr_response(response, collection, query)
    except RestException, e:
      try:
        response['error'] = json.loads(e.message)['error']['msg']
      except:
        response['error'] = force_unicode(str(e))
    except Exception, e:
      raise PopupException(e, title=_('Error while accessing Solr'))

      response['error'] = force_unicode(str(e))
Пример #10
0
def search(request):
    response = {}

    collection = json.loads(request.POST.get("collection", "{}"))
    query = json.loads(request.POST.get("query", "{}"))
    query["download"] = "download" in request.POST
    # todo: remove the selected histo facet if multiq

    if collection["id"]:
        hue_collection = Collection.objects.get(id=collection["id"])  # TODO perms

    if collection:
        try:
            response = SolrApi(SOLR_URL.get(), request.user).query(collection, query)
            response = augment_solr_response(response, collection, query)
        except RestException, e:
            try:
                response["error"] = json.loads(e.message)["error"]["msg"]
            except:
                response["error"] = force_unicode(str(e))
        except Exception, e:
            raise PopupException(e, title=_("Error while accessing Solr"))

            response["error"] = force_unicode(str(e))
Пример #11
0
        solr_query['start'] = search_form.cleaned_data['start'] or 0
        solr_query['facets'] = search_form.cleaned_data['facets'] or 1

        try:
            hue_collection = Collection.objects.get(id=collection_id)
            solr_query['collection'] = hue_collection.name
            response = SolrApi(SOLR_URL.get()).query(solr_query,
                                                     hue_collection)
        except Exception, e:
            error['message'] = unicode(str(e), "utf8")
    else:
        hue_collection = hue_collections[0]
        collection_id = hue_collection.id

    if hue_collection is not None:
        response = augment_solr_response(response,
                                         hue_collection.facets.get_data())
        print response

    if request.GET.get('format') == 'json':
        return HttpResponse(json.dumps(response), mimetype="application/json")

    return render(
        'search.mako', request, {
            'search_form': search_form,
            'response': response,
            'error': error,
            'solr_query': solr_query,
            'hue_collection': hue_collection,
            'hue_collections': hue_collections,
            'current_collection': collection_id,
            'json': json,
Пример #12
0
    solr_query['search_time'] = 0

    try:
      hue_collection = Collection.objects.get(id=collection_id)
      solr_query['collection'] = hue_collection.name
      response = SolrApi(SOLR_URL.get(), request.user).query(solr_query, hue_collection)
      solr_query['total_pages'] = int(math.ceil((float(response['response']['numFound']) / float(solr_query['rows']))))
      solr_query['search_time'] = response['responseHeader']['QTime']
    except Exception, e:
      error['title'] = force_unicode(e.title) if hasattr(e, 'title') else ''
      error['message'] = force_unicode(str(e))
  else:
    error['message'] = _('There is no collection to search.')

  if hue_collection is not None:
    response = augment_solr_response(response, hue_collection.facets.get_data())

  if request.GET.get('format') == 'json':
    return HttpResponse(json.dumps(response), mimetype="application/json")

  return render('search.mako', request, {
    'search_form': search_form,
    'response': response,
    'error': error,
    'solr_query': solr_query,
    'hue_collection': hue_collection,
    'hue_collections': hue_collections,
    'current_collection': collection_id,
    'json': json,
  })
Пример #13
0
 def query(self, collection, query, facet=None):
   response = self.api.query(collection, query)
   return augment_solr_response(response, collection, query)