Skip to content

Instantly share code, notes, and snippets.

@zyegfryed
Created Aug 18, 2012
Embed
What would you like to do?
Configurable SearchIndex for Haystack
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))
HAYSTACK_SEARCH_INDEX = 'haystack.indexes.RealTimeSearchIndex'
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