def index(request): facets = [faceting.get_facet(name) for name in SHOW_THESE] return render_to_response('ui/browse/index.html', { 'facets': facets, }, context_instance=RequestContext(request, processors=[]))
def term_query( request, field, term ): """Results of a search query. """ # prep query for elasticsearch terms_display = {'field':field, 'term':term} terms = {field:term} facet = faceting.get_facet(field) for t in facet['terms']: if t['id'] == term: try: terms_display['term'] = t['title_display'] except: terms_display['term'] = t['title'] break filters = {} fields = models.all_list_fields() sort = {'record_created': request.GET.get('record_created', ''), 'record_lastmod': request.GET.get('record_lastmod', ''),} # do the query results = elasticsearch.query(settings.ELASTICSEARCH_HOST_PORT, settings.DOCUMENT_INDEX, term=terms, filters=filters, fields=fields, sort=sort) hits = models.massage_query_results(results) paginator = Paginator(hits, settings.RESULTS_PER_PAGE) page = paginator.page(request.GET.get('page', 1)) return render_to_response( 'ui/search/results.html', {'paginator': paginator, 'page': page, 'terms': terms_display, 'filters': filters, 'sort': sort,}, context_instance=RequestContext(request, processors=[]) )
def index( request ): facets = [faceting.get_facet(name) for name in SHOW_THESE] return render_to_response( 'ui/browse/index.html', { 'facets': facets, }, context_instance=RequestContext(request, processors=[]) )
def facet(request, facet): facet = faceting.get_facet(facet) terms = faceting.facet_terms(facet) return render_to_response('ui/browse/facet.html', { 'facet': facet, 'facet_terms': terms, }, context_instance=RequestContext(request, processors=[]))
def facet( request, facet ): facet = faceting.get_facet(facet) terms = faceting.facet_terms(facet) return render_to_response( 'ui/browse/facet.html', { 'facet': facet, 'facet_terms': terms, }, context_instance=RequestContext(request, processors=[]) )
def build_object(o, id, source): """Build object from ES GET data. """ o.id = id o.fields = [] for field in DDRmodels.model_fields(o.model): fieldname = field['name'] label = field.get('label', field['name']) if source.get(fieldname, None): # direct attribute setattr(o, fieldname, source[fieldname]) # fieldname,label,value tuple for use in template contents = source[fieldname] style = field_display_style(o, fieldname) if style: if style == 'facet': facet = faceting.get_facet(fieldname) contents_display = field_display_handler[style](fieldname, contents, facet) else: contents_display = field_display_handler[style](fieldname, contents) o.fields.append((fieldname, label, contents_display)) # rename entity.files to entity._files ohasattr = hasattr(o, 'files') if (o.model == 'entity') and hasattr(o, 'files'): o._files = o.files try: delattr(o, 'files') except: pass # parent object ids if o.model == 'file': o.repo, o.org, o.cid, o.eid, o.role, o.sha1 = o.id.split('-') elif o.model == 'entity': o.repo, o.org, o.cid, o.eid = o.id.split('-') elif o.model == 'collection': o.repo, o.org, o.cid = o.id.split('-') elif o.model == 'organization': o.repo, o.org = o.id.split('-') if o.model in ['file']: o.entity_id = '%s-%s-%s-%s' % (o.repo, o.org, o.cid, o.eid) if o.model in ['file', 'entity']: o.collection_id = '%s-%s-%s' % (o.repo, o.org, o.cid) if o.model in ['file', 'entity', 'collection']: o.organization_id = '%s-%s' % (o.repo, o.org) if o.model in ['file', 'entity', 'collection', 'organization']: o.repository_id = '%s' % (o.repo) return o
def build_object( o, id, source ): """Build object from ES GET data. """ o.id = id o.fields = [] for field in DDRmodels.model_fields(o.model): fieldname = field['name'] label = field.get('label', field['name']) if source.get(fieldname,None): # direct attribute setattr(o, fieldname, source[fieldname]) # fieldname,label,value tuple for use in template contents = source[fieldname] style = field_display_style(o, fieldname) if style: if style == 'facet': facet = faceting.get_facet(fieldname) contents_display = field_display_handler[style](fieldname, contents, facet) else: contents_display = field_display_handler[style](fieldname, contents) o.fields.append( (fieldname, label, contents_display) ) # rename entity.files to entity._files ohasattr = hasattr(o, 'files') if (o.model == 'entity') and hasattr(o, 'files'): o._files = o.files try: delattr(o, 'files') except: pass # parent object ids if o.model == 'file': o.repo,o.org,o.cid,o.eid,o.role,o.sha1 = o.id.split('-') elif o.model == 'entity': o.repo,o.org,o.cid,o.eid = o.id.split('-') elif o.model == 'collection': o.repo,o.org,o.cid = o.id.split('-') elif o.model == 'organization': o.repo,o.org = o.id.split('-') if o.model in ['file']: o.entity_id = '%s-%s-%s-%s' % (o.repo,o.org,o.cid,o.eid) if o.model in ['file','entity']: o.collection_id = '%s-%s-%s' % (o.repo,o.org,o.cid) if o.model in ['file','entity','collection']: o.organization_id = '%s-%s' % (o.repo,o.org) if o.model in ['file','entity','collection','organization']: o.repository_id = '%s' % (o.repo) return o
def term_query(request, field, term): """Results of a search query. """ # prep query for elasticsearch terms_display = {'field': field, 'term': term} terms = {field: term} facet = faceting.get_facet(field) for t in facet['terms']: if t['id'] == term: try: terms_display['term'] = t['title_display'] except: terms_display['term'] = t['title'] break filters = {} fields = models.all_list_fields() sort = { 'record_created': request.GET.get('record_created', ''), 'record_lastmod': request.GET.get('record_lastmod', ''), } # do the query results = elasticsearch.query(settings.ELASTICSEARCH_HOST_PORT, settings.DOCUMENT_INDEX, term=terms, filters=filters, fields=fields, sort=sort) hits = models.massage_query_results(results) paginator = Paginator(hits, settings.RESULTS_PER_PAGE) page = paginator.page(request.GET.get('page', 1)) return render_to_response('ui/search/results.html', { 'paginator': paginator, 'page': page, 'terms': terms_display, 'filters': filters, 'sort': sort, }, context_instance=RequestContext(request, processors=[]))