]> git.openstreetmap.org Git - osqa.git/blob - forum_modules/mysqlfulltext/startup.py
Use a collation on tag and user names that allows case insensitive search.
[osqa.git] / forum_modules / mysqlfulltext / startup.py
1 from django.db import connection, transaction
2 import os, settings
3
4 import re
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
10
11 if not bool(settings.MYSQL_FTS_INSTALLED):
12     f = open(os.path.join(os.path.dirname(__file__), 'fts_install.sql'), 'r')
13
14     try:
15         cursor = connection.cursor()
16         cursor.execute(f.read())
17         transaction.commit_unless_managed()
18
19         settings.MYSQL_FTS_INSTALLED.set_value(True)
20
21     except Exception, e:
22         #import sys, traceback
23         #traceback.print_exc(file=sys.stdout)
24         pass
25     finally:
26         cursor.close()
27
28     f.close()
29
30 word_re = re.compile(r'\w+', re.UNICODE)
31
32 @decorate(QuestionManager.search, needs_origin=False)
33 def question_search(self, keywords):
34     return False, self.filter(models.Q(ftsindex__body__search=keywords.upper()))