Ejemplo n.º 1
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)
Ejemplo n.º 2
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 = []
Ejemplo n.º 3
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")
Ejemplo n.º 4
0
  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()])
Ejemplo n.º 5
0
    def decorator(request, *args, **kwargs):
        try:
            return view_fn(request, *args, **kwargs)
        except Exception, e:
            from search.api import SolrApi

            if "/solr/twitter_demo/select" in str(e):
                return SolrApi._get_json(TWITTER_SEARCH_RESPONSE)
            elif "/solr/yelp_demo/select" in str(e):
                return SolrApi._get_json(YELP_SEARCH_RESPONSE)
            elif "/solr/log_demo/select" in str(e):
                return SolrApi._get_json(LOG_SEARCH_RESPONSE)
            else:
                raise e
Ejemplo n.º 6
0
def admin_collection_schema(request, collection_id):
    hue_collection = Collection.objects.get(id=collection_id)
    solr_schema = SolrApi(SOLR_URL.get()).schema(hue_collection.name)

    content = {'solr_schema': solr_schema.decode('utf-8')}
    return HttpResponse(json.dumps(content), mimetype="application/json")
Ejemplo n.º 7
0
 def is_core(self, core_name):
     solr_cores = SolrApi(SOLR_URL.get()).cores()
     return core_name in solr_cores
Ejemplo n.º 8
0
 def is_collection(self, collection_name):
     solr_collections = SolrApi(SOLR_URL.get()).collections()
     return collection_name in solr_collections
Ejemplo n.º 9
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,