Skip to main content

An extension to django CMS to provide multilingual Haystack indexes

Project description

This package provides a search indexes for easy Haystack 2 integration with django CMS. The package is compatible with Aldryn.

Usage

After installing aldryn-search through your package manager of choice, add aldryn_search to your INSTALLED_APPS. If you run a multilingual CMS setup, you have to define a haystack backend for every language in use:

HAYSTACK_CONNECTIONS = {
    'en': {
        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
        'URL': 'http://my-solr-server/solr/my-site-en/',
        'TIMEOUT': 60 * 5,
        'INCLUDE_SPELLING': True,
        'BATCH_SIZE': 100,
    },
    'fr': {
        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
        'URL': 'http://my-solr-server/solr/my-site-fr/',
        'TIMEOUT': 60 * 5,
        'INCLUDE_SPELLING': True,
        'BATCH_SIZE': 100,
    },
}

To make sure the correct backend is used during search, add aldryn_search.router.LanguageRouter to your HAYSTACK_ROUTERS setting:

HAYSTACK_ROUTERS = ['aldryn_search.router.LanguageRouter',]

When using multiple languages, usually there’s one search backend per language, when indexing it’s important to know which language is currently being used, this can be facilitated by the ALDRYN_SEARCH_LANGUAGE_FROM_ALIAS setting, this setting could be a callable or a string path that resolves to one.

Please keep in mind that it’s usually not a good idea to import things in your settings, however there are cases where it seems overkill to create a function to handle the alias, for example:

ALDRYN_SEARCH_LANGUAGE_FROM_ALIAS = lambda alias: alias.split('-')[-1]

the example above could be used when using multiple languages and sites, all backends could have a language suffix.

The same could be achieved using a function defined somewhere else in your code like so:

ALDRYN_SEARCH_LANGUAGE_FROM_ALIAS = "my_app.helpers.language_from_alias"

If any of the above return None then settings.LANGUAGE_CODE will be used.

By default this setting evaluates to a function that checks if the alias is in settings.LANGUAGES and if so it uses the alias as a language.

For a complete Haystack setup, please refer to their documentation.

For more docs, see the docs folder or the online documentation.

Integration with django CMS

aldryn-search comes with an App Hook for django CMS, and a search view using Django’s class based views. If you want to use this app hook, you can either subclass it and register it yourself, or set ALDRYN_SEARCH_REGISTER_APPHOOK to True.

For pagination, aldryn-search uses aldryn_search.contrib.paginator.DiggPaginator. If you want to use this built-in pagination, make sure to install`django-spurl <https://github.com/j4mie/django-spurl>`_, and add then add spurl to INSTALLED_APPS.

Project details


Release history Release notifications

History Node

1.0.0

History Node

0.5.0

History Node

0.4.1

History Node

0.4.0

History Node

0.3.0

History Node

0.2.12

History Node

0.2.11

History Node

0.2.10

History Node

0.2.9

History Node

0.2.8

History Node

0.2.7

History Node

0.2.6

History Node

0.2.5

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

This version
History Node

0.1.9

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
aldryn-search-0.1.9.tar.gz (18.7 kB) Copy SHA256 hash SHA256 Source None May 26, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page