Skip to content

SolrIntegration

Delta edited this page Oct 18, 2023 · 1 revision

Integrating Apache Solr Search

Solr is a standalone, full text search server that is considerably more powerful than the core search module provided by Drupal. Integrating an existing Solr server is accomplished by installing the Apache Solr Search Integration module. Download the 6.x-3.x version from http://drupal.org/project/apachesolr

Setting Up a Solr Server

(If a Solr server is already running, skip ahead to Configure Solr Integration.)

Download the latest 3.x version tarball of Apache Solr and extract it to /opt (or another appropriate location on the filesystem). Copy three configuration files from the solr-conf directory of the apachesolr Drupal module to the example/solr/conf of the Solr installation: schema.xml, solrconfig.xml, and protwords.text. Then, create a directory at example/solr/data and give the apache user (www-data, apache2, etc.) write access to the directory.

Solr can be started as a test by changing to the example directory of the Solr installation and running the service as the apache user: sudo -u www-data java -jar start.jar

This example configuration may be sufficient in some cases, while in others it may be more appropriate to configure Solr to run in Tomcat or another application server. If the simple example implementation is acceptable, it can be made into an init service by creating an executable script at /etc/init.d/solr similar to the following:


# Prerequisites:
# 1. Solr needs to be installed at /usr/local/solr/example
# 2. daemon needs to be installed
# 3. Script needs to be executed by root

# This script will launch Solr in a mode that will automatically respawn if it
# crashes. Output will be sent to /var/log/solr/solr.log. A PID file will be
# created in the standard location.

start () {
    echo -n "Starting solr..."

    # Start daemon
    daemon --user=www-data --chdir='/usr/local/solr/example' --command "java -jar start.jar" --respawn --output=/var/log/solr/solr.log --name=solr --verbose

    RETVAL=$?
    if [ $RETVAL = 0 ]
    then
        echo "done."
    else
        echo "failed. See error code for more information."
    fi
    return $RETVAL
}

stop () {
    # Stop daemon
    echo -n "Stopping solr..."

    daemon --stop --name=solr  --verbose
    RETVAL=$?

    if [ $RETVAL = 0 ]
    then
        echo "Done."
    else
        echo "Failed. See error code for more information."
    fi
    return $RETVAL
}


restart () {
    daemon --restart --name=solr  --verbose
}


status () {
    # Report on the status of the daemon
    daemon --running --verbose --name=solr
    return $?
}


case "$1" in
    start)
        start
    ;;
    status)
        status
    ;;
    stop)
        stop
    ;;
    restart)
        restart
    ;;
    *)
        echo $"Usage: solr {start|status|stop|restart}"
        exit 3
    ;;
esac

exit $RETVAL

This script can then be enabled on a debian system with: update-rc.d solr defaults

On a redhat system: /usr/sbin/chkconfig --add solr

Once started, the Solr admin interface should be available at: http://localhost:8983/solr/admin/

Configure Solr Integration

If not already done (i.e. if this is a pre-existing implementation of Solr), copy schema.xml, solrconfig.xml, and protwords.text from the solr-conf directory of the apachesolr Drupal module to the conf directory of the Solr installation (e.g. example/solr/conf). Also, be sure the data directory is exists parallel to the conf directory and that the web service has write access to it.

Enable the "Global Search (solr)" feature in Drupal. There should now be an Apache Solr search menu item in administration under Site Configuration. That page gives the current status of the index and replaces core Drupal indexing. The Indexing throttle on the core Search settings page should be set to zero to disable it. If the Solr index status shows zero items indexed and zero remaining, try clicking the button to Queue all content for reindexing. Actions can then be taken to begin indexing or it can be handled in the background via cron.

**NOTE: Enabling Solr search does not disable internal Drupal indexing! Set "Number of items to index per cron run" to zero in Search settings or Drupal cron will continue to index site content!

Check other settings for Apache Solr search as appropriate. By default, the new search functionality will be available at the /search/site path of the website.

Clone this wiki locally