Esempio n. 1
0
def process_query(request):
    """
    Uses regular expression pattern matching on text for quoted phrases,
    tsquery for the rest.  Uses the soon-to-be deprecated extra()
    method, because this returns a QuerySet on which we can do additional
    filtering.

    We might want to limit the number of results we actually return,
    which is why the query contains an order_by clause.  Returning
    them all for now.
    """

    try:
        raw = request.GET.get('query')
        raw_title = request.GET.get('query_title', '')
        raw_sponsors = request.GET.get('query_sponsors', '')

        ignore_routine = request.GET.get('ignore_routine', 'true').lower() \
            in ['true', 't', '1']
        date_range = request.GET.get('date_range', '')

        if raw_title or raw_sponsors:
            qs, is_ranked = advanced_search(raw, raw_title, raw_sponsors,
                    ignore_routine=ignore_routine,
                    date_range=date_range)
        else:
            qs, is_ranked = simple_search(raw,
                    ignore_routine=ignore_routine,
                    date_range=date_range)

        return _documents_json(qs, is_ranked)
    except Exception as e:
        traceback.print_exc()
        return JsonResponse({'error': str(e)})
Esempio n. 2
0
def default_query(request):
    """
    Find all non-routine documents from within the last 30 days
    """
    try:
        qs, is_ranked = simple_search('', ignore_routine=True, date_range='past-month')
        return _documents_json(qs, is_ranked)
    except Exception as e:
        traceback.print_exc()
        return JsonResponse({'error': str(e)})