def get_by_text_query(self, search_query): """returns a query set of questions, matching the full text 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 Question.objects.filter(deleted=False, id__in=question_ids) if settings.DATABASE_ENGINE == 'mysql' and mysql.supports_full_text_search( ): return self.filter( models.Q(title__search = search_query) \ | models.Q(text__search = search_query) \ | models.Q(tagnames__search = search_query) \ | models.Q(answers__text__search = search_query) ) elif 'postgresql_psycopg2' in askbot.get_database_engine_name(): rank_clause = "ts_rank(question.text_search_vector, to_tsquery(%s))" search_query = '&'.join(search_query.split()) extra_params = (search_query, ) extra_kwargs = { 'select': { 'relevance': rank_clause }, 'where': ['text_search_vector @@ to_tsquery(%s)'], 'params': extra_params, 'select_params': extra_params, } return self.extra(**extra_kwargs) else: #fallback to dumb title match search return self.extra(where=['title like %s'], params=['%' + 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 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 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(): rank_clause = "ts_rank(askbot_thread.text_search_vector, plainto_tsquery(%s))" search_query = '&'.join(search_query.split()) extra_params = (search_query,) extra_kwargs = { 'select': {'relevance': rank_clause}, 'where': ['askbot_thread.text_search_vector @@ plainto_tsquery(%s)'], 'params': extra_params, 'select_params': extra_params, } return qs.extra(**extra_kwargs) else: 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) )
def get_by_text_query(self, search_query): """returns a query set of questions, matching the full text 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 Question.objects.filter(deleted = False, id__in = question_ids) if settings.DATABASE_ENGINE == 'mysql' and mysql.supports_full_text_search(): return self.filter( models.Q(title__search = search_query) \ | models.Q(text__search = search_query) \ | models.Q(tagnames__search = search_query) \ | models.Q(answers__text__search = search_query) ) elif 'postgresql_psycopg2' in askbot.get_database_engine_name(): rank_clause = "ts_rank(question.text_search_vector, to_tsquery(%s))"; search_query = '&'.join(search_query.split()) extra_params = (search_query,) extra_kwargs = { 'select': {'relevance': rank_clause}, 'where': ['text_search_vector @@ to_tsquery(%s)'], 'params': extra_params, 'select_params': extra_params, } return self.extra(**extra_kwargs) else: #fallback to dumb title match search return self.extra( where=['title like %s'], params=['%' + search_query + '%'] )
def get_by_text_query(self, search_query): """returns a query set of questions, matching the full text query """ # todo - goes to thread - we search whole threads 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 Question.objects.filter(deleted=False, id__in=question_ids) if settings.DATABASE_ENGINE == "mysql" and mysql.supports_full_text_search(): return self.filter( models.Q(title__search=search_query) | models.Q(text__search=search_query) | models.Q(tagnames__search=search_query) | models.Q(answers__text__search=search_query) ) elif "postgresql_psycopg2" in askbot.get_database_engine_name(): 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.extra(where=["title like %s"], params=["%" + search_query + "%"])
def get_by_text_query(self, search_query): """returns a query set of questions, matching the full text query """ if settings.DATABASE_ENGINE == 'mysql' and mysql.supports_full_text_search(): return self.filter( models.Q(title__search = search_query) \ | models.Q(text__search = search_query) \ | models.Q(tagnames__search = search_query) \ | models.Q(answers__text__search = search_query) ) elif 'postgresql_psycopg2' in askbot.get_database_engine_name(): rank_clause = "ts_rank(question.text_search_vector, to_tsquery(%s))"; search_query = '&'.join(search_query.split()) extra_params = ("'" + search_query + "'",) extra_kwargs = { 'select': {'relevance': rank_clause}, 'where': ['text_search_vector @@ to_tsquery(%s)'], 'params': extra_params, 'select_params': extra_params, } return self.extra(**extra_kwargs) else: #fallback to dumb title match search return self.extra( where=['title like %s'], params=['%' + 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 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 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(): from askbot.search import postgresql return postgresql.run_full_text_search(qs, search_query) else: 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) )
def get_by_text_query(self, search_query): """returns a query set of questions, matching the full text query """ if settings.DATABASE_ENGINE == "mysql" and mysql.supports_full_text_search(): return self.filter( models.Q(title__search=search_query) | models.Q(text__search=search_query) | models.Q(tagnames__search=search_query) | models.Q(answers__text__search=search_query) ) elif "postgresql_psycopg2" in askbot.get_database_engine_name(): rank_clause = "ts_rank(question.text_search_vector, to_tsquery(%s))" search_query = "&".join(search_query.split()) extra_params = ("'" + search_query + "'",) extra_kwargs = { "select": {"relevance": rank_clause}, "where": ["text_search_vector @@ to_tsquery(%s)"], "params": extra_params, "select_params": extra_params, } return self.extra(**extra_kwargs) else: # fallback to dumb title match search return self.extra(where=["title like %s"], params=["%" + 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 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 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(): rank_clause = "ts_rank(askbot_thread.text_search_vector, plainto_tsquery(%s))" search_query = '&'.join(search_query.split()) extra_params = (search_query, ) extra_kwargs = { 'select': { 'relevance': rank_clause }, 'where': ['askbot_thread.text_search_vector @@ plainto_tsquery(%s)'], 'params': extra_params, 'select_params': extra_params, } return qs.extra(**extra_kwargs) else: 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))