Ejemplo n.º 1
0
def results(request , template_name = "search/results.html"):

    #get current search phrase
    q = request.GET.get('q','')
    # get the current page number . Set it to 1 is missing or invalid
    try:
        page = int(request.GET.get('page',1))

    except ValueError:
        page = 1
    # retrieve the matching destinations

    matching = search.destinations(q).get('destinations')

    #generate the paginator object
    paginator = Paginator(matching,settings.DESTINATIONS_PER_PAGE)
    try:
        results = paginator.page(page).object_list
    except (InvalidPage,EmptyPage):
        results = paginator.page(1).object_list

    # store the search
    search.store(request ,q)

    page_title = 'Search Results for: '+ q

    return render_to_response(template_name ,locals(),context_instance = RequestContext(request))
Ejemplo n.º 2
0
def recommend_from_search(request):
    #get the common words from the stored searches
    common_words = frequent_search_words(request)
    from savannahtrekkers.search import search
    matching = []
    for word in common_words:
        results = search.destinations(word).get('destinations',[])
        for r in results:
            if len(matching)>DESTINATIONS_PER_ROW and not r in matching:
                matching.append(r)
    return matching