From: hernani Date: Thu, 26 May 2011 12:07:42 +0000 (+0000) Subject: Some improvements in the mysql full text module. X-Git-Tag: live~265 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/389dfe31994fdc9e835af751b59e784d49f9e175?hp=3540ef931f8aaf061ea2d80bf5ac3fbca77fe35c Some improvements in the mysql full text module. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1048 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum_modules/mysqlfulltext/__init__.py b/forum_modules/mysqlfulltext/__init__.py index b9ce96f..679d703 100644 --- a/forum_modules/mysqlfulltext/__init__.py +++ b/forum_modules/mysqlfulltext/__init__.py @@ -3,8 +3,10 @@ DESCRIPTION = "Enables Mysql full text search functionality." try: import MySQLdb - from django.conf import settings - CAN_USE = settings.DATABASE_ENGINE in ('mysql', 'pooled_mysql') -except: + import settings_local + CAN_USE = settings_local.DATABASE_ENGINE in ('mysql', 'pooled_mysql') +except Exception, e: + import traceback + traceback.print_exc() CAN_USE = False \ No newline at end of file diff --git a/forum_modules/mysqlfulltext/models.py b/forum_modules/mysqlfulltext/models.py index 8f22379..1de3dea 100644 --- a/forum_modules/mysqlfulltext/models.py +++ b/forum_modules/mysqlfulltext/models.py @@ -3,6 +3,8 @@ from django.db import models class MysqlFtsIndex(models.Model): node = models.OneToOneField('Node', related_name='ftsindex') body = models.TextField() + title = models.CharField(max_length=300) + tagnames = models.CharField(max_length=255) class Meta: managed = False diff --git a/forum_modules/mysqlfulltext/startup.py b/forum_modules/mysqlfulltext/startup.py index e2bc7ef..232bbb4 100644 --- a/forum_modules/mysqlfulltext/startup.py +++ b/forum_modules/mysqlfulltext/startup.py @@ -44,14 +44,13 @@ def question_search(self, keywords): keywords = keywords.upper() return '-ranking', self.filter( - models.Q(ftsindex__body__search=keywords) or models.Q(ftsindex__title__search=keywords) or models.Q(ftsindex__tagnames__search=keywords) - + models.Q(ftsindex__body__isnull=False) ).extra( select={ 'ranking': """ - match(forum_mysqlftsindex.tagnames) against (%s in boolean mode) * 4 + - match(forum_mysqlftsindex.title) against (%s in boolean mode) * 2 + - match(forum_mysqlftsindex.body) against (%s in boolean mode) * 1 + match(forum_mysqlftsindex.tagnames) against (%s) * 2 + + match(forum_mysqlftsindex.title) against (%s) * 4 + + match(forum_mysqlftsindex.body) against (%s) * 1 """, }, select_params=[keywords, keywords, keywords]