首页 > 解决方案 > Django-Haystack 和 Solr 8.5.1

问题描述

Django haystack 是否适用于最新的 Solr 更新(8.5.1)?另外我如何设置我的 Django 博客项目

标签: djangosolrdjango-haystackpysolr

解决方案


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

推荐阅读