def select(request, q=""): """ Issues a select request to the search server and renders any results. The query term is derived from the incoming URL, while additional parameters for pagination, faceting, filtering, sorting, etc come from the query string. """ if not connection.is_available(): return HttpResponseRedirect(reverse("solango_search_error")) params = {} facets = [] paginator = None sort_links = [] if q: params["q"] = q if request.GET: params.update(dict(request.GET.items())) if params: paginator = SearchPaginator(params, request) facets = utils.get_facets_links(request, paginator.results) sort_links = utils.get_sort_links(request) return render_to_response( "solango/search.html", {"paginator": paginator, "facets": facets, "q": q, "sort_links": sort_links}, RequestContext(request), )
def main(self, request, form_class=None, template_name=None, extra_context={}): """ Main Function of view """ if not self.is_available(): return HttpResponseRedirect(reverse(self.error_redirect)) form_class = self.get_form(form_class) params = {} facets = [] sort_links = [] paginator = None if request.GET: form = form_class(request.GET) if form.is_valid(): # Get all the get params params.update(dict(request.GET.items())) # Overwrite those with anything you might of changed in the form. params.update(form.cleaned_data) paginator = SearchPaginator(params, request) facets = utils.get_facets_links(request, paginator.results) sort_links = utils.get_sort_links(request) else: form = form_class() # Get Context context = self.get_context(request, paginator, facets, sort_links, form) apply_extra_context(extra_context, context) template = self.get_template(request, template_name) #Render Template rendered_template = template.render(context) return HttpResponse(rendered_template)
def main(self, request, form_class=None, template_name=None, extra_context={}): """ Main Function of view """ if not self.is_available(): return HttpResponseRedirect(reverse(self.error_redirect)) form_class = self.get_form(form_class) params = {} facets = [] sort_links = [] facet_dates = [] paginator = None if request.GET: form = form_class(request.GET) if form.is_valid(): # Get all the get params get_args = dict(request.GET.items()) # Add wildcards to q words = request.GET.get('q', '').split() words_wild = [] for word in words: words_wild.append(word.strip() + '* ') if words_wild: get_args['q'] = ' '.join(words_wild) params.update(get_args) # Overwrite those with anything you might of changed in the form. params.update(form.cleaned_data) paginator = SearchPaginator(params, request) facets = utils.get_facets_links(request, paginator.results) sort_links = utils.get_sort_links(request) else: form = form_class() # Get Context context = self.get_context(request, paginator, facets, sort_links, form) apply_extra_context(extra_context, context) template = self.get_template(request, template_name) #Render Template rendered_template = template.render(context) return HttpResponse(rendered_template)
def main(self, request, form_class=None, template=None, extra_context={}): """ Main Function of view """ form_class = self.get_form(form_class) params = [] facets = [] sort_links = [] facet_dates = [] paginator = None if request.GET: form = form_class(request.GET) if form.is_valid(): # Get all the get params params = deepcopy(request.GET) page = int(params.pop("page", [1])[0]) per_page = int(params.pop("per_page", [25])[0]) params.update(form.cleaned_data) query = self.index.query(params.items()) query.start = (page - 1) * per_page query.rows = per_page results = self.select(query) paginator = SearchPaginator(results, request, page, per_page) facets = utils.get_facets_links(request, paginator.results) sort_links = utils.get_sort_links(request) else: form = form_class() # Get Context context = self.get_context(request, paginator, facets, sort_links, form) apply_extra_context(extra_context, context) template = self.get_template(request, template) # Render Template rendered_template = template.render(context) return HttpResponse(rendered_template)
def main(self, request, form_class=None, template_name=None, extra_context={}): """ Main Function of view """ if not self.is_available(): return HttpResponseRedirect(reverse(self.error_redirect)) form_class = self.get_form(form_class) params = {} facets = [] sort_links = [] facet_dates = [] paginator = None form = form_class(request.GET) # Get all the get params # Overwrite those with anything you might of changed in the form. params.update(dict(request.GET.items())) q = request.GET.get("q") if q: params.pop("q") params["q"] = "text:%s^10 OR text:%s~" % (q, q) params["state"] = '"P"' else: params["q"] = 'state:"P"' params.update(dict(per_page=40)) params.pop("x", None) params.pop("y", None) paginator = SearchPaginator(params, request) facets = utils.get_facets_links(request, paginator.results) sort_links = utils.get_sort_links(request) # Get Context context = self.get_context(request, paginator, facets, sort_links, form) apply_extra_context(extra_context, context) template = self.get_template(request, template_name) # Render Template rendered_template = template.render(context) return HttpResponse(rendered_template)