Django-Haystack and Solr 8.5.1



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

CentOS 8, Solr 8.7, Django Oscar 3.0

1 ( 安装爪哇

yum update
yum install java-1.8.0-openjdk lsof

2 ( 安装溶胶

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 ( 限制

调整 solr 用户的 linux 限制。 你可以在这里做/etc/security/limits.conf. 在文件末尾添加行:

solr        soft    nofile      65535
solr        hard    nofile      65535

或者在这里/etc/systemd/system.conf 设置变量:

DefaultLimitNOFILE=65000
DefaultLimitNPROC=65000

4 ( 防火墙

关闭 iptables 或防火墙中的端口 8983

5 ( 重新启动

reboot

6 ( 创建 solr 配置文件

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

配置文件目录将在此处创建:/var/solr/data/haystack/

systemctl restart solr

7 ( 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,
},
}

重新启动受监督管理:

systemctl restart supervisord

8 ( 切换到虚拟环境

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

9 ( 创建架构

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

在文件中/var/solr/data/haystack/conf/managed-schema替换

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

<!-- <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"/>

在文件中/var/solr/data/haystack/conf/managed-schema找到最后一个</fieldType>并在其后添加

<!-- 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 -->

currency.xml复制到您的工作目录:

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 ( 重新启动 solr:

systemctl restart solr

11 ( 重建索引

python manage.py rebuild_index --noinput
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

最新更新