Created
August 18, 2012 12:59
-
-
Save zyegfryed/3386677 to your computer and use it in GitHub Desktop.
Configurable SearchIndex for Haystack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.core.exceptions import ImproperlyConfigured | |
# Python 2.7 has an importlib with import_module; for older Pythons, | |
# Django's bundled copy provides it. | |
try: # pragma: no cover | |
from importlib import import_module # pragma: no cover | |
except ImportError: # pragma: no cover | |
from django.utils.importlib import import_module # pragma: no cover | |
assert hasattr(settings, 'HAYSTACK_SEARCH_INDEX'), "You should define an Haystach search index class in HAYSTACK_SEARCH_INDEX settings. Please edit your settings file accordingly" | |
try: | |
mod_name, klass_name = settings.HAYSTACK_SEARCH_INDEX.rsplit('.', 1) | |
mod = import_module(mod_name) | |
except ImportError, e: | |
raise ImproperlyConfigured('Error loading search index class %s: "%s"' | |
% (mod_name, e)) | |
try: | |
SearchIndex = getattr(mod, klass_name) | |
except AttributeError: | |
raise ImproperlyConfigured('Module "%s" does not define a search index ' | |
'class named "%s"' % (mod_name, klass_name)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HAYSTACK_SEARCH_INDEX = 'haystack.indexes.RealTimeSearchIndex' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HAYSTACK_SEARCH_INDEX = 'queued_search.indexes.QueuedSearchIndex' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment