As of 26/02/20, here's how I install & configure a search box on a djangocms (& djangocms-blog) project using solr:
-
Make sure to have a fully functional django + djangocms + djangocms-blog project (see djangocms-blog installer).
-
Install django-haystack & aldryn-search
-
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
-
Add this to INSTALLED_APPS (in
mydumbproject/settings.py
) (see doc):'haystack', 'aldryn_common', 'aldryn_search', 'standard_form', 'spurl',
-
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' }, }
-
-
Install solr
-
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 withsudo update-alternatives --config java
. -
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
-
Run
pipenv install pysolr
-
Follow the instructions here (kinda unclear sometimes)
OR
Follow these 3 steps:-
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
toschema.xml
) -
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 atemplates/search_configuration
folder.mkdir templates mkdir templates/search_configuration cp ../solr/server/solr/tester/conf/schema.xml templates/search_configuration/solr.xml
-
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).
-
-
-
Create a new, empty page on your website (screenshot)
-
Go on page, then click on advanced settings (screenshot)
-
Select aldryn search in Application list (screenshot)
-
You now should have a working basic search input on your page (screenshot)
Features
- OR statement (using
|
) - screenshot - coming soon
-
Optional - Ignore accents in search
-
Optional - Enable fuzzy search