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 def delete_docs(node):
32 cursor = connection.cursor()
33 cursor.execute("DELETE FROM forum_rootnode_doc WHERE node_id = %s" % (node.id))
35 for n in node.children.all():
39 #@decorate(Node.delete)
40 def delete(origin, self, *args, **kwargs):
42 transaction.commit_unless_managed()
43 origin(self, *args, **kwargs)