X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/55eea8d5a3f8fcc3a509f2eaf45005bba20fc76a..0bd53bfd0a08e9949651ec35bf22048db8e740d9:/forum_modules/mysqlfulltext/startup.py?ds=sidebyside diff --git a/forum_modules/mysqlfulltext/startup.py b/forum_modules/mysqlfulltext/startup.py index e2bc7ef..8c2af5f 100644 --- a/forum_modules/mysqlfulltext/startup.py +++ b/forum_modules/mysqlfulltext/startup.py @@ -8,7 +8,7 @@ from forum.models.question import Question, QuestionManager from forum.models.node import Node from forum.modules import decorate -VERSION = 2 +VERSION = 4 f_name = None @@ -43,16 +43,16 @@ word_re = re.compile(r'\w+', re.UNICODE) 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) - + qs = self.filter( + 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] - ) + ).filter(Q(ftsindex__title__search=keywords) | Q(ftsindex__tagnames__search=keywords) | Q(ftsindex__body__search=keywords)) + return '-ranking', qs