def coverage_data(request, version, court): """Provides coverage data for a court. Responds to either AJAX or regular requests. """ if court != "all": court_str = get_object_or_404(Court, pk=court).pk else: court_str = "all" q = request.GET.get("q") si = ExtraSolrInterface(settings.SOLR_OPINION_URL, mode="r") facet_field = "dateFiled" response = (si.query().add_extra( **build_coverage_query(court_str, q, facet_field)).execute()) si.conn.http_connection.close() counts = response.facet_counts.facet_ranges[facet_field]["counts"] counts = strip_zero_years(counts) # Calculate the totals annual_counts = {} total_docs = 0 for date_string, count in counts: annual_counts[date_string[:4]] = count total_docs += count return JsonResponse({ "annual_counts": annual_counts, "total": total_docs }, safe=True)
def coverage_data(request, version, court): """Provides coverage data for a court. Responds to either AJAX or regular requests. """ if court != 'all': court_str = get_object_or_404(Court, pk=court).pk else: court_str = 'all' q = request.GET.get('q') conn = sunburnt.SolrInterface(settings.SOLR_OPINION_URL, mode='r') response = conn.raw_query(**build_coverage_query(court_str, q)).execute() counts = response.facet_counts.facet_ranges[0][1][0][1] counts = strip_zero_years(counts) # Calculate the totals annual_counts = {} total_docs = 0 for date_string, count in counts: annual_counts[date_string[:4]] = count total_docs += count return JsonResponse({ 'annual_counts': annual_counts, 'total': total_docs, }, safe=True)
def coverage_data(request, version, court): """Provides coverage data for a court. Responds to either AJAX or regular requests. """ if court != 'all': court_str = get_object_or_404(Court, pk=court).pk else: court_str = 'all' q = request.GET.get('q') conn = sunburnt.SolrInterface(settings.SOLR_OPINION_URL, mode='r') start_year = search_utils.get_court_start_year(conn, court_str) response = conn.raw_query( **search_utils.build_coverage_query(court_str, start_year, q) ).execute() counts = response.facet_counts.facet_ranges[0][1][0][1] counts = strip_trailing_zeroes(counts) # Calculate the totals annual_counts = {} total_docs = 0 for date_string, count in counts: annual_counts[date_string[:4]] = count total_docs += count response = { 'annual_counts': annual_counts, 'total': total_docs, } return JsonResponse(response, safe=True)