How it works...

MultilingualWhooshEngine specifies two custom properties:

  • backend points to MultilingualWhooshSearchBackend, which ensures that, for each language, the items will be indexed for each language given in the LANGUAGES setting, and put under the associated Haystack index location defined in HAYSTACK_CONNECTIONS.
  • query references the MultilingualWhooshSearchQuery, whose responsibility is to ensure that, when searching for keywords, the Haystack connection specific to the current language will be used.

Each index has a field text field, where full-text from a specific language of a model will be stored. The model for the index is determined by the get_model() method, the index_queryset() method defines what QuerySet to index, and the content to search within is collected as a newline-separated string in the prepare_text() method.

For the template, we have incorporated a few elements of Bootstrap 3 using the out-of-the-box rendering capabilities for forms. This might be enhanced using an approach such as explained in either the Creating a form layout with custom templates recipe or the subsequent Creating a form layout with django-crispy-forms recipe from earlier in this chapter. The final search form in this case will look similar to the following:

The easiest way to update the search index regularly is to call the rebuild_index management command, perhaps by a cron job every night. To learn about it, check the Setting up cron jobs for regular tasks recipe in Chapter 11, Testing and Deployment.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.147.193