]> git.openstreetmap.org Git - osqa.git/blobdiff - forum_modules/pgfulltext/handlers.py
Fix OSQA 257, Improve search algorithm.
[osqa.git] / forum_modules / pgfulltext / handlers.py
index 835c2f5dd76e463fc25fed9e5ddfc25ad61f2ab5..2b57e96efe699bca3b6f45a81dfb5b44c1ab7541 100644 (file)
@@ -5,10 +5,11 @@ from forum.views.readers import do_question_search
 @decorate(do_question_search, needs_origin=False)
 def question_search(keywords):
     return Question.objects.all().extra(
+                    tables=['forum_rootnode_doc'],
                     select={
-                        'ranking': 'node_ranking("forum_node"."id", %s)',
+                        'ranking': 'ts_rank_cd("forum_rootnode_doc"."document", plainto_tsquery(\'english\', %s), 32)',
                     },
-                    where=['node_ranking("forum_node"."id", %s) > 0'],
+                    where=['"forum_rootnode_doc"."node_id" = "forum_node"."id"', '"forum_rootnode_doc"."document" @@ plainto_tsquery(\'english\', %s)'],
                     params=[keywords],
                     select_params=[keywords],
                     order_by=['-ranking']