예제 #1
0
def do_search(request, rows=20, order_by=None, type=None):

    # Bind the search form.
    search_form = SearchForm(request.GET)
    if search_form.is_valid():
        cd = search_form.cleaned_data
        # Allows an override by calling methods.
        if order_by:
            cd['order_by'] = order_by
        if type:
            cd['type'] = type
        search_form = _clean_form(request, cd)

        try:
            if cd['type'] == 'o':
                conn = sunburnt.SolrInterface(settings.SOLR_OPINION_URL,
                                              mode='r')
                stat_facet_fields = search_utils.place_facet_queries(cd, conn)
                status_facets = search_utils.make_stats_variable(
                    stat_facet_fields, search_form)
            elif cd['type'] == 'oa':
                conn = sunburnt.SolrInterface(settings.SOLR_AUDIO_URL,
                                              mode='r')
                status_facets = None
            results_si = conn.raw_query(**search_utils.build_main_query(cd))

            courts = Court.objects.filter(in_use=True).values(
                'pk', 'short_name', 'jurisdiction',
                'has_oral_argument_scraper')
            courts, court_count_human, court_count = search_utils\
                .merge_form_with_courts(courts, search_form)

        except Exception, e:
            logger.warning("Error loading search with request: %s" %
                           request.GET)
            logger.warning("Error was %s" % e)
            return {'error': True}
예제 #2
0
def do_search(request, rows=20, order_by=None, type=None):

    # Bind the search form.
    search_form = SearchForm(request.GET)
    if search_form.is_valid():
        cd = search_form.cleaned_data
        # Allows an override by calling methods.
        if order_by is not None:
            cd['order_by'] = order_by
        if type is not None:
            cd['type'] = type
        search_form = _clean_form(request, cd)

        try:
            if cd['type'] == 'o':
                conn = sunburnt.SolrInterface(settings.SOLR_OPINION_URL,
                                              mode='r')
                stat_facet_fields = search_utils.place_facet_queries(cd, conn)
                status_facets = search_utils.make_stats_variable(
                    stat_facet_fields, search_form)
            elif cd['type'] == 'oa':
                conn = sunburnt.SolrInterface(settings.SOLR_AUDIO_URL,
                                              mode='r')
                status_facets = None
            elif cd['type'] == 'p':
                conn = sunburnt.SolrInterface(settings.SOLR_PEOPLE_URL,
                                              mode='r')
                status_facets = None
            results_si = conn.raw_query(**search_utils.build_main_query(cd))

            courts = Court.objects.filter(in_use=True)
            courts, court_count_human, court_count = search_utils\
                .merge_form_with_courts(courts, search_form)

        except Exception as e:
            if settings.DEBUG is True:
                traceback.print_exc()
            logger.warning("Error loading search with request: %s" %
                           request.GET)
            logger.warning("Error was %s" % e)
            return {'error': True}

    else:
        # Invalid form, send it back
        logger.warning(
            "Invalid form when loading search page with request: %s" %
            request.GET)
        return {'error': True}

    # Set up pagination
    try:
        paginator = Paginator(results_si, rows)
        page = request.GET.get('page', 1)
        try:
            paged_results = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            paged_results = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            paged_results = paginator.page(paginator.num_pages)
    except Exception, e:
        # Catches any Solr errors, and aborts.
        logger.warning(
            "Error loading pagination on search page with request: %s" %
            request.GET)
        logger.warning("Error was: %s" % e)
        if settings.DEBUG is True:
            print e
        return {'error': True}
예제 #3
0
def do_search(request, rows=20, order_by=None, type=None):

    search_form = SearchForm(request.GET)
    if search_form.is_valid():
        cd = search_form.cleaned_data
        # Allows an override by calling methods.
        if order_by is not None:
            cd['order_by'] = order_by
        if type is not None:
            cd['type'] = type
        search_form = _clean_form(request, cd)

        try:
            query_citation = None
            status_facets = None
            if cd['type'] == 'o':
                si = ExtraSolrInterface(settings.SOLR_OPINION_URL, mode='r')
                stat_facet_fields = place_facet_queries(cd, si)
                status_facets = make_stats_variable(stat_facet_fields,
                                                    search_form)
                query_citation = get_query_citation(cd)
                results = si.query().add_extra(**build_main_query(cd))
            elif cd['type'] == 'r':
                si = ExtraSolrInterface(settings.SOLR_RECAP_URL, mode='r')
                results = si.query().add_extra(**build_main_query(cd))
            elif cd['type'] == 'oa':
                si = ExtraSolrInterface(settings.SOLR_AUDIO_URL, mode='r')
                results = si.query().add_extra(**build_main_query(cd))
            elif cd['type'] == 'p':
                si = ExtraSolrInterface(settings.SOLR_PEOPLE_URL, mode='r')
                results = si.query().add_extra(**build_main_query(cd))

            courts = Court.objects.filter(in_use=True)
            courts, court_count_human, court_count = merge_form_with_courts(
                courts,
                search_form
            )

        except Exception as e:
            if settings.DEBUG is True:
                traceback.print_exc()
            logger.warning("Error loading search with request: %s" % request.GET)
            logger.warning("Error was %s" % e)
            return {'error': True}

    else:
        # Invalid form, send it back
        logger.warning("Invalid form when loading search page with request: %s" % request.GET)
        return {'error': True}

    # Set up pagination
    try:
        paginator = Paginator(results, rows)
        page = request.GET.get('page', 1)
        try:
            paged_results = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            paged_results = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            paged_results = paginator.page(paginator.num_pages)
    except Exception, e:
        # Catches any Solr errors, and aborts.
        logger.warning("Error loading pagination on search page with request: %s" % request.GET)
        logger.warning("Error was: %s" % e)
        if settings.DEBUG is True:
            traceback.print_exc()
        return {'error': True}