Django -干草堆和太阳8.5.1

t1qtbnec  于 2023-01-14  发布在  Go
关注(0)|答案(2)|浏览(71)

Djangohaystack可以在最新的Solr更新(8.5.1)中使用吗?另外我如何设置我的Djangoblog项目

5jdjgkvh

5jdjgkvh1#

CentOS 8,太阳能8.7,Django奥斯卡3.0
1)安装Java

yum update
yum install java-1.8.0-openjdk lsof

2)安装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)限制
调整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/数据/干草堆/

systemctl restart solr

7)www.example.com中的干草堆设置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,
    },
}

重新启动受监控d:

systemctl restart supervisord

8)切换到virtualenv

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)重启电磁阀:

systemctl restart solr

11)重建索引

python manage.py rebuild_index --noinput
mzsu5hc0

mzsu5hc02#

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

相关问题