Exemple #1
0
    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)
            )
Exemple #2
0
    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 forwards(self, orm):
     "Write your forwards methods here."
     if 'postgresql_psycopg2' in askbot.get_database_engine_name():
         script_path = os.path.join(askbot.get_install_directory(),
                                    'search', 'postgresql',
                                    'question_answer_comment_models.plsql')
         setup_full_text_search(script_path)
Exemple #4
0
 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 + '%']
                 )
Exemple #5
0
 def get_by_text_query(self, search_query):
     """returns a query set of questions, 
     matching the full text query
     """
     if settings.DATABASE_ENGINE == 'mysql':
         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 askbot.get_database_engine_name() == 'postgresql_psycopg2':
         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 + '%']
                 )
Exemple #6
0
 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_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 + "%"])
Exemple #8
0
 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 + '%']
                 )
Exemple #9
0
 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 + '%'])
Exemple #10
0
 def setUp(self):
     self.old_cache = cache.cache
     # Disable caching (to not interfere with production cache,
     # not sure if that's possible but let's not risk it)
     cache.cache = DummyCache("", {})
     if "postgresql" in askbot.get_database_engine_name():
         management.call_command("init_postgresql_full_text_search", verbosity=0, interactive=False)
 def backwards(self, orm):
     db_engine_name = askbot.get_database_engine_name()
     if "mysql" in db_engine_name:
         db.execute("DROP INDEX deleted_posttype_threadid ON askbot_post")
         print "Dropped INDEX deleted_posttype_threadid ..."
     elif "sqlite" in db_engine_name:
         db.execute("DROP INDEX deleted_posttype_threadid")
         print "Dropped INDEX deleted_posttype_threadid ..."
 def forwards(self, orm):
     "Write your forwards methods here."
     db_engine_name = askbot.get_database_engine_name()
     if 'postgresql_psycopg2' in db_engine_name:
         script_path = os.path.join(askbot.get_install_directory(),
                                    'search', 'postgresql',
                                    'user_profile_search_16102012.plsql')
         postgresql.setup_full_text_search(script_path)
Exemple #13
0
 def forwards(self, orm):
     "Write your forwards methods here."
     db_engine_name = askbot.get_database_engine_name()
     if 'postgresql_psycopg2' in db_engine_name:
         script_path = os.path.join(
             askbot.get_install_directory(), 'search', 'postgresql',
             'thread_and_post_models_10032013.plsql')
         postgresql.setup_full_text_search(script_path)
Exemple #14
0
def should_show_sort_by_relevance():
    """True if configuration support sorting
    questions by search relevance
    """
    return (
        ('postgresql_psycopg2' in askbot.get_database_engine_name()) or
        django_settings.ENABLE_HAYSTACK_SEARCH
    )
Exemple #15
0
 def setUp(self):
     self.old_cache = cache.cache
     #Disable caching (to not interfere with production cache,
     #not sure if that's possible but let's not risk it)
     cache.cache = DummyCache('', {})
     if 'postgresql' in askbot.get_database_engine_name():
         management.call_command('init_postgresql_full_text_search',
                                 verbosity=0,
                                 interactive=False)
 def forwards(self, orm):
     "Write your forwards methods here."
     if 'postgresql_psycopg2' in askbot.get_database_engine_name():
         script_path = os.path.join(
                             askbot.get_install_directory(),
                             'search',
                             'postgresql',
                             'thread_and_post_models_01162012.plsql'
                         )
         setup_full_text_search(script_path)
 def forwards(self, orm):
     "Write your forwards methods here."
     if 'postgresql_psycopg2' in askbot.get_database_engine_name():
         script_path = os.path.join(
                             askbot.get_install_directory(),
                             'search',
                             'postgresql',
                             'exercise_problem_comment_models.plsql'
                         )
         setup_full_text_search(script_path)
 def forwards(self, orm):
     "Write your forwards methods here."
     db_engine_name = askbot.get_database_engine_name()
     if 'postgresql_psycopg2' in db_engine_name:
         script_path = os.path.join(
                             askbot.get_install_directory(),
                             'search',
                             'postgresql',
                             'user_profile_search_02262013.plsql'
                         )
         postgresql.setup_full_text_search(script_path)
def test_postgres():
    """Checks for the postgres buggy driver, version 2.4.2"""
    if 'postgresql_psycopg2' in askbot.get_database_engine_name():
        import psycopg2
        version = psycopg2.__version__.split(' ')[0].split('.')
        if version == ['2', '4', '2']:
            raise AskbotConfigError(
                'Please install psycopg2 version 2.4.1,\n version 2.4.2 has a bug')
        elif version > ['2', '4', '2']:
            pass  # don't know what to do
        else:
            pass  # everythin is ok
Exemple #20
0
def test_postgres():
    """Checks for the postgres buggy driver, version 2.4.2"""
    if 'postgresql_psycopg2' in askbot.get_database_engine_name():
        import psycopg2
        version = psycopg2.__version__.split(' ')[0].split('.')
        if version == ['2', '4', '2']:
            raise AskbotConfigError(
                'Please install psycopg2 version 2.4.1,\n version 2.4.2 has a bug')
        elif version > ['2', '4', '2']:
            pass  # don't know what to do
        else:
            pass  # everythin is ok
def test_postgres():
    """Checks for the postgres buggy driver, version 2.4.2"""
    if "postgresql_psycopg2" in askbot.get_database_engine_name():
        import psycopg2

        version = psycopg2.__version__.split(" ")[0].split(".")
        if version == ["2", "4", "2"]:
            raise AskbotConfigError("Please install psycopg2 version 2.4.1,\n version 2.4.2 has a bug")
        elif version > ["2", "4", "2"]:
            pass  # don't know what to do
        else:
            pass  # everythin is ok
