]> git.openstreetmap.org Git - osqa.git/commitdiff
Fixes some problems with urlquoting on seraches.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 3 Jun 2010 18:01:39 +0000 (18:01 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 3 Jun 2010 18:01:39 +0000 (18:01 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@363 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/views/readers.py
forum_modules/pgfulltext/handlers.py

index f756a9468f7c12042ec8d34c6104b5b177ec19d4..6e75b378a1572b2900f78933db16bdeab4157f69 100644 (file)
@@ -120,9 +120,9 @@ def search(request):
         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:
index f6decaf01275e0d9a565e0c017a83503de150637..196790bfedc964b14fe43cb22c058fb631e96056 100644 (file)
@@ -5,8 +5,9 @@ from forum.modules.decorators import decorate
 
 @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'],
@@ -17,9 +18,9 @@ def question_search(self, keywords):
                     },
                     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']
                 )