2

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

4

2 回答 2

2
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
于 2020-05-21T16:30:36.663 回答
2

CentOS 8、Solr 8.7、Django Oscar 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

4) 防火墙

关闭 iptables 或 firewalld 中的 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 中的 Haystack 设置

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

重启supervisord:

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)重启solr:

systemctl restart solr

11 ) 重建索引

python manage.py rebuild_index --noinput
于 2021-01-25T05:44:05.300 回答