How to install Search API with solr 6.x as backend in Drupal 8

First of all we have to install the solr service in Ubuntu


sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

(This command may take a while. Accept the licence agreement also)
sudo apt-get install oracle-java8-installer


cd ~
wget http://archive.apache.org/dist/lucene/solr/6.0.0/solr-6.0.0.tgz
tar xzf solr-6.0.0.tgz solr-6.0.0/bin/install_solr_service.sh --strip-components=2
sudo bash ./install_solr_service.sh solr-6.0.0.tgz

check if the server is running:

sudo service solr status

To install Search API and Solr Search run these commands in the Drupal root folder (recommended method).
First add the Drupal 8 Composer repository:


composer config repositories.drupal composer https://packages.drupal.org/8

Download the module Search API

composer require drupal/search_api

Download the module Search API Solr

composer require drupal/search_api_solr

Enable modules and clear cache

drush en -y search_api_solr
drush cache-rebuild

Verify Solarium Client has been added to vendor folder.

Next we have to create the solr collection where indexed data will be stored. There is a config folder for each version of solr inside Search API Solr module. Copy the config module apt for your setup and move it to config folder of solr collection folder.

Solr will be installed /opt/solr-6.0.0 and a symbolic link with solr will be created to link with it.
solr symbolic link will have user and group as solr. Configuration and collection will be at /var/solr with user and group as solr. Therefore when you cd to it even if we use sudo will be permission denied.

We have to use the format below to execute as solr user:

sudo su - solr -c "command to execute"

Now we will create a testdata collection and also copy the config from Search API solr module to here.


sudo su - solr -c "/opt/solr/bin/solr create -c testdata -n data_driven_schema_configs"
sudo su - solr -c "mkdir /var/solr/data/testdata/conf"
sudo su - solr -c "cp ~/drupalroot/modules/contrib/search_api_solr/solr-conf/6.x/* /var/solr/data/testdata/conf"

Go to Configurate->Search API->Add Server and give a name and click on Solr and you will get the screen as below. (otherwise there is someerror in your installation of search api and search api solr module using composer)
Add search server   BTX XO

Add testdata as core and you click save and you should have everything working. Then you have to add an index and set the just created solr server as backend. After that click the fields tab and add the fields required and Processor tab to add processors.Then click Edit tab to index the data to server.

There you have the Solr backend.

Now create a Search View page with the just created Index(Here Default Solr index) as shown below in picture.

Screenshot from 2016-08-03 11:15:57

Select Unformatted List of Rendered Entity and then you can style it as and how you like it.

Thats it, Cheers, you have done it!!

Advertisements

2 thoughts on “How to install Search API with solr 6.x as backend in Drupal 8

  1. Hello,

    Nice tuto and short :-).

    In this step,
    > sudo su – solr -c “/opt/solr/bin/solr create -c testdata -n data_driven_schema_configs”

    i have th following error in my command line
    “Failed to determine the port of a local Solr instance, cannot create testdata”

    Thank’s a lot !

    1. Have you checked if local solr service is running – sudo service solr status …also check in the browser if you can get the solr gui…normally it is in port 8983. http://localhost:8983/solr/#/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s