Exemple #1
0
def search(request):
    """
    Central function for request processing and response generation.
    Return HTTP Response object
    """
    raw_query = request.GET.get('query', '')

    show_bing = 'bing' in request.GET
    show_blekko = 'blekko' in request.GET
    show_entweb = 'entweb' in request.GET
    aggr = request.GET.get('aggr', '')
    cluster = request.GET.get('cluster', '')

    errors = validate(raw_query, show_bing, show_blekko, show_entweb, aggr)

    if errors:
        return render(request, 'metasearch/start.html', {'errors': errors})

    queries = string_process(raw_query)

    page = int(request.GET.get('page', '1'))

    if 1 <= page <= 6:
        page_list = range(1, 11)  # 1, 2, ..., 10
    elif page > 6:
        page_list = range(page - 5, page + 5)

    full_path = request.get_full_path()

    if aggr == 'false' or aggr == '':
        lists = non_aggr_search(queries, show_bing, show_blekko, show_entweb,
                                page)

        if cluster == 'true':
            bing_clusters = make_cluster(lists[0])
            blekko_clusters = make_cluster(lists[1])
            entweb_clusters = make_cluster(lists[2])

            return render(
                request, 'metasearch/results_nonaggr.html', {
                    'raw_query': raw_query,
                    'show_bing': show_bing,
                    'show_blekko': show_blekko,
                    'show_entweb': show_entweb,
                    'cluster': True,
                    'bing_clusters': bing_clusters,
                    'blekko_clusters': blekko_clusters,
                    'entweb_clusters': entweb_clusters,
                    'full_path': full_path,
                    'page_list': page_list,
                    'current_page': page
                })

        elif cluster == 'false' or cluster == '':
            return render(
                request, 'metasearch/results_nonaggr.html', {
                    'raw_query': raw_query,
                    'show_bing': show_bing,
                    'show_blekko': show_blekko,
                    'show_entweb': show_entweb,
                    'cluster': False,
                    'bing_list': lists[0],
                    'blekko_list': lists[1],
                    'entweb_list': lists[2],
                    'full_path': full_path,
                    'page_list': page_list,
                    'current_page': page
                })
    elif aggr == 'true':
        result_list = aggr_search(queries, show_bing, show_blekko, show_entweb,
                                  page)

        if cluster == 'true':
            clusters = make_cluster(result_list)

            return render(
                request, 'metasearch/results_aggr.html', {
                    'raw_query': raw_query,
                    'show_bing': show_bing,
                    'show_blekko': show_blekko,
                    'show_entweb': show_entweb,
                    'cluster': True,
                    'clusters': clusters,
                    'full_path': full_path,
                    'page_list': page_list,
                    'current_page': page
                })

        elif cluster == 'false' or cluster == '':
            return render(
                request, 'metasearch/results_aggr.html', {
                    'raw_query': raw_query,
                    'show_bing': show_bing,
                    'show_blekko': show_blekko,
                    'show_entweb': show_entweb,
                    'cluster': False,
                    'result_list': result_list,
                    'full_path': full_path,
                    'page_list': page_list,
                    'current_page': page
                })
Exemple #2
0
def search(request):
    """
    Central function for request processing and response generation.
    Return HTTP Response object
    """
    raw_query = request.GET.get('query', '')
    
    show_bing = request.GET.has_key('bing')
    show_blekko = request.GET.has_key('blekko')
    show_entweb = request.GET.has_key('entweb')
    aggr = request.GET.get('aggr', '')
    cluster = request.GET.get('cluster', '')
    
    errors = validate(raw_query, show_bing, show_blekko, show_entweb, aggr)
    
    if errors:
        return render(request, 'metasearch/start.html', {'errors' : errors})
    
    queries = string_process(raw_query)
    
    page = int(request.GET.get('page', '1'))
    
    if 1 <= page <= 6:
        page_list = range(1, 11) # 1, 2, ..., 10
    elif page > 6:
        page_list = range(page - 5, page + 5)
        
    full_path = request.get_full_path()
    
    if aggr == 'false' or aggr == '':
        lists = non_aggr_search(queries, show_bing, show_blekko, show_entweb, page)
        
        if cluster == 'true':
            bing_clusters = make_cluster(lists[0])
            blekko_clusters = make_cluster(lists[1])
            entweb_clusters = make_cluster(lists[2])
            
            return render(request, 'metasearch/results_nonaggr.html', 
                    {
                        'raw_query' : raw_query,
                        'show_bing' : show_bing,
                        'show_blekko' : show_blekko,
                        'show_entweb' : show_entweb,
                        'cluster' : True,
                        'bing_clusters' : bing_clusters,
                        'blekko_clusters' : blekko_clusters, 
                        'entweb_clusters' : entweb_clusters,
                        'full_path' : full_path,
                        'page_list' : page_list,
                        'current_page': page
                    }
                    )
        
        elif cluster == 'false' or cluster == '':
            return render(request, 'metasearch/results_nonaggr.html', 
                    {
                        'raw_query' : raw_query,
                        'show_bing' : show_bing,
                        'show_blekko' : show_blekko,
                        'show_entweb' : show_entweb,
                        'cluster' : False,
                        'bing_list' : lists[0],
                        'blekko_list' : lists[1], 
                        'entweb_list' : lists[2],
                        'full_path' : full_path,
                        'page_list' : page_list,
                        'current_page': page
                    }
                    )
    elif aggr == 'true':
        result_list = aggr_search(queries, show_bing, show_blekko, show_entweb, page)
        
        if cluster == 'true':
            clusters = make_cluster(result_list)

            return render(request, 'metasearch/results_aggr.html', 
                    {
                        'raw_query' : raw_query,
                        'show_bing' : show_bing,
                        'show_blekko' : show_blekko,
                        'show_entweb' : show_entweb,
                        'cluster' : True,
                        'clusters': clusters,
                        'full_path' : full_path,
                        'page_list' : page_list,
                        'current_page': page
                    }
                    )
            
        elif cluster == 'false' or cluster == '':
            return render(request, 'metasearch/results_aggr.html', 
                    {
                        'raw_query' : raw_query,
                        'show_bing' : show_bing,
                        'show_blekko' : show_blekko,
                        'show_entweb' : show_entweb,
                        'cluster' : False,
                        'result_list': result_list,
                        'full_path' : full_path,
                        'page_list' : page_list,
                        'current_page': page
                    }
                    )