You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

how_to_setup_solr.rst 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. .. spelling::
  2. Solr
  3. ============================
  4. How to setup Solr with Oscar
  5. ============================
  6. `Apache Solr`_ is Oscar's recommended production-grade search backend. This
  7. how-to describes how to get Solr running, and integrated with Oscar. The
  8. instructions below are tested on an Debian/Ubuntu machine, but should be applicable
  9. for similar environments. A working Java or OpenJDK version 8 installation are
  10. necessary.
  11. .. _`Apache Solr`: https://lucene.apache.org/solr/
  12. Python Package
  13. ==============
  14. You will need to install the ``pysolr`` Python package. Or add it to your
  15. `requirements.txt`:
  16. .. code-block:: bash
  17. $ pip install pysolr
  18. Installing Solr
  19. ===============
  20. You first need to fetch and extract Solr. The schema included with Oscar
  21. is tested with Solr 6.6.6:
  22. .. code-block:: bash
  23. $ wget -O ${HOME}/solr-6.6.6.tgz https://archive.apache.org/dist/lucene/solr/6.6.6/solr-6.6.6.tgz
  24. $ tar xzf ${HOME}/solr-6.6.6.tgz --directory=${HOME}
  25. $ ln -s ${HOME}/solr-6.6.6 ${HOME}/solr
  26. .. note::
  27. For development this will presume the solr directory is in
  28. the users ``HOME`` directory. (For an actual deployment this may be better
  29. placed in ``/opt``).
  30. Start Solr and Create a Core
  31. ======================================
  32. Next start up Solr and create a core named ``sandbox`` this name will be used
  33. through out this howto, change ``sandbox`` to something that suits your installation.
  34. This step also sets up up the directory structure and a basic configuration.
  35. .. code-block:: bash
  36. $ cd ${HOME}/solr
  37. $ ./bin/solr start
  38. $ ./bin/solr create -c sandbox -n basic_config
  39. Integrating with Haystack
  40. =========================
  41. Haystack provides an abstraction layer on top of different search backends and
  42. integrates with Django. The Haystack connection settings in your
  43. ``settings.py`` for the config above will look like this:
  44. .. code-block:: python
  45. # Solr 6.x
  46. HAYSTACK_CONNECTIONS = {
  47. 'default': {
  48. 'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
  49. 'URL': 'http://127.0.0.1:8983/solr/sandbox',
  50. 'ADMIN_URL': 'http://127.0.0.1:8983/solr/admin/cores',
  51. 'INCLUDE_SPELLING': True,
  52. },
  53. }
  54. To use Solr with the Sandbox locally comment out the ``HAYSTACK_CONNECTIONS``
  55. section using the WhooshEngine and uncomment the Solr 6.x section like this one.
  56. Build Solr schema
  57. =================
  58. Next, get Oscar to generate the ``schema.xml`` and ``solrconfig.xml`` for Solr.
  59. .. code-block:: bash
  60. $ ./manage.py build_solr_schema --configure-directory=${HOME}/solr/server/solr/sandbox/conf
  61. $ ./manage.py build_solr_schema --reload-core sandbox
  62. .. note::
  63. If using this Solr install with the Sandbox locally ensure the steps up to
  64. this point have been done prior to running ``make sandbox`` in the
  65. `Run the sandbox locally <https://django-oscar.readthedocs.io/en/latest/internals/sandbox.html#run-the-sandbox-locally>`_
  66. instructions.
  67. Rebuild search index
  68. ====================
  69. If all is well, you should now be able to rebuild the search index.
  70. .. code-block:: bash
  71. $ ./manage.py rebuild_index --noinput
  72. Removing all documents from your index because you said so.
  73. All documents removed.
  74. Indexing 201 Products
  75. If the indexing succeeded, search in Oscar will be working. Search for any term
  76. in the search box on your Oscar site, and you should get results.