diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-01-16 20:42:47 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-01-16 20:42:47 -0300 |
commit | 957085bca7dc58174c8ea02a625092ff5c1054ce (patch) | |
tree | f44aceb622f022687a39492d91a9f4a39e40cf88 | |
parent | 76b140c4513282e3d326e813b3b9881240a67f73 (diff) | |
download | askbot-957085bca7dc58174c8ea02a625092ff5c1054ce.tar.gz askbot-957085bca7dc58174c8ea02a625092ff5c1054ce.tar.bz2 askbot-957085bca7dc58174c8ea02a625092ff5c1054ce.zip |
fixed a bug it postgres full text search, relevance searching still does not work
-rw-r--r-- | askbot/models/question.py | 4 | ||||
-rw-r--r-- | askbot/views/commands.py | 19 |
2 files changed, 12 insertions, 11 deletions
diff --git a/askbot/models/question.py b/askbot/models/question.py index a1899fc7..4544d486 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -214,9 +214,9 @@ class ThreadManager(models.Manager): ### # HACK: GO BACK To QUESTIONS, otherwise we cannot sort properly! + thread_ids = qs.values_list('id', flat = True) qs_thread = qs - - qs = Post.objects.filter(post_type='question', thread__in=qs_thread) + qs = Post.objects.filter(post_type='question', thread__id__in=thread_ids) qs = qs.select_related('thread__last_activity_by') if search_state.sort == 'relevance-desc': diff --git a/askbot/views/commands.py b/askbot/views/commands.py index 2f4e80f4..f596b6f6 100644 --- a/askbot/views/commands.py +++ b/askbot/views/commands.py @@ -446,16 +446,17 @@ def api_get_questions(request): query = request.GET.get('query', '').strip() if not query: return HttpResponseBadRequest('Invalid query') - questions = models.Post.objects.get_questions().get_by_text_query(query) + threads = models.Thread.objects.get_for_query(query) if should_show_sort_by_relevance(): - questions = questions.extra(order_by = ['-relevance']) - questions = questions.filter(deleted=False).select_related('thread').distinct()[:30] - question_list = [{ - 'url': question.get_absolute_url(), - 'title': question.thread.title, - 'answer_count': question.thread.answer_count - } for question in questions] - json_data = simplejson.dumps(question_list) + threads = threads.extra(order_by = ['-relevance']) + #todo: filter out deleted threads, for now there is no way + threads = threads.distinct()[:30] + thread_list = [{ + 'url': thread.get_absolute_url(), + 'title': thread.title, + 'answer_count': thread.answer_count + } for thread in threads] + json_data = simplejson.dumps(thread_list) return HttpResponse(json_data, mimetype = "application/json") |