How to install Apache Solr for Magento store?

Do you know how many customers your Magento store is losing just because your visitors can’t find the products they need since the search system is imperfect? Huge stores with an extensive amount of products suffer from it dramatically. Learn how to help your customers to find what they need and boost your sales by installing Apache Solr.

When a customer doesn’t know the exact product name, search of the good he wants turns into a long adventure. Grouping by categories and Improved Sorting might make the situation a little bit better, but if one doesn’t know what category a product belongs to or how its name is spelled, the search result might be inappropriate.

To solve this problem Magento offers full-text search. Starting from version 1.8.0.0 Magento Enterprise supports not only the full-text search based on MySQL (used by default), but also Apache Solr search engine. And until recent our Magento extensions Improved Layered Navigation also supports Solr, which makes it easy to use for Magento sotre owners with any level of web-literacy.

What are the advantages of Apache Solr integration with Magento store?

Installation of Apache Solr for your Magento Store provides you with a number of advantages in comparison with the full-text search based on MySQL:

  • Zero results tips or results correction;
  • Suggestions;
  • Clustering;
  • Attribute weight based on attribute settings;
  • Localized characters search;
  • Word delimiter (for example, search of “spider man”, “spiderman return” or “spider-man”).

What is the essence of this installation?

Apache Solr installation consists of the following stages:

  1. Installation of Java Runtime Environment;
  2. Launch of Java application as a system service (to test it one can simply launch the application in the command line);
  3. Settings change of the full-text search in Magento Enterprise configuration.

Can I install Apache Solr by myself?

Since installation of Apache Solr is connected with the changes in the server configuration, we highly recommend you to refer to the professionals for the help (e.g. technical support service of your hosting). Before starting the installation please make a backup copy of your website and make sure you know how to restore the website from it!

How to install Apache Solr search for Magento store?

DISCLAIMER: If configured improperly Solr might have an adverse effect on server security. Carefully setup your firewall to protect Solr from possible malicious actions. Amasty takes no responsibility for any possible damages to equipment or software, downtime or any losses.

The instructions below are suitable for Debian/Ubuntu installations, for other installations commands may vary.

Install Java.

# aptitude install openjdk-7-jre-headless

Prepare directories for Solr installations.

# mkdir /srv/solr
# useradd -d /srv/solr -s /bin/bash solr
# chown solr:solr /srv/solr/
# su - solr

Download installation package Solr 3.4 (the version is chosen in accordance with the compatibility table).

$ wget http://archive.apache.org/dist/lucene/solr/3.4.0/apache-solr-3.4.0.tgz
$ tar xf apache-solr-3.4.0.tgz

Copy Magento configurations for Solr.

$ cp -r /path/to/magento/install/lib/Apache/Solr/conf/* apache-solr-3.4.0/example/solr/conf/

Prepare auto-start script (add the contents to the file /etc/init.d/apache-solr).

#! /bin/sh
### BEGIN INIT INFO
# Provides:          apache-solr
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Apache Solr
# Description:       Apache Solr search engine
### END INIT INFO

# Author: XXXXX XXXXXXXX <XXXXXXXXX@amasty.com>

SOLR_DIR="/srv/solr/apache-solr-3.4.0/example"
SOLR_USER="solr"
JAVA_OPTIONS="-Xmx1024m -DSTOP.PORT=10000 -DSTOP.KEY=jetty-stop-key -jar start.jar"
LOG_FILE="/var/log/apache-solr.log"
JAVA="java"

case $1 in
        start)  
                echo "Starting Solr"
                su - $SOLR_USER -c "cd $SOLR_DIR && exec $JAVA $JAVA_OPTIONS >$LOG_FILE 2>&1 &"
                ;;
        stop)   
                echo "Stopping Solr"
                su - $SOLR_USER -c "cd $SOLR_DIR && $JAVA $JAVA_OPTIONS --stop"
                ;;
        restart)
                $0 stop
                sleep 1
                $0 start
                ;;
        *)      
                echo "Usage: $0 {start|stop|restart}" >&2
                exit 1
                ;;
esac

:

And make it executable

# chmod 755 /etc/init.d/apache-solr

Create logrotate configuration (add the contents to the file  /etc/logrotate.d/apache-solr).

/var/log/apache-solr.log {
        daily
        rotate 7
        compress
        delaycompress
        missingok
        notifempty
        create 640 solr adm
}

Initialize file logs.

# touch /var/log/apache-solr.log
# chown solr:adm /var/log/apache-solr.log
# chmod 0640 /var/log/apache-solr.log

Launch Solr and add it to auto-start.

# update-rc.d apache-solr defaults
# service apache-solr start

If everything was done correctly, Solr control panel will be available at the address http://your-site-ip:8983/solr/admin/

Settings of Magento Enterprise for working with Solr

One can find the Official Manual on connecting Solr to Magento here.

The installed Solr can be found at the address your-site-ip:8983. To connect it one needs to:

  • Go to Magento admin panel  System / Configuration;
  • In the group CATALOG choose Catalog / Catalog Search;
  • Choose Solr in the field Search Engine;
  • Enter your-site-ip in the Solr Server Hostname field;
  • Enter 8983 in the Solr Server Port field;
  • Enter solr in the Solr Server Path;
  • Press Test connection button. If it has changed its color to green one, Solr is connected and is ready for use;
  • Save the changes (press Save Config button).

If required, update the indices at System / Index Management.

DISCLAIMER: If configured improperly Solr might have an adverse effect on server security. Carefully setup your firewall to protect Solr from possible malicious actions. Amasty takes no responsibility for any possible damages to equipment or software, downtime or any losses.