Пример #1
0
def index(request):
    hue_collections = Collection.objects.all()

    if not hue_collections:
        if request.user.is_superuser:
            return admin_collections(request, True)
        else:
            return no_collections(request)

    search_form = QueryForm(request.GET)
    response = {}
    error = {}
    solr_query = {}
    hue_collection = None

    if search_form.is_valid():
        collection_id = search_form.cleaned_data['collection']
        if request.GET.get('collection') is None:
            collection_id = request.COOKIES.get('hueSearchLastCollection',
                                                collection_id)
        solr_query['q'] = search_form.cleaned_data['query']
        solr_query['fq'] = search_form.cleaned_data['fq']
        if search_form.cleaned_data['sort']:
            solr_query['sort'] = search_form.cleaned_data['sort']
        solr_query['rows'] = search_form.cleaned_data['rows'] or 15
        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")
Пример #2
0
def index(request):
  hue_collections = Collection.objects.filter(enabled=True)

  if not hue_collections:
    if request.user.is_superuser:
      return admin_collections(request, True)
    else:
      return no_collections(request)

  initial_collection = request.COOKIES.get('hueSearchLastCollection', 0)
  search_form = QueryForm(request.GET, initial_collection=initial_collection)
  response = {}
  error = {}
  solr_query = {}
  hue_collection = None

  if search_form.is_valid():
    collection_id = search_form.cleaned_data['collection']
    solr_query['q'] = search_form.cleaned_data['query'].encode('utf8')
    solr_query['fq'] = search_form.cleaned_data['fq']
    if search_form.cleaned_data['sort']:
      solr_query['sort'] = search_form.cleaned_data['sort']
    solr_query['rows'] = search_form.cleaned_data['rows'] or 15
    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(), request.user).query(solr_query, hue_collection)
    except Exception, e:
      error['message'] = unicode(str(e), "utf8")
Пример #3
0
def index(request):
  hue_collections = Collection.objects.filter(enabled=True)

  if not hue_collections:
    if request.user.is_superuser:
      return admin_collections(request, True)
    else:
      return no_collections(request)

  init_collection = initial_collection(request, hue_collections)

  search_form = QueryForm(request.GET, initial_collection=init_collection)
  response = {}
  error = {}
  solr_query = {}

  if search_form.is_valid():
    try:
      collection_id = search_form.cleaned_data['collection']
      hue_collection = Collection.objects.get(id=collection_id)

      solr_query = search_form.solr_query_dict
      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))
Пример #4
0
def index(request):
  hue_collections = SearchController(request.user).get_search_collections()

  if not hue_collections:
    if request.user.is_superuser:
      return admin_collections(request, True)
    else:
      return no_collections(request)

  init_collection = initial_collection(request, hue_collections)

  search_form = QueryForm(request.GET, initial_collection=init_collection)
  response = {}
  error = {}
  solr_query = {}

  if search_form.is_valid():
    try:
      collection_id = search_form.cleaned_data['collection']
      hue_collection = Collection.objects.get(id=collection_id)

      solr_query = search_form.solr_query_dict
      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))
Пример #5
0
def download(request, format):
  hue_collections = Collection.objects.filter(enabled=True)

  if not hue_collections:
    raise PopupException(_("No collection to download."))

  init_collection = initial_collection(request, hue_collections)

  search_form = QueryForm(request.GET, initial_collection=init_collection)

  if search_form.is_valid():
    try:
      collection_id = search_form.cleaned_data['collection']
      hue_collection = Collection.objects.get(id=collection_id)

      solr_query = search_form.solr_query_dict
      response = SolrApi(SOLR_URL.get(), request.user).query(solr_query, hue_collection)

      LOG.debug('Download results for query %s' % smart_str(solr_query))

      return export_download(response, format)
    except Exception, e:
      raise PopupException(_("Could not download search results: %s") % e)
Пример #6
0
def download(request, format):
  hue_collections = SearchController(request.user).get_search_collections()

  if not hue_collections:
    raise PopupException(_("No collection to download."))

  init_collection = initial_collection(request, hue_collections)

  search_form = QueryForm(request.GET, initial_collection=init_collection)

  if search_form.is_valid():
    try:
      collection_id = search_form.cleaned_data['collection']
      hue_collection = Collection.objects.get(id=collection_id)

      solr_query = search_form.solr_query_dict
      response = SolrApi(SOLR_URL.get(), request.user).query(solr_query, hue_collection)

      LOG.debug('Download results for query %s' % smart_str(solr_query))

      return export_download(response, format)
    except Exception, e:
      raise PopupException(_("Could not download search results: %s") % e)
Пример #7
0
def index(request):
  hue_collections = Collection.objects.filter(enabled=True)

  if not hue_collections:
    if request.user.is_superuser:
      return admin_collections(request, True)
    else:
      return no_collections(request)

  initial_collection = request.COOKIES.get('hueSearchLastCollection', hue_collections[0].id)
  try:
    Collection.objects.get(id=initial_collection)
  except Exception, e:
    initial_collection = hue_collections[0].id

  search_form = QueryForm(request.GET, initial_collection=initial_collection)
  response = {}
  error = {}
  solr_query = {}
  hue_collection = None

  if search_form.is_valid():
    collection_id = search_form.cleaned_data['collection']
    solr_query['q'] = search_form.cleaned_data['query'].encode('utf8')
    solr_query['fq'] = search_form.cleaned_data['fq']
    if search_form.cleaned_data['sort']:
      solr_query['sort'] = search_form.cleaned_data['sort']
    solr_query['rows'] = search_form.cleaned_data['rows'] or 15
    solr_query['start'] = search_form.cleaned_data['start'] or 0
    solr_query['facets'] = search_form.cleaned_data['facets'] or 1
    solr_query['current_page'] = int(math.ceil((float(solr_query['start']) + 1) / float(solr_query['rows'])))
Пример #8
0
    hue_collections = Collection.objects.filter(enabled=True)

    if not hue_collections:
        if request.user.is_superuser:
            return admin_collections(request, True)
        else:
            return no_collections(request)

    initial_collection = request.COOKIES.get('hueSearchLastCollection',
                                             hue_collections[0].id)
    try:
        Collection.objects.get(id=initial_collection)
    except Exception, e:
        initial_collection = hue_collections[0].id

    search_form = QueryForm(request.GET, initial_collection=initial_collection)
    response = {}
    error = {}
    solr_query = {}
    hue_collection = None

    if search_form.is_valid():
        collection_id = search_form.cleaned_data['collection']
        solr_query['q'] = search_form.cleaned_data['query'].encode('utf8')
        solr_query['fq'] = search_form.cleaned_data['fq']
        if search_form.cleaned_data['sort']:
            solr_query['sort'] = search_form.cleaned_data['sort']
        solr_query['rows'] = search_form.cleaned_data['rows'] or 15
        solr_query['start'] = search_form.cleaned_data['start'] or 0
        solr_query['facets'] = search_form.cleaned_data['facets'] or 1