def recommended_from_search(request): # get the common words from the stored searches common_words = frequent_search_words(request) from djecomstore.search import search matching = [] for word in common_words: results = search.products(word).get('products',[]) for r in results: if len(matching) < PRODUCTS_PER_ROW and not r in matching: matching.append(r) return matching
def results(request, template_name="search/results.html"): # get current search phrase q = request.GET.get('q', '') # get current page number. Set to 1 is missing or invalid try: page = int(request.GET.get('page', 1)) except ValueError: page = 1 # retrieve the matching products matching = search.products(q).get('products') #generate the paginator object paginator = Paginator(matching, settings.PRODUCTS_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) # the usual... page_title = 'Search Results for: ' + q return render_to_response(template_name, locals(), context_instance=RequestContext(request))