Solr search engine and Ibexa

I’m coming back to you with another article on the Ibexa series. We will see how to configure and set up a content indexing system

The entry point is here :

We will use Docker to set up SOLR. I’m sharing our docker-compose.yaml file here, which has changed since the last article.

version: '3'

services:
  database:
    container_name: bdd_ibexa_oss
    image: 'mysql:5.7'
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: main
    ports:
      - '3306'
  mailer:
    container_name: mailer_ibexa_oss
    image: schickling/mailcatcher
    ports: [1025, 1080]
  redis:
    image: 'redis:latest'
    container_name: redis_ibexa_oss
    ports:
      - 6379:6379
  phpmyadmin:
      image: phpmyadmin
      container_name: phpmyadmin_ibexa_oss
      restart: always
      depends_on:
        - database
      ports:
        - 8282:80
      environment:
        PMA_HOST: database #to have the same value as service BDD
  solr:
      image: 'solr:7.7'
      container_name: solr_ibexa_oss
      volumes:
        - './provisionning/solr/entrypoint.bash:/entrypoint.bash:ro'
        - './provisionning/solr/model/custom-fields-types.xml:/opt/solr/vendor/custom-fields-types.xml'
        - './provisionning/solr/model/language-fieldtypes.xml:/opt/solr/vendor/language-fieldtypes.xml'
        - './provisionning/solr/model/schema.xml:/opt/solr/vendor/schema.xml'
      ports:
        - '8983:8983'
      entrypoint: /entrypoint.bash
      environment:
        - DEV_UID
        - DEV_GID
        - SOLR_CORES=collection1

So, we have added the services redis/phpmyadmin and solr. We will write more articles on Docker in the future…

The files in the ‘model’ folder are located in the following path :

  • oss-skeleton/vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/

For Solr, the important parts are the configuration entrypoint and volumes. I’m providing you with the code from the bash entrypoint.bash :

In your .env or .env.local file, you need to provide the correct value for legacy (no indexing engine), elasticsearch, or solr

SEARCH_ENGINE=solr
SOLR_DSN=http://localhost:8983/solr
SOLR_CORE=collection1

Ibexa provides a default file: ezplatform_solr.yaml

# Base configuration for Solr, for more options see: https://doc.ezplatform.com/en/latest/guide/search/#solr-bundle
# Can have several connections used by each eZ Repositories in ezplatform.yml
parameters:
    # Solr root endpoint, relevant if `solr` is set as search_engine
    solr_dsn: '%env(SOLR_DSN)%'
    solr_core: '%env(SOLR_CORE)%'

ez_search_engine_solr:
    endpoints:
        ibexa_oss:
            dsn: '%solr_dsn%'
            core: '%solr_core%'
    connections:
        default:
            entry_endpoints:
                - ibexa_oss
            mapping:
                default: ibexa_oss

I changed the endpoint name to ibexa_oss.

Don’t forget to run ‘docker-compose up -d’ once everything is OK. You can then access this interface, which is very useful.

  • I changed the endpoint name to ibexa_oss.
  • Don’t forget to run ‘docker-compose up -d’ once everything is OK. You can then access this interface, which is very useful.

All that’s left is to create content from your back office.

You can also run the content indexing command from your terminal :

  • php bin/console ibexa:reindex

More details in the following link: https://doc.ibexa.co/en/3.3/guide/search/solr/

I didn’t struggle too much to explain the situation. The counselor facilitated the exchange

#!/usr/bin/env bash

# Check if missing template folder
DESTINATION_EZ="/opt/solr/ezsolr/server/ez"
DESTINATION_VENDOR="/opt/solr/vendor"
DESTINATION_TEMPLATE="${DESTINATION_EZ}/template"
if [ ! -d ${DESTINATION_TEMPLATE} ]; then
    cd $PROJECTMAPPINGFOLDER/ezplatform
    mkdir -p ${DESTINATION_TEMPLATE}
    cp -R /opt/solr/vendor/* ${DESTINATION_TEMPLATE}
fi

# Check for solr config folder (changes btw 6 and 7)
SOURCE_SOLR="/opt/solr/server/solr/configsets/_default/"
if [ ! -d ${SOURCE_SOLR} ]; then
    SOURCE_SOLR="/opt/solr/server/solr/configsets/basic_configs/"
fi

mkdir -p ${DESTINATION_EZ}
if [ ! -f ${DESTINATION_EZ}/solr.xml ]; then
    cp /opt/solr/server/solr/solr.xml ${DESTINATION_EZ}
    cp ${SOURCE_SOLR}/conf/{currency.xml,solrconfig.xml,stopwords.txt,synonyms.txt,elevate.xml} ${DESTINATION_TEMPLATE}
    sed -i.bak '/<updateRequestProcessorChain name="add-unknown-fields-to-the-schema".*/,/<\/updateRequestProcessorChain>/d' ${DESTINATION_TEMPLATE}/solrconfig.xml
    sed -i -e 's/<maxTime>${solr.autoSoftCommit.maxTime:-1}<\/maxTime>/<maxTime>${solr.autoSoftCommit.maxTime:20}<\/maxTime>/g' ${DESTINATION_TEMPLATE}/solrconfig.xml
    sed -i -e 's/<dataDir>${solr.data.dir:}<\/dataDir>/<dataDir>\/opt\/solr\/data\/${solr.core.name}<\/dataDir>/g' ${DESTINATION_TEMPLATE}/solrconfig.xml
fi

SOLR_CORES=${SOLR_CORES:-collection1}
CREATE_CORES=false

for core in $SOLR_CORES
do
    if [ ! -d ${DESTINATION_EZ}/${core} ]; then
        CREATE_CORES=true
        echo "Found missing core: ${core}"
    fi
done

if [ "$CREATE_CORES" = true ]; then
    touch ${DESTINATION_EZ}/solr.creating.cores
    echo "Start solr on background to create missing cores"
    /opt/solr/bin/solr -s ${DESTINATION_EZ}

    for core in $SOLR_CORES
    do
        if [ ! -d ${DESTINATION_EZ}/${core} ]; then
            /opt/solr/bin/solr create_core -c ${core}  -d ${DESTINATION_TEMPLATE}
            echo "Core ${core} created."
        fi
    done
    echo "Stop background solr"
    /opt/solr/bin/solr stop
    rm ${DESTINATION_EZ}/solr.creating.cores
fi

/opt/solr/bin/solr -s ${DESTINATION_EZ} -f