Skip to content

Instantly share code, notes, and snippets.

@corentinbettiol
Last active February 26, 2020 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corentinbettiol/df92b76cb39089881dcb5aec47c67651 to your computer and use it in GitHub Desktop.
Save corentinbettiol/df92b76cb39089881dcb5aec47c67651 to your computer and use it in GitHub Desktop.

As of 26/02/20, here's how I install & configure a search box on a djangocms (& djangocms-blog) project using solr:

  1. Make sure to have a fully functional django + djangocms + djangocms-blog project (see djangocms-blog installer).

  2. Install django-haystack & aldryn-search

    1. Run:

      pipenv install git+https://github.com/django-haystack/django-haystack#egg=django-haystack
      

      Edit 26/02/2020: aldryn-search 1.1.0 is out and support django 2! Install it using official pypi package!

      pipenv install aldryn-search
      
    2. Add this to INSTALLED_APPS (in mydumbproject/settings.py) (see doc):

          'haystack',
          'aldryn_common',
          'aldryn_search',
          'standard_form',
          'spurl',
      
    3. Add this in mydumbproject/settings.py (see doc):

      HAYSTACK_CONNECTIONS = {
          'default': {
              'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
              'URL': 'http://127.0.0.1:8983/solr/tester',
              'ADMIN_URL': 'http://127.0.0.1:8983/solr/admin/cores'
          },
      }
      
  3. Install solr

    1. Install java 8 openjdk (sudo apt-get install openjdk-8-jre) since solr 6.6.6 won't run with java 11 openjdk. You can select the default java version with sudo update-alternatives --config java.

    2. Run (see doc):

      curl -LO https://archive.apache.org/dist/lucene/solr/6.6.6/solr-6.6.6.tgz
      mkdir solr
      tar -C solr -xf solr-6.6.6.tgz --strip-components=1
      cd solr
      ./bin/solr start
      ./bin/solr create -c tester -n basic_config
      
    3. Run pipenv install pysolr

    4. Follow the instructions here (kinda unclear sometimes)

      OR
      Follow these 3 steps:

      1. Run py manage.py build_solr_schema --configure-directory=../solr/server/solr/tester/conf/

        (haystack will replace new schemaless mode by old schema mode, ie will update ../solr/server/solr/tester/conf/solrconfig.xml with new values, and will rename managed-schema to schema.xml)

      2. Run these commands:

        We need the actual schema.xml file to be discovered by Haystack (we need to override default schema.xml). This can be done by copying the schema.xml inside a templates/search_configuration folder.

        mkdir templates
        mkdir templates/search_configuration
        cp ../solr/server/solr/tester/conf/schema.xml templates/search_configuration/solr.xml
        
      3. Run py manage.py rebuild_index

        This will require having at least one entry in the ALLOWED_HOSTS parameter (set it to "*" if you want).

  4. Create a new, empty page on your website (screenshot)

  5. Go on page, then click on advanced settings (screenshot)

  6. Select aldryn search in Application list (screenshot)

  7. You now should have a working basic search input on your page (screenshot)

  8. That's all folks!


Features


  1. Optional - Ignore accents in search

  2. Optional - Enable fuzzy search

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment