diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-01-10 16:39:59 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-01-10 16:39:59 -0300 |
commit | 5e71f4a5015a69923e7aab4785f00e7d7089f3f2 (patch) | |
tree | ec0ab6dcff8046a3972cf23e82244997d37f7634 | |
parent | 25d449b1a3291e8bd644d6a1c66e7b8331983bc1 (diff) | |
download | askbot-5e71f4a5015a69923e7aab4785f00e7d7089f3f2.tar.gz askbot-5e71f4a5015a69923e7aab4785f00e7d7089f3f2.tar.bz2 askbot-5e71f4a5015a69923e7aab4785f00e7d7089f3f2.zip |
restored the postgres search config
-rw-r--r-- | askbot/management/commands/setup_postgresql_full_text_search.plsql | 28 | ||||
-rw-r--r-- | askbot/models/question.py | 52 |
2 files changed, 44 insertions, 36 deletions
diff --git a/askbot/management/commands/setup_postgresql_full_text_search.plsql b/askbot/management/commands/setup_postgresql_full_text_search.plsql index 94a443de..7156833b 100644 --- a/askbot/management/commands/setup_postgresql_full_text_search.plsql +++ b/askbot/management/commands/setup_postgresql_full_text_search.plsql @@ -174,10 +174,10 @@ UPDATE askbot_thread as t SET text_search_vector = text_search_vector || /* one trigger per table for tsv updates */ /* set up update triggers */ -CREATE OR REPLACE FUNCTION thread_trigger() RETURNS trigger AS +CREATE OR REPLACE FUNCTION thread_update_trigger() RETURNS trigger AS $$ BEGIN - new.text_search_vector = get_thread_tsv(new.tagnames) || + new.text_search_vector = get_thread_tsv(new.title, new.tagnames) || get_thread_question_tsv(new.id) || get_dependent_answers_tsv(new.id); RETURN new; @@ -185,23 +185,33 @@ END; $$ LANGUAGE plpgsql; DROP TRIGGER IF EXISTS thread_search_vector_update_trigger on askbot_thread; CREATE TRIGGER thread_search_vector_update_trigger -BEFORE INSERT OR UPDATE ON askbot_thread FOR EACH ROW EXECUTE PROCEDURE thread_trigger(); +BEFORE UPDATE ON askbot_thread FOR EACH ROW EXECUTE PROCEDURE thread_update_trigger(); + +CREATE OR REPLACE FUNCTION thread_insert_trigger() RETURNS trigger AS +$$ +BEGIN + new.text_search_vector = get_thread_tsv(new.title, new.tagnames); + RETURN new; +END; +$$ LANGUAGE plpgsql; +DROP TRIGGER IF EXISTS thread_search_vector_insert_trigger on askbot_thread; +CREATE TRIGGER thread_search_vector_insert_trigger +BEFORE INSERT ON askbot_thread FOR EACH ROW EXECUTE PROCEDURE thread_insert_trigger(); /* post trigger */ CREATE OR REPLACE FUNCTION post_trigger() RETURNS trigger AS $$ BEGIN IF new.post_type = 'question' THEN - new.text_search_vector = get_post_tsv(new.text, 'question'); - new.text_search_vector = new.text_search_vector || - get_dependent_comments_tsv(new.id); + new.text_search_vector = get_post_tsv(new.text, 'question') || + get_dependent_comments_tsv(new.id); ELSIF new.post_type = 'answer' THEN - new.text_search_vector = get_post_tsv(new.text, 'answer'); - new.text_search_vector = new.text_search_vector || - get_dependent_comments_tsv(new.id); + new.text_search_vector = get_post_tsv(new.text, 'answer') || + get_dependent_comments_tsv(new.id); ELSIF new.post_type = 'comment' THEN new.text_search_vector = get_post_tsv(new.text, 'comment'); END IF; + UPDATE askbot_thread SET id=new.thread_id WHERE id=new.thread_id; return new; END; $$ LANGUAGE plpgsql; diff --git a/askbot/models/question.py b/askbot/models/question.py index b3ce8e68..5bca15f9 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -96,37 +96,35 @@ class ThreadManager(models.Manager): """returns a query set of questions, matching the full text query """ - return self.filter( - models.Q(title__icontains=search_query) | - models.Q(tagnames__icontains=search_query) | - models.Q(posts__deleted=False, posts__text__icontains = search_query) - ) - # if getattr(settings, 'USE_SPHINX_SEARCH', False): # matching_questions = Question.sphinx_search.query(search_query) # question_ids = [q.id for q in matching_questions] # return self.filter(posts__post_type='question', posts__deleted=False, posts__self_question_id__in=question_ids) -# elif settings.DATABASE_ENGINE == 'mysql' and mysql.supports_full_text_search(): -# return self.filter( -# models.Q(title__search = search_query) | -# models.Q(tagnames__search = search_query) | -# models.Q(posts__deleted=False, posts__text__search = search_query) -# ) -# elif 'postgresql_psycopg2' in askbot.get_database_engine_name(): -# # TODO: !! Fix Postgres search -# rank_clause = "ts_rank(question.text_search_vector, plainto_tsquery(%s))"; -# search_query = '&'.join(search_query.split()) -# extra_params = (search_query,) -# extra_kwargs = { -# 'select': {'relevance': rank_clause}, -# 'where': ['text_search_vector @@ plainto_tsquery(%s)'], -# 'params': extra_params, -# 'select_params': extra_params, -# } -# return self.extra(**extra_kwargs) -# else: -# #fallback to dumb title match search -# return self.filter(title__icontains=search_query) + if settings.DATABASE_ENGINE == 'mysql' and mysql.supports_full_text_search(): + return self.filter( + models.Q(title__search = search_query) | + models.Q(tagnames__search = search_query) | + models.Q(posts__deleted=False, posts__text__search = search_query) + ) + elif 'postgresql_psycopg2' in askbot.get_database_engine_name(): + # TODO: !! Fix Postgres search + rank_clause = "ts_rank(question.text_search_vector, plainto_tsquery(%s))"; + search_query = '&'.join(search_query.split()) + extra_params = (search_query,) + extra_kwargs = { + 'select': {'relevance': rank_clause}, + 'where': ['text_search_vector @@ plainto_tsquery(%s)'], + 'params': extra_params, + 'select_params': extra_params, + } + return self.extra(**extra_kwargs) + else: + return self.filter( + models.Q(title__icontains=search_query) | + models.Q(tagnames__icontains=search_query) | + models.Q(posts__deleted=False, posts__text__icontains = search_query) + ) + def run_advanced_search(self, request_user=None, search_state=None): # TODO: !! review and fix this """ |