示例#1
0
def admin_collection_template(request, collection_id):
  hue_collection = Collection.objects.get(id=collection_id)
  solr_collection = SolrApi(SOLR_URL.get(), request.user).collection_or_core(hue_collection)
  sample_data = {}

  if request.method == 'POST':
    hue_collection.result.update_from_post(request.POST)
    hue_collection.result.save()
    return HttpResponse(json.dumps({}), mimetype="application/json")

  solr_query = {}
  solr_query['collection'] = hue_collection.name
  solr_query['q'] = ''
  solr_query['fq'] = ''
  solr_query['rows'] = 5
  solr_query['start'] = 0
  solr_query['facets'] = 0

  try:
    response = SolrApi(SOLR_URL.get(), request.user).query(solr_query, hue_collection)
    sample_data = json.dumps(response["response"]["docs"])
  except PopupException, e:
    message = e
    try:
      message = json.loads(e.message.message)['error']['msg'] # Try to get the core error
    except:
      pass
    request.error(_('No preview available, some facets are invalid: %s') % message)
    LOG.exception(e)
示例#2
0
def admin_collection_template(request, collection_id):
    hue_collection = Collection.objects.get(id=collection_id)
    solr_collection = SolrApi(
        SOLR_URL.get()).collection_or_core(hue_collection)

    if request.method == 'POST':
        hue_collection.result.update_from_post(request.POST)
        hue_collection.result.save()
        return HttpResponse(json.dumps({}), mimetype="application/json")

    solr_query = {}
    solr_query['collection'] = hue_collection.name
    solr_query['q'] = ''
    solr_query['fq'] = ''
    solr_query['rows'] = 5
    solr_query['start'] = 0
    solr_query['facets'] = 0

    response = SolrApi(SOLR_URL.get()).query(solr_query, hue_collection)

    return render(
        'admin_collection_template.mako', request, {
            'solr_collection': solr_collection,
            'hue_collection': hue_collection,
            'sample_data': json.dumps(response["response"]["docs"]),
        })
示例#3
0
文件: models.py 项目: jessica9421/hue
    def fields_data(self, user):
        schema_fields = SolrApi(SOLR_URL.get(), user).fields(self.name)
        schema_fields = schema_fields['schema']['fields']

        dynamic_fields = SolrApi(SOLR_URL.get(), user).fields(self.name,
                                                              dynamic=True)
        dynamic_fields = dynamic_fields['fields']

        schema_fields.update(dynamic_fields)

        return sorted([{
            'name': str(field),
            'type': str(attributes.get('type', ''))
        } for field, attributes in schema_fields.iteritems()])
示例#4
0
def admin_collection_properties(request, collection_id):
    hue_collection = Collection.objects.get(id=collection_id)
    solr_collection = SolrApi(SOLR_URL.get(),
                              request.user).collection_or_core(hue_collection)

    if request.method == 'POST':
        collection_form = CollectionForm(request.POST, instance=hue_collection)
        if collection_form.is_valid():
            searcher = SearchController(request.user)
            hue_collection = collection_form.save(commit=False)
            hue_collection.is_core_only = not searcher.is_collection(
                hue_collection.name)
            hue_collection.save()
            return redirect(
                reverse('search:admin_collection_properties',
                        kwargs={'collection_id': hue_collection.id}))
        else:
            request.error(
                _('Errors on the form: %s.') % collection_form.errors)
    else:
        collection_form = CollectionForm(instance=hue_collection)

    return render(
        'admin_collection_properties.mako', request, {
            'solr_collection': solr_collection,
            'hue_collection': hue_collection,
            'collection_form': collection_form,
        })
示例#5
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))
示例#6
0
def admin_collection_schema(request, collection_id):
    hue_collection = Collection.objects.get(id=collection_id)
    solr_schema = SolrApi(SOLR_URL.get(),
                          request.user).schema(hue_collection.name)

    content = {'solr_schema': solr_schema.decode('utf-8')}
    return HttpResponse(json.dumps(content), mimetype="application/json")
示例#7
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")
示例#8
0
 def get_new_collections(self):
     try:
         solr_collections = SolrApi(SOLR_URL.get()).collections()
         for name in Collection.objects.values_list('name', flat=True):
             solr_collections.pop(name, None)
     except Exception, e:
         LOG.warn('No Zookeeper servlet running on Solr server: %s' % e)
         solr_collections = []
示例#9
0
 def get_new_cores(self):
     try:
         solr_cores = SolrApi(SOLR_URL.get()).cores()
         for name in Collection.objects.values_list('name', flat=True):
             solr_cores.pop(name, None)
     except Exception, e:
         solr_cores = []
         LOG.warn('No Single core setup on Solr server: %s' % e)
示例#10
0
文件: models.py 项目: MarvinWang/hue
    def fields_data(self):
        solr_schema = SolrApi(SOLR_URL.get()).schema(self.name)
        schema = etree.fromstring(solr_schema)

        return sorted([{
            'name': field.get('name'),
            'type': field.get('type')
        } for fields in schema.iter('fields')
                       for field in fields.iter('field')])
示例#11
0
def admin_collection_solr_properties(request, collection_id):
  hue_collection = Collection.objects.get(id=collection_id)
  solr_collection = SolrApi(SOLR_URL.get(), request.user).collection_or_core(hue_collection)

  content = render('admin_collection_properties_solr_properties.mako', request, {
    'solr_collection': solr_collection,
    'hue_collection': hue_collection,
  }, force_template=True).content

  return HttpResponse(json.dumps({'content': content}), mimetype="application/json")
示例#12
0
def admin_collection_highlighting(request, collection_id):
  hue_collection = Collection.objects.get(id=collection_id)
  solr_collection = SolrApi(SOLR_URL.get(), request.user).collection_or_core(hue_collection)

  if request.method == 'POST':
    hue_collection.result.update_from_post(request.POST)
    hue_collection.result.save()
    return HttpResponse(json.dumps({}), mimetype="application/json")

  return render('admin_collection_highlighting.mako', request, {
    'solr_collection': solr_collection,
    'hue_collection': hue_collection,
  })
示例#13
0
def query_suggest(request, collection_id, query=""):
    hue_collection = Collection.objects.get(id=collection_id)
    result = {'status': -1, 'message': 'Error'}

    solr_query = {}
    solr_query['collection'] = collection
    solr_query['q'] = query

    try:
        response = SolrApi(SOLR_URL.get()).suggest(solr_query, hue_collection)
        result['message'] = response
        result['status'] = 0
    except Exception, e:
        result['message'] = unicode(str(e), "utf8")
示例#14
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)
示例#15
0
 def is_core(self, core_name):
     solr_cores = SolrApi(SOLR_URL.get()).cores()
     return core_name in solr_cores
示例#16
0
 def is_collection(self, collection_name):
     solr_collections = SolrApi(SOLR_URL.get()).collections()
     return collection_name in solr_collections
示例#17
0
    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")
    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,