Skip to main content

Solr Search

Submitted by rnsrk on

Prerequisites

  • A Solr server is up and running with a dummy-core ... is the initial core in order to download the Solr server config from your Drupal instance, i. e. gettingstarted. .
  • You have to use composer to manage the dependencies of the module Solr Search, so if you haven't a installed version >=2, please follow the instructions for your OS on the composer site.

Additional Information

Drupal-Solr supports of functions and processors. For further reference visit the howto pages.

Installation

Solr Search Api

Open a terminal, change to your root-dir ...is the directory, where your Drupal website files and folders are stored (core, modules, sites, themes, .htaccess etc.), if you follow the recommended project structure it's the web folder of your project directory, i.e. /var/www/html/wisski.com/web, or C:/xampp/htdocs/wisski.com/web. and install Solr Search module with

composer require 'drupal/search_api_solr:^4.2'

Activate the module at Manage Extend by checking Search API, Search API Solr and Search API Solr Admin and click Install.

After installation you will see a warning "Search API: The default Drupal core Search module is still enabled..." if you disable the default search, WissKI's "Find"-link will disapear, you may not want this.

Replace ContentEntity.php

Since Search API assumes, that it operates on SQL tables, we have to alter some parts of the ContentEntity class at root-dir ...is the directory, where your Drupal website files and folders are stored (core, modules, sites, themes, .htaccess etc.), if you follow the recommended project structure it's the web folder of your project directory, i.e. /var/www/html/wisski.com/web, or C:/xampp/htdocs/wisski.com/web. \modules\contrib\search_api\Plugin\search_api\datasource\ContentEntity.php.

You can just replace the content with this code (please compare Search API versions).

Add Solr Server

Go to Manage Configuration Search API (Search and metadata). Click + Add server. Enter a name for your solr-server ... is your Solr server configuration, with an administrative name like WissKI Solr. , check Standard as Solr Connector (in Configure Solr backend section). Enter the name of your dummy-core ... is the initial core in order to download the Solr server config from your Drupal instance, i. e. gettingstarted. in the Solr core field (in section Configure standard Solr connector). Open the Advanced Section with a click and check Retrieve result data from Solr and Retrieve highlighted snippets, then click Save. You switch automatically to the View tab of your new created WissKI Solr API configuration.

Download Solr Config

Click + Get config.zip and download it to your preferred download-directory ... is the place, where you save your downloads, i. e. ~/Downloads in Linux/MacOS or the Downloads folder in Windows. , switch to the download directory and unzip the zip file.

Linux/ MacOS

unzip solr*.zip -d config

Windows

Right click on the zip file, click Extract All and rename the folder to config.

Create WissKI Solr core

Open a terminal in your download-directory ... is the place, where you save your downloads, i. e. ~/Downloads in Linux/MacOS or the Downloads folder in Windows. (Only for Linux/ MacOS users: switch to solr user by typing su solr) and create a wisski-solr-core ... is the Solr core with the specific configuration for your WissKI instance, with a machine name like wisski_solr. (the path to solr binaries in the solrdata-directory ... is the place where want to store the Solr data, i. e. ~/solrdata (on Linux/MaxOS) or C:\solrdata (on Windows). may vary), with your specific configuration files, i. e. by

/opt/solr/bin/solr create_core -c wisski_solr -d config -n wisski_solr

Switch to WissKI Core

At Manage Configuration Search API (Search and metadata section), click on Edit (Operations column), alter the Solr core field (Configure standard Solr Connector section) to your wisski-solr-core ... is the Solr core with the specific configuration for your WissKI instance, with a machine name like wisski_solr. and click Save.

At Manage Configuration Search API (Search and metadata section), click on your solr-server ... is your Solr server configuration, with an administrative name like WissKI Solr. . As Server Connection, you should see The Solr server could be reached.

Configuration

Add search index

At Manage Configuration Search API (Search and metadata section), click on + Add index. Enter a name for your solr-index ... where you configure the datasources, fields and processors of the things, you want to be searchable, has an administrative name like Specimen. and check Wisski Entity from Datasources. Check the radio button Only those selected and select the bundles, which should be indexed. As the Server, select your solr-server ... is your Solr server configuration, with an administrative name like WissKI Solr. from the list.

You may want to uncheck Index items immediately at Index options to keep Solr from constantly triggering new indexing operations. You have to start the indexing manually then!

Add Highlight processor

At Manage Configuration Search API (Search and metadata section), unfold the Operations for your solr-index ... where you configure the datasources, fields and processors of the things, you want to be searchable, has an administrative name like Specimen. by clicking on the caret and select Processors. Check Highlight in the Enabled section.  In the section Processor settings instantly arise a tab called Highlight, check Highlight partial matches and uncheck Create excerpt, delete the content of Highlighting prefix and Highlighting suffix field.

Example Screencast

Need help?

Write an email or join chat.wiss-ki.eu!