Exemple #22
0
    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))
Exemple #23
0
    def forwards(self, orm):
        "Write your forwards methods here."
        profiles = orm['askbot.GroupProfile'].objects.all()
        items = profiles.iterator()
        count = profiles.count()
        message = 'Transfering group information from Tag to Group model'
        for profile in ProgressBar(items, count, message):
            group_tag = profile.group_tag
            group_name = group_tag.name.replace('-', ' ')
            group = orm['askbot.Group']()
            group.name = group_name
            group.logo_url = profile.logo_url
            group.moderate_email = profile.moderate_email
            group.is_open = profile.is_open
            group.preapproved_emails = profile.preapproved_emails
            group.preapproved_email_domains = profile.preapproved_email_domains

            try:
                #see if such group is already there
                auth_group = orm['auth.Group'].objects.get(name=group_name)
                group.group_ptr = auth_group
            except orm['auth.Group'].DoesNotExist:
                pass

            group.save()

            #update thread groups
            thread_groups = orm['askbot.ThreadToGroup'].objects
            thread_groups = thread_groups.filter(tag=group_tag)
            thread_groups.update(group=group)
            #update post groups
            post_groups = orm['askbot.PostToGroup'].objects
            post_groups = post_groups.filter(tag=group_tag)
            post_groups.update(group=group)
            #update user groups
            memberships = group_tag.user_memberships.all()
            for membership in memberships:
                membership.user.groups.add(group)

        db_engine_name = askbot.get_database_engine_name()
        if 'postgresql_psycopg2' in db_engine_name:
            from django.db import connection
            cursor = connection.cursor()
            cursor.execute(
                'DROP TRIGGER IF EXISTS group_membership_tsv_update_trigger '
                'ON askbot_groupmembership'
            )

        message = 'Deleting old group information'
        items = profiles.iterator()
        for profile in ProgressBar(items, count, message):
            group_tag = profile.group_tag
            group_tag.user_memberships.all().delete()
            profile.delete()

        #for postgresql setup new user full text search
        if 'postgresql_psycopg2' in db_engine_name:
            
            script_path = os.path.join(
                askbot.get_install_directory(),
                'search', 'postgresql', 
                'user_profile_search_08312012.plsql'
            )
            setup_full_text_search(script_path)
Exemple #24
0
def should_show_sort_by_relevance():
    """True if configuration support sorting
    questions by search relevance
    """
    return ('postgresql_psycopg2' in askbot.get_database_engine_name())
 def forwards(self, orm):
     db_engine_name = askbot.get_database_engine_name()
     if "mysql" in db_engine_name or "sqlite" in db_engine_name:
         db.execute("CREATE INDEX deleted_posttype_threadid ON askbot_post (deleted, post_type, thread_id);")
         print "Created an INDEX deleted_posttype_threadid ..."
    def forwards(self, orm):
        "Write your forwards methods here."
        profiles = orm['askbot.GroupProfile'].objects.all()
        items = profiles.iterator()
        count = profiles.count()
        message = 'Transfering group information from Tag to Group model'
        for profile in ProgressBar(items, count, message):
            group_tag = profile.group_tag
            group_name = group_tag.name.replace('-', ' ')
            group = orm['askbot.Group']()
            group.name = group_name
            group.logo_url = profile.logo_url
            group.moderate_email = profile.moderate_email
            group.is_open = profile.is_open
            group.preapproved_emails = profile.preapproved_emails
            group.preapproved_email_domains = profile.preapproved_email_domains

            try:
                #see if such group is already there
                auth_group = orm['auth.Group'].objects.get(name=group_name)
                group.group_ptr = auth_group
            except orm['auth.Group'].DoesNotExist:
                pass

            group.save()

            #update thread groups
            thread_groups = orm['askbot.ThreadToGroup'].objects
            thread_groups = thread_groups.filter(tag=group_tag)
            thread_groups.update(group=group)
            #update post groups
            post_groups = orm['askbot.PostToGroup'].objects
            post_groups = post_groups.filter(tag=group_tag)
            post_groups.update(group=group)
            #update user groups
            memberships = group_tag.user_memberships.all()
            for membership in memberships:
                membership.user.groups.add(group)

        db_engine_name = askbot.get_database_engine_name()
        if 'postgresql_psycopg2' in db_engine_name:
            from django.db import connection
            cursor = connection.cursor()
            cursor.execute(
                'DROP TRIGGER IF EXISTS group_membership_tsv_update_trigger '
                'ON askbot_groupmembership'
            )

        message = 'Deleting old group information'
        items = profiles.iterator()
        for profile in ProgressBar(items, count, message):
            group_tag = profile.group_tag
            group_tag.user_memberships.all().delete()
            profile.delete()

        #for postgresql setup new user full text search
        if 'postgresql_psycopg2' in db_engine_name:
            
            script_path = os.path.join(
                askbot.get_install_directory(),
                'search', 'postgresql', 
                'user_profile_search_08312012.plsql'
            )
            setup_full_text_search(script_path)
 def forwards(self, orm):
     "Write your forwards methods here."
     if 'postgresql_psycopg2' in askbot.get_database_engine_name():
         management.call_command('init_postgresql_full_text_search')
def should_show_sort_by_relevance():
    """True if configuration support sorting
    questions by search relevance
    """
    return ('postgresql_psycopg2' in askbot.get_database_engine_name())