diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-10-12 01:27:11 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-10-12 01:27:11 -0400 |
commit | cb358e33d98ab7d73165ed03428fc0e4cedec828 (patch) | |
tree | 5fd0ffa896775a77c8484576b8ec217704649329 | |
parent | ffcc088eeccfcfb534fa2854ce9ea8df36f6d12c (diff) | |
download | askbot-cb358e33d98ab7d73165ed03428fc0e4cedec828.tar.gz askbot-cb358e33d98ab7d73165ed03428fc0e4cedec828.tar.bz2 askbot-cb358e33d98ab7d73165ed03428fc0e4cedec828.zip |
merged the haystack support branch
-rw-r--r-- | askbot/doc/source/changelog.rst | 1 | ||||
-rw-r--r-- | askbot/doc/source/optional-modules.rst | 5 | ||||
-rw-r--r-- | askbot/models/__init__.py | 3 | ||||
-rw-r--r-- | askbot/models/question.py | 13 | ||||
-rw-r--r-- | askbot/startup_procedures.py | 19 | ||||
-rw-r--r-- | askbot/tests/haystack_search_tests.py | 2 | ||||
-rw-r--r-- | askbot/tests/page_load_tests.py | 4 |
7 files changed, 29 insertions, 18 deletions
diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index d77e11ab..a971d9d6 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -3,6 +3,7 @@ Changes in Askbot Development version ------------------- +* Added support of Haystack for search (Adolfo) * Added minimum reputation setting to accept any answer as correct (Evgeny) * Added "VIP" option to groups - if checked, all posts belong to the group and users of that group in the future will be able to moderate those posts. Moderation features for VIP group are in progress (Evgeny) * Added setting `NOTIFICATION_DELAY_TIME` to use with enabled celery daemon (Adolfo) diff --git a/askbot/doc/source/optional-modules.rst b/askbot/doc/source/optional-modules.rst index aab80bf4..995ed224 100644 --- a/askbot/doc/source/optional-modules.rst +++ b/askbot/doc/source/optional-modules.rst @@ -60,6 +60,11 @@ Haystack search Askbot supports `Haystack <http://haystacksearch.org/>`_, a modular search framework that supports popular search engine backends as Solr, Elasticsearch, Whoosh and Xapian. +.. note:: + Haystack support in Askbot is a new feature, + please give us your feedback at ``support@askbot.com`` + regarding the possible improvements. + To enable: * add 'haystack' to INSTALLED_APPS diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index ee8bbc47..e3afcbb9 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -93,7 +93,7 @@ def get_users_by_text_query(search_query, users_query_set = None): """Runs text search in user names and profile. For postgres, search also runs against user group names. """ - if django_settings.ENABLE_HAYSTACK_SEARCH: + if getattr(django_settings, 'ENABLE_HAYSTACK_SEARCH', False): from askbot.search.haystack import AskbotSearchQuerySet qs = AskbotSearchQuerySet().filter(content=search_query).models(User).get_django_queryset(User) return qs @@ -2894,7 +2894,6 @@ def format_instant_notification_email( only update_types in const.RESPONSE_ACTIVITY_TYPE_MAP_FOR_TEMPLATES are supported """ - site_url = askbot_settings.APP_URL origin_post = post.get_origin_post() #todo: create a better method to access "sub-urls" in user views diff --git a/askbot/models/question.py b/askbot/models/question.py index 7897250b..36a1725e 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -2,7 +2,7 @@ import datetime import operator import re -from django.conf import settings +from django.conf import settings as django_settings from django.db import models from django.contrib.auth.models import User from django.core import cache # import cache, not from cache import cache, to be able to monkey-patch cache.cache in test cases @@ -176,7 +176,7 @@ class ThreadManager(BaseQuerySetManager): """returns a query set of questions, matching the full text query """ - if settings.ENABLE_HAYSTACK_SEARCH: + if django_settings.ENABLE_HAYSTACK_SEARCH: from askbot.search.haystack import AskbotSearchQuerySet hs_qs = AskbotSearchQuerySet().filter(content=search_query) return hs_qs.get_django_queryset() @@ -303,7 +303,7 @@ class ThreadManager(BaseQuerySetManager): elif search_state.scope == 'favorite': favorite_filter = models.Q(favorited_by=request_user) - if 'followit' in settings.INSTALLED_APPS: + if 'followit' in django_settings.INSTALLED_APPS: followed_users = request_user.get_followed_users() favorite_filter |= models.Q(posts__post_type__in=('question', 'answer'), posts__author__in=followed_users) qs = qs.filter(favorite_filter) @@ -383,7 +383,10 @@ class ThreadManager(BaseQuerySetManager): orderby = QUESTION_ORDER_BY_MAP[search_state.sort] - if not (settings.ENABLE_HAYSTACK_SEARCH and orderby=='-relevance'): + if not ( + getattr(django_settings, 'ENABLE_HAYSTACK_SEARCH', False) \ + and orderby=='-relevance' + ): #FIXME: this does not produces the very same results as postgres. qs = qs.extra(order_by=[orderby]) @@ -882,7 +885,7 @@ class Thread(models.Model): { 'latest':'-added_at', 'oldest':'added_at', - 'votes':'-score' + 'votes':'-points' }[sort_method] ).values_list('id', flat=True) diff --git a/askbot/startup_procedures.py b/askbot/startup_procedures.py index 0a9e4e07..706e19ad 100644 --- a/askbot/startup_procedures.py +++ b/askbot/startup_procedures.py @@ -534,12 +534,16 @@ def test_avatar(): def test_haystack(): if 'haystack' in django_settings.INSTALLED_APPS: try_import('haystack', 'django-haystack', short_message = True) - if not hasattr(django_settings, 'HAYSTACK_SEARCH_ENGINE'): - message = 'Please add HAYSTACK_SEARCH_ENGINE = simple, for more info please checkout: http://django-haystack.readthedocs.org/en/v1.2.7/settings.html#haystack-search-engine' - raise AskbotConfigError(message) - if not hasattr(django_settings, 'HAYSTACK_SITECONF'): - message = 'Please add HAYSTACK_SITECONF = "askbot.search.haystack"' - raise AskbotConfigError(message) + if getattr(django_settings, 'ENABLE_HAYSTACK_SEARCH', False): + errors = list() + if not hasattr(django_settings, 'HAYSTACK_SEARCH_ENGINE'): + message = "Please HAYSTACK_SEARCH_ENGINE to an appropriate value, value 'simple' can be used for basic testing" + errors.append(message) + if not hasattr(django_settings, 'HAYSTACK_SITECONF'): + message = 'Please add HAYSTACK_SITECONF = "askbot.search.haystack"' + errors.append(message) + footer = 'Please refer to haystack documentation at http://django-haystack.readthedocs.org/en/v1.2.7/settings.html#haystack-search-engine' + print_errors(errors, footer=footer) def test_custom_user_profile_tab(): setting_name = 'ASKBOT_CUSTOM_USER_PROFILE_TAB' @@ -732,9 +736,6 @@ def run_startup_tests(): 'value': True, 'message': 'Please add: RECAPTCHA_USE_SSL = True' }, - 'ENABLE_HAYSTACK_SEARCH': { - 'message': 'Please add: ENABLE_HAYSTACK_SEARCH = False or True according to your setup' - }, 'HAYSTACK_SITECONF': { 'value': 'askbot.search.haystack', 'message': 'Please add: HAYSTACK_SITECONF = "askbot.search.haystack"' diff --git a/askbot/tests/haystack_search_tests.py b/askbot/tests/haystack_search_tests.py index d1592f42..7a8bfcfd 100644 --- a/askbot/tests/haystack_search_tests.py +++ b/askbot/tests/haystack_search_tests.py @@ -11,7 +11,7 @@ class HaystackSearchTests(AskbotTestCase): that were added for askbot """ def setUp(self): - self._old_value = settings.ENABLE_HAYSTACK_SEARCH + self._old_value = getattr(settings, 'ENABLE_HAYSTACK_SEARCH', False) setattr(settings, "ENABLE_HAYSTACK_SEARCH", True) self.user = self.create_user(username='gepeto') diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py index 3805d012..4efac0f0 100644 --- a/askbot/tests/page_load_tests.py +++ b/askbot/tests/page_load_tests.py @@ -166,13 +166,15 @@ class PageLoadTestCase(AskbotTestCase): group.save() user = self.create_user('user') user.join_group(group) - self.post_question(user=user, title='alibaba', group_id=group.id) + question = self.post_question(user=user, title='alibaba', group_id=group.id) + #ask for data anonymously - should get nothing query_data = {'query': 'alibaba'} response = self.client.get(reverse('api_get_questions'), query_data) response_data = simplejson.loads(response.content) self.assertEqual(len(response_data), 0) + #log in - should get the question self.client.login(method='force', user_id=user.id) response = self.client.get(reverse('api_get_questions'), query_data) response_data = simplejson.loads(response.content) |