]> git.openstreetmap.org Git - osqa.git/blob - forum_modules/pgfulltext/handlers.py
Fix OSQA 257, Improve search algorithm.
[osqa.git] / forum_modules / pgfulltext / handlers.py
1 from forum.models import Question
2 from forum.modules.decorators import decorate
3 from forum.views.readers import do_question_search
4
5 @decorate(do_question_search, needs_origin=False)
6 def question_search(keywords):
7     return Question.objects.all().extra(
8                     tables=['forum_rootnode_doc'],
9                     select={
10                         'ranking': 'ts_rank_cd("forum_rootnode_doc"."document", plainto_tsquery(\'english\', %s), 32)',
11                     },
12                     where=['"forum_rootnode_doc"."node_id" = "forum_node"."id"', '"forum_rootnode_doc"."document" @@ plainto_tsquery(\'english\', %s)'],
13                     params=[keywords],
14                     select_params=[keywords],
15                     order_by=['-ranking']
16                 )