1 from django.db import connection, transaction
5 from django.db import connection, transaction, models
6 from django.db.models import Q
7 from forum.models.question import Question, QuestionManager
8 from forum.models.node import Node
9 from forum.modules import decorate
15 if not bool(settings.MYSQL_FTS_INSTALLED):
16 f_name = os.path.join(os.path.dirname(__file__), 'fts_install.sql')
17 elif int(settings.MYSQL_FTS_VERSION < VERSION):
18 f_name = os.path.join(os.path.dirname(__file__), 'fts_update.sql')
24 cursor = connection.cursor()
25 cursor.execute(f.read())
26 transaction.commit_unless_managed()
28 settings.MYSQL_FTS_INSTALLED.set_value(True)
29 settings.MYSQL_FTS_VERSION.set_value(VERSION)
32 #import sys, traceback
33 #traceback.print_exc(file=sys.stdout)
40 word_re = re.compile(r'\w+', re.UNICODE)
42 @decorate(QuestionManager.search, needs_origin=False)
43 def question_search(self, keywords):
44 keywords = keywords.upper()
46 return '-ranking', self.filter(
47 models.Q(ftsindex__body__search=keywords) or models.Q(ftsindex__title__search=keywords) or models.Q(ftsindex__tagnames__search=keywords)
52 match(forum_mysqlftsindex.tagnames) against (%s in boolean mode) * 4 +
53 match(forum_mysqlftsindex.title) against (%s in boolean mode) * 2 +
54 match(forum_mysqlftsindex.body) against (%s in boolean mode) * 1
57 select_params=[keywords, keywords, keywords]