From 6c6f43a4e5339aded1b8b1ae921411cb00c71e84 Mon Sep 17 00:00:00 2001 From: Tomasz Zielinski Date: Tue, 24 Jan 2012 19:05:05 +0100 Subject: Search bugfix attempt - still need assistance from Evgeny --- askbot/models/question.py | 17 +++++++++-------- askbot/views/readers.py | 11 ++++++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/askbot/models/question.py b/askbot/models/question.py index cd1ca184..184e8813 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -98,24 +98,25 @@ class ThreadManager(models.Manager): return thread - def get_for_query(self, search_query): + def get_for_query(self, search_query, qs=None): """returns a query set of questions, matching the full text query """ + if not qs: + qs = self.all() # 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) +# return qs.filter(posts__post_type='question', posts__deleted=False, posts__self_question_id__in=question_ids) if askbot.get_database_engine_name().endswith('mysql') \ and mysql.supports_full_text_search(): - return self.filter( + return qs.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(text_search_vector, plainto_tsquery(%s))"; + rank_clause = "ts_rank(text_search_vector, plainto_tsquery(%s))" search_query = '&'.join(search_query.split()) extra_params = (search_query,) extra_kwargs = { @@ -124,9 +125,9 @@ class ThreadManager(models.Manager): 'params': extra_params, 'select_params': extra_params, } - return self.extra(**extra_kwargs) + return qs.extra(**extra_kwargs) else: - return self.filter( + return qs.filter( models.Q(title__icontains=search_query) | models.Q(tagnames__icontains=search_query) | models.Q(posts__deleted=False, posts__text__icontains = search_query) @@ -148,7 +149,7 @@ class ThreadManager(models.Manager): meta_data = {} if search_state.stripped_query: - qs = self.get_for_query(search_state.stripped_query) + qs = self.get_for_query(search_query=search_state.stripped_query, qs=qs) if search_state.query_title: qs = qs.filter(title__icontains = search_state.query_title) if search_state.query_users: diff --git a/askbot/views/readers.py b/askbot/views/readers.py index c243f99c..e034533c 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -69,6 +69,9 @@ def questions(request, **kwargs): List of Questions, Tagged questions, and Unanswered questions. matching search query or user selection """ + import time + start = time.time() + if request.method != 'GET': return HttpResponseNotAllowed(['GET']) @@ -208,7 +211,12 @@ def questions(request, **kwargs): 'feed_url': context_feed_url, } - return render_into_skin('main_page.html', template_data, request) + tstart = time.time() + ret = render_into_skin('main_page.html', template_data, request) + print "Jinja - elapsed:", time.time() - tstart + print "Elapsed:", time.time() - start + return ret + def tags(request):#view showing a listing of available tags - plain list @@ -455,6 +463,7 @@ def question(request, id):#refactor - long subroutine. display question body, an page_objects = objects_list.page(show_page) #count visits + #import ipdb; ipdb.set_trace() if functions.not_a_robot_request(request): #todo: split this out into a subroutine #todo: merge view counts per user and per session -- cgit v1.2.3-1-g7c22