Search code examples
djangosearchdjango-templatessearch-enginedjango-haystack

Django search engine for tempates


I have a Django app that has an accompanying user guide. Page content for the user guide is stored in a directory of templates. Haystack seems to be the most popular Django search engine, but it is only recommended for use on model data and doesn't seem to provide template indexing.

What's the best method of indexing the Django template content for search? I could create a model which stores the rendered templates, and index that using Haystack. Is there any software out there that does this already? Or any alternative ways of doing this? Any solution needs should preferably include rendered content (i.e. can't just index the templates straight from disk). I also wish to avoid any external ad-supported search engines like Google Custom Search and Django integration is desirable.

Any suggestions would be much appreciated, thanks.


Solution

  • haystack_static_pages is made just for this purpose.

    The app is designed to crawl and index specified rendered pages on your own site. You configure the URLs or URL names and then use the management command to crawl your site.

    It's worth noting a few things about this up front. Haystack is pretty tightly coupled to the Django ORM, so what haystack_static_pages does is add a model for static content and then dump crawled content into the model as a precursor to indexing. It also appears to be designed around the 1.x version of Haystack.