2 from django.db import connection, transaction
3 from django.db.models import Q
4 from forum.models.question import Question, QuestionManager
5 from forum.models.node import Node
6 from forum.modules import decorate
8 word_re = re.compile(r'\w+', re.UNICODE)
10 @decorate(QuestionManager.search, needs_origin=False)
11 def question_search(self, keywords):
12 tsquery = " | ".join(word_re.findall(keywords))
13 ilike = keywords + u"%%"
15 return True, self.extra(
16 tables = ['forum_rootnode_doc'],
19 rank_exact_matches(ts_rank_cd('{0.1, 0.2, 0.8, 1.0}'::float4[], "forum_rootnode_doc"."document", to_tsquery('english', %s), 32))
23 "forum_rootnode_doc"."node_id" = "forum_node"."id" AND ("forum_rootnode_doc"."document" @@ to_tsquery('english', %s) OR
24 "forum_node"."title" ILIKE %s)
26 params=[tsquery, ilike],
27 select_params=[tsquery],
31 @decorate(Node.delete)
32 def delete(origin, self, *args, **kwargs):
33 cursor = connection.cursor()
34 cursor.execute("DELETE FROM forum_rootnode_doc WHERE node_id = %s" % (self.id))
35 transaction.commit_unless_managed()
36 return origin(self, *args, **kwargs)