Exemple #1
0
 def patch_signal_processor(self):
     if haystack.signal_processor_path != self.base_signal_processor_path:
         haystack.signal_processor.teardown()
         haystack.signal_processor_path = self.base_signal_processor_path
         haystack.signal_processor_class = loading.import_class(
             haystack.signal_processor_path)
         haystack.signal_processor = haystack.signal_processor_class(
             haystack.connections, haystack.connection_router)
Exemple #2
0
    def ready(self):
        # Setup default logging.
        log = logging.getLogger('haystack')
        self.stream = logging.StreamHandler()
        self.stream.setLevel(logging.INFO)
        log.addHandler(self.stream)

        # Setup the signal processor.
        if not self.signal_processor:
            signal_processor_path = getattr(settings, 'HAYSTACK_SIGNAL_PROCESSOR', 'haystack.signals.BaseSignalProcessor')
            signal_processor_class = loading.import_class(signal_processor_path)
            self.signal_processor = signal_processor_class(connections, connection_router)
Exemple #3
0
    def ready(self):
        # Setup default logging.
        log = logging.getLogger('haystack')
        self.stream = logging.StreamHandler()
        self.stream.setLevel(logging.INFO)
        log.addHandler(self.stream)

        # Setup the signal processor.
        if not self.signal_processor:
            signal_processor_path = getattr(
                settings, 'HAYSTACK_SIGNAL_PROCESSOR',
                'haystack.signals.BaseSignalProcessor')
            signal_processor_class = loading.import_class(
                signal_processor_path)
            self.signal_processor = signal_processor_class(
                connections, connection_router)
    def handle(self, *args, **options):
        connection_options = settings.HAYSTACK_CONNECTIONS['default']

        index_name = connection_options['INDEX_NAME']
        new_alias = '%s_%s' % (index_name, datetime.now().isoformat().lower())
        connection_options['INDEX_NAME'] = new_alias

        BackendClass = loading.import_class(connection_options['ENGINE']).backend
        backend = BackendClass('default', **connection_options)
        backend.setup()

        index_write = '%s_write' % index_name

        aliases = backend.conn.aliases()
        actions = []
        for n, al in aliases.items():
            if index_write in al['aliases']:
                actions.append({'remove': {'index': n, 'alias': index_write}})

        actions.append({'add': {'index': new_alias, 'alias': index_write}})
        backend.conn.update_aliases({'actions': actions})
    def handle(self, *args, **options):
        connection_options = settings.HAYSTACK_CONNECTIONS['default']

        index_name = connection_options['INDEX_NAME']
        index_write = '%s_write' % index_name

        BackendClass = loading.import_class(connection_options['ENGINE']).backend
        backend = BackendClass('default', **connection_options)

        actions = []
        current_alias = None
        for n, al in backend.conn.aliases().items():
            if index_name in al['aliases']:
                actions.append( { 'remove': { 'index': n, 'alias': index_name } } )
            if index_write in al['aliases']:
                current_alias = n

        if not current_alias:
            raise Exception('There is no "%s" alias to use' % index_write)

        actions.append( { 'add': { 'index': current_alias, 'alias': index_name } } )
        backend.conn.update_aliases({ 'actions': actions })
    def handle(self, *args, **options):
        connection_options = settings.HAYSTACK_CONNECTIONS["default"]

        index_name = connection_options["INDEX_NAME"]
        index_write = "%s_write" % index_name

        BackendClass = loading.import_class(connection_options["ENGINE"]).backend
        backend = BackendClass("default", **connection_options)

        actions = []
        current_alias = None
        for n, al in backend.conn.aliases().items():
            if index_name in al["aliases"]:
                actions.append({"remove": {"index": n, "alias": index_name}})
            if index_write in al["aliases"]:
                current_alias = n

        if not current_alias:
            raise Exception('There is no "%s" alias to use' % index_write)

        actions.append({"add": {"index": current_alias, "alias": index_name}})
        backend.conn.update_aliases({"actions": actions})
Exemple #7
0
    def handle(self, *args, **options):
        connection_options = settings.HAYSTACK_CONNECTIONS['default']

        index_name = connection_options['INDEX_NAME']
        new_alias = '%s_%s' % (index_name, datetime.now().isoformat().lower())
        connection_options['INDEX_NAME'] = new_alias

        BackendClass = loading.import_class(
            connection_options['ENGINE']).backend
        backend = BackendClass('default', **connection_options)
        backend.setup()

        index_write = '%s_write' % index_name

        aliases = backend.conn.aliases()
        actions = []
        for n, al in aliases.items():
            if index_write in al['aliases']:
                actions.append({'remove': {'index': n, 'alias': index_write}})

        actions.append({'add': {'index': new_alias, 'alias': index_write}})
        backend.conn.update_aliases({'actions': actions})
