Django Oscar 4 requires us to configure a search engine. For this, we use Haystack.
Search engines allow us to index and search products efficiently, enabling things like ordering alphabetically, by price, or by date added etc.
| 🟢 Basic | Simple Engine | Just testing, very few products |
| 🟡 Intermediate | Whoosh | Up to ~5,000 products, no complex search features |
| 🟠 Advanced | Solr | Over 10,000 products, robust search capabilities |
| 🔴 Professional | Elasticsearch | Large catalogs, high performance, relevance-based search needs |
Solr
Solr implementation differs between development and production.
In this tutorial, we'll show how to run Solr locally and discuss the production setup only theoretically.
Besides your web server, Solr requires a dedicated server.
Django Server & Solr Server
Documentation:
https://www.java.com/en/download/manual.jsp
https://django-oscar.readthedocs.io/en/latest/howto/how_to_setup_solr.html
pip install pysolr==3.10.0
- Download Solr by accessing the following url:
https://archive.apache.org/dist/lucene/solr/6.6.6/solr-6.6.6.tgz
- Extrack the content
- In the Command Line go to: /solr-6.6.6/solr-6.6.6/bin
cd solr-6.6.6 cd solr-6.6.6 cd bin - Run:
solr start solr create -c sandbox -n basic_config -
HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', 'URL': 'http://127.0.0.1:8983/solr/sandbox', 'ADMIN_URL': 'http://127.0.0.1:8983/solr/admin/cores', 'INCLUDE_SPELLING': True, }, }Replace the HAYSTACK_CONNECTIONS
-
In your project directory run:
python manage.py build_solr_schema --configure C:/Users/jaimedcsilva/Desktop/solr-6.6.6/solr-6.6.6/server/solr/sandbox/conf python manage.py build_solr_schema --reload-core sandbox python manage.py rebuild_index --noinput
Access the Solr admin page at: http://localhost:8983/
Things to keep in mind when moving to production
- Solr requires a dedicated server
- Solr requires Java
- The Solr server should be restricted to communicate only to the Django server
- Only the admin should have access to http://localhost:8983/
- Consider server backups.
If you need to stop the Solr server:
solr stop -all
Tested with: Django==5.2 django-oscar==4 pysolr==3.10.0
09 Aug. 2024
|
Last Updated: 02 Dec. 2025
|
jaimedcsilva Related