Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django-Haystack and Solr 8.5.1

Does Django haystack work with the latest Solr update (8.5.1)? Plus how do I setup with my Django blog project

like image 831
Charles Avatar asked Sep 16 '25 05:09

Charles


2 Answers

CentOS 8, Solr 8.7, Django Oscar 3.0

1 ) Install Java

yum update
yum install java-1.8.0-openjdk lsof

2 ) Install Solr

cd /tmp
wget https://downloads.apache.org/lucene/solr/8.7.0/solr-8.7.0.tgz
tar xzf solr-8.7.0.tgz solr-8.7.0/bin/install_solr_service.sh --strip-components=2
./install_solr_service.sh solr-8.7.0.tgz

systemctl enable solr
systemctl start solr

3 ) Limits

Tune your linux limits for solr user. You can do it here /etc/security/limits.conf. Add rows at the end of the file:

solr        soft    nofile      65535
solr        hard    nofile      65535

Or here /etc/systemd/system.conf set the vars:

DefaultLimitNOFILE=65000
DefaultLimitNPROC=65000

4 ) Firewall

Close the port 8983 in your iptables or firewalld

5 ) Reboot

reboot

6 ) Creating solr config files

cd /opt/solr-8.7.0/
sudo -i -u solr /opt/solr-8.7.0/bin/solr create -c haystack

Configuration files directory will be created here: /var/solr/data/haystack/

systemctl restart solr

7 ) Haystack settings in settings.py

INSTALLED_APPS = [
    "django.contrib.admin",
    ...
    "haystack",
]

HAYSTACK_CONNECTIONS = {
    "default": {
        "ENGINE": "haystack.backends.solr_backend.SolrEngine",
        "URL": "http://127.0.0.1:8983/solr/haystack",
        "INCLUDE_SPELLING": True,
    },
}

Restart supervisord:

systemctl restart supervisord

8 ) Switch to virtualenv

source path_to_your_venv_activate_script # (example: source /tmp/venv/django/bin/activate)
cd path_to_your_manage_py_location_directory

9 ) Create schema

cp -p /var/solr/data/haystack/conf/managed-schema /var/solr/data/haystack/conf/managed-schema.copy
python manage.py build_solr_schema > /var/solr/data/haystack/conf/managed-schema

In the file /var/solr/data/haystack/conf/managed-schema replace

<field name="django_ct" type="string" indexed="true" stored="true" multiValued="false"/>

with

<!-- <field name="django_ct" type="string" indexed="true" stored="true" multiValued="false"/> -->
<field name="django_ct" type="text_general" indexed="true" stored="true" multiValued="false"/>

In the file /var/solr/data/haystack/conf/managed-schema find last </fieldType> and add after it

<!-- NRR manual insert start -->
<!-- Lines from origin managed-schema: -->
<fieldType name="pdate" class="solr.DatePointField" docValues="true"/>
<fieldType name="pdates" class="solr.DatePointField" docValues="true" multiValued="true"/>
<fieldType name="pdouble" class="solr.DoublePointField" docValues="true"/>
<fieldType name="pdoubles" class="solr.DoublePointField" docValues="true" multiValued="true"/>
<fieldType name="pfloat" class="solr.FloatPointField" docValues="true"/>
<fieldType name="pfloats" class="solr.FloatPointField" docValues="true" multiValued="true"/>
<fieldType name="pint" class="solr.IntPointField" docValues="true"/>
<fieldType name="pints" class="solr.IntPointField" docValues="true" multiValued="true"/>
<fieldType name="plong" class="solr.LongPointField" docValues="true"/>
<fieldType name="plongs" class="solr.LongPointField" docValues="true" multiValued="true"/>
<!-- NRR manual insert end -->

Copy currency.xml to your working dir:

cp -p /opt/solr-8.7.0/example/example-DIH/solr/solr/conf/currency.xml /var/solr/data/haystack/conf/

chown solr:solr /var/solr/data/haystack/conf/currency.xml

10 ) Restart solr:

systemctl restart solr

11 ) Rebuild index

python manage.py rebuild_index --noinput
like image 65
Rufat Avatar answered Sep 17 '25 18:09

Rufat


Step 1:- Install Package

pip install pysolr
pip install django-haystack

Step 2:- Changes in settings.py for configuration


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    '...',
    'haystack',
]

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
        'URL': 'http://127.0.0.1:8983/solr/blog',
    },
}

HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'

step 3:-Install Apache Solr

apt-get install solr-tomcat

# Update Tomcat's configuration to set the servlet connector port to a sensible value:

vim /etc/tomcat7/server.xml

# Change the value of the Catalina service's Connector port to 8983 (at the time of writing, it defaults to 8080). Restart tomcat.
service tomcat6 restart



Step 4:- Build and install the solr schema

python manage.py build_solr_schema > schema.xml
sudo cp schema.xml /usr/share/solr/conf/schema.xml
sudo systemctl restart tomcat7


step 5:- Build the index for the first time:

python manage.py rebuild_index


Step 6: Update Data in Solr

# Update Solr Index

# Changes to the Database Aren't Reflected in Search Results

python manage.py update_index

# This command updates the Solr index with any changes which are not currently reflected.


# When the Solr Schema Definition has been Changed

python manage.py rebuild_index
like image 31
Mukul Kumar Avatar answered Sep 17 '25 20:09

Mukul Kumar