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 results( request ): """Results of a search query. """ # prep query for elasticsearch model = request.GET.get('model', None) q = django_urlquote(request.GET.get('query', '')) 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, query=q, 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, 'query': q, 'filters': filters, 'sort': sort,}, context_instance=RequestContext(request, processors=[]) )
def results(request): """Results of a search query. """ # prep query for elasticsearch model = request.GET.get('model', None) q = django_urlquote(request.GET.get('query', '')) 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, query=q, 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, 'query': q, 'filters': filters, 'sort': sort, }, 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=[]))