Exemple #8
0
    def handle(self, *args, **options):
        connection_options = settings.HAYSTACK_CONNECTIONS['default']

        index_name = connection_options['INDEX_NAME']
        index_write = '%s_write' % index_name

        BackendClass = loading.import_class(
            connection_options['ENGINE']).backend
        backend = BackendClass('default', **connection_options)

        actions = []
        current_alias = None
        for n, al in backend.conn.aliases().items():
            if index_name in al['aliases']:
                actions.append({'remove': {'index': n, 'alias': index_name}})
            if index_write in al['aliases']:
                current_alias = n

        if not current_alias:
            raise Exception('There is no "%s" alias to use' % index_write)

        actions.append({'add': {'index': current_alias, 'alias': index_name}})
        backend.conn.update_aliases({'actions': actions})
Exemple #9
0
connections = loading.ConnectionHandler(settings.HAYSTACK_CONNECTIONS)

# Load the router(s).
connection_router = loading.ConnectionRouter()

if hasattr(settings, 'HAYSTACK_ROUTERS'):
    if not isinstance(settings.HAYSTACK_ROUTERS, (list, tuple)):
        raise ImproperlyConfigured(
            "The HAYSTACK_ROUTERS setting must be either a list or tuple.")

    connection_router = loading.ConnectionRouter(settings.HAYSTACK_ROUTERS)

# Setup the signal processor.
signal_processor_path = getattr(settings, 'HAYSTACK_SIGNAL_PROCESSOR',
                                'haystack.signals.BaseSignalProcessor')
signal_processor_class = loading.import_class(signal_processor_path)
signal_processor = signal_processor_class(connections, connection_router)


# Per-request, reset the ghetto query log.
# Probably not extraordinarily thread-safe but should only matter when
# DEBUG = True.
def reset_search_queries(**kwargs):
    for conn in connections.all():
        conn.reset_queries()


if settings.DEBUG:
    from django.core import signals as django_signals
    django_signals.request_started.connect(reset_search_queries)
Exemple #10
0
# Load the connections.
connections = loading.ConnectionHandler(settings.HAYSTACK_CONNECTIONS)

# Load the router(s).
connection_router = loading.ConnectionRouter()

if hasattr(settings, 'HAYSTACK_ROUTERS'):
    if not isinstance(settings.HAYSTACK_ROUTERS, (list, tuple)):
        raise ImproperlyConfigured("The HAYSTACK_ROUTERS setting must be either a list or tuple.")

    connection_router = loading.ConnectionRouter(settings.HAYSTACK_ROUTERS)

# Setup the signal processor.
signal_processor_path = getattr(settings, 'HAYSTACK_SIGNAL_PROCESSOR', 'haystack.signals.BaseSignalProcessor')
signal_processor_class = loading.import_class(signal_processor_path)
signal_processor = signal_processor_class(connections, connection_router)


# Per-request, reset the ghetto query log.
# Probably not extraordinarily thread-safe but should only matter when
# DEBUG = True.
def reset_search_queries(**kwargs):
    for conn in connections.all():
        conn.reset_queries()


if settings.DEBUG:
    from django.core import signals as django_signals
    django_signals.request_started.connect(reset_search_queries)
Exemple #11
0
# Load the connections.
connections = loading.ConnectionHandler(settings.HAYSTACK_CONNECTIONS)

# Load the router(s).
connection_router = loading.ConnectionRouter()

if hasattr(settings, 'HAYSTACK_ROUTERS'):
    if not isinstance(settings.HAYSTACK_ROUTERS, (list, tuple)):
        raise ImproperlyConfigured("The HAYSTACK_ROUTERS setting must be either a list or tuple.")

    connection_router = loading.ConnectionRouter(settings.HAYSTACK_ROUTERS)

# Setup the signal processor.
signal_processor_path = getattr(settings, 'HAYSTACK_SIGNAL_PROCESSOR', 'haystack.signals.BaseSignalProcessor')
signal_processor_class = loading.import_class(signal_processor_path)
signal_processor = signal_processor_class(connections, connection_router)

default_search_result_path = getattr(settings, 'HAYSTACK_DEFAULT_SEARCH_RESULT', 'haystack.models.SearchResult')
DEFAULT_SEARCH_RESULT = loading.import_class(default_search_result_path)

SPELLCHECK_MAX_COLLATIONS = getattr(settings, 'SPELLCHECK_MAX_COLLATIONS', 1)

# Per-request, reset the ghetto query log.
# Probably not extraordinarily thread-safe but should only matter when
# DEBUG = True.
def reset_search_queries(**kwargs):
    for conn in connections.all():
        conn.reset_queries()

 def get_analyzer_class(self, field_class):
     ret = getattr(settings, 'HAYSTACK_WHOOSH_ANALYZER_CLASS', StemmingAnalyzer)
     if isinstance(ret, six.string_types):
         ret = import_class(ret)
     return ret