Craft Solr Integration
Forked from https://github.com/dionsnoeijen/dssolr
This plugin requires Craft CMS 3.0.0-beta.23 or later.
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require onedesign/one-solr
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for One Solr.
- In
app/config
create aone-solr.php
file with the following configs
return [
'credentials' => [
'host' => getenv('SOLR_HOST'),
'port' => getenv('SOLR_PORT'),
'path' => getenv('SOLR_PATH'),
'core' => getenv('SOLR_CORE')
],
'stepSize' => 10,
'sectionIdField' => 'section_id_i',
];
Set your environment vars as normal, you'll probably need to use /
for SOLR_PATH
- Create a
onesolr
directory intemplates
For each section Solr map you want to generate, create a .json
file and place in templates/onesolr
. It will need to accept sectionId
, entryId
, limit
, and offset
. It should look something like this:
{% if sectionId is defined %}
{% set entries = craft.entries.sectionId(sectionId).status('enabled').limit(limit).offset(offset).all() %}
{% else %}
{% set entries = craft.entries({id: entryId}).all() %}
{% endif %}
[
{% for entry in entries %}
{
"id": "{{ entry.id }}",
"section_id_i": {{ entry.sectionId | raw }},
"entry_id_i": {{ entry.id }},
"article_type_i": 4,
"title": {{ entry.title | json_encode() | raw }}
}
{% if loop.index != entries|length %},{% endif %}
{% endfor %}
]
Some things to do, and ideas for potential features:
- Refactor the JSON files to just use a config of entry variables to store
- Refactor js
- Use jobs to update entries instead of relying on JS sending multiple batches
- Release it
Brought to you by Michael Ramuta