if not keywords:
return HttpResponseRedirect(reverse(index))
if search_type == 'tag':
- return HttpResponseRedirect(reverse('tags') + '?q=%s' % (keywords.strip()))
+ return HttpResponseRedirect(reverse('tags') + '?q=%s' % urlquote(keywords.strip()))
elif search_type == "user":
- return HttpResponseRedirect(reverse('users') + '?q=%s' % (keywords.strip()))
+ return HttpResponseRedirect(reverse('users') + '?q=%s' % urlquote(keywords.strip()))
elif search_type == "question":
return question_search(request, keywords)
else:
@decorate(QuestionManager.search, needs_origin=False)
def question_search(self, keywords):
- repl_re = re.compile(r"[^\'\-_\s\w]")
+ repl_re = re.compile(r"[^\'\-_\s\w]", re.UNICODE)
tsquery = " | ".join([k for k in repl_re.sub('', keywords).split(' ') if k])
+ ilike = keywords + u"%%"
return self.extra(
tables = ['forum_rootnode_doc'],
},
where=["""
"forum_rootnode_doc"."node_id" = "forum_node"."id" AND ("forum_rootnode_doc"."document" @@ to_tsquery('english', %s) OR
- "forum_node"."title" ILIKE '""" + keywords.replace("'",r"\'") + """%%')
+ "forum_node"."title" ILIKE %s)
"""],
- params=[tsquery],
+ params=[tsquery, ilike],
select_params=[tsquery],
order_by=['-ranking']
)