Apache Solr is a proven and popular open source search platform developed by Apache Lucene. It is an application developed in java and runs as a standalone full text search server embedded in a servlet container. Solr search is server-independent and supports the following features:

Multi Site Search: Multiple search sites can be performed when the large number of websites have a common index. The shared index of these sites stores the documents with a site and a hash field which enables to filter by keywords and generate the results either from a single site or the sites that share the index. There is Apache Solr Multisite Search Module  which adds the tab "Multisite search" to the search page.

Distributed Search: Takes place either when the length of the index exceeds the capacity of a single system or when the execution of a query takes a long time and splits the data into different parts. Solr can query and join the split results.

Faceted Search: This technique is used to minimize the search result according to the categories and get the relevant information. The end users are able to extract adequate information in several ways to meet their needs e.g. in a retail website, when a product is searched, the users get additional options to narrow search result in the left hand side. These options make the search more accurate and specific.

Solr also has an edge over drupal core search with respect to indexing and scalability.

Java Installation
Tomcat and Solr are dependent on Java Development Kit(JDK) and run on Java Virtual Machine (JVM). JDK consists of JVM and Java Runtime Environment (JRE). Therefore, we need to install full JDK.

aptitude install java7-jdk 

Tomcat 7
Apache Tomcat is another open source web server consisting servlet container. It enables us to view and run jsp and servlets in the browser. Apache Tomcat consists of configuration and management tools. However, it can be configured by editing XML configuration files. Tomcat 7 runs on Servlet 3.0 and JSP 2.2 specification. It requires Java Development Kit (JDK 1.6) and later version.

Installing Tomcat 7

  1. Add a user and associated permission
    useradd -Mb /usr/local tomcat
    chown -R tomcat:tomcat /usr/local/tomcat
    
  2. Get the Tomcat’s latest version from  http://tomcat.apache.org/download-70.cgi and download the file tar.gz binary to usr/local/src server and extract the file to usr/local/tomcat
    wget http://apache.tradebit.com/pub/tomcat/tomcat-7/v7.0.53/bin/apache-tomcat-7.0.53.tar.gz
    tar -C /usr/local -zxf /usr/local/src/apache-tomcat-7.*.tar.gz 
    mv /usr/local/apache-tomcat-7.* /usr/local/tomcat
    
  3. The default HTTP connector port and AJP connector port is 8080 and 8009 respectively. We had varnish installed on port 80 & Apache running on 8080. To avoid, we have to change port number Tomcat listens to. Command line to find & replace port number -
    sed -i s/8080/8983/g /usr/local/tomcat/conf/server.xml
    // You can give any non conflicting port number
    
  4. Test the successful installation of Apache Tomcat
    sudo -u tomcat /usr/local/tomcat/bin/startup.sh
    

You are good to go if you don’t see any errors on your termial.

Solr Installation steps

  1. Download Solr 4.7 from http://lucene.apache.org/solr/ and extract the downloaded file
    cd /usr/local/src
    wget http://apache.tradebit.com/pub/lucene/solr/4.7.2/solr-4.7.2.tgz
    tar -zxf solr-4.7.2.tgz
    
  2. Copy the Solr java library files from Solr to Tomcat library directory
    cp solr-4.7.2/dist/solrj-lib/* /usr/local/tomcat/lib/
    
  3. Copy log4j configuration file from Solr to Tomcat config directory
    cp solr-4.7.2/example/resources/log4j.properties /usr/local/tomcat/conf/ 
    
  4. Install Apache Solr’s war into Tomcat Webapps directory
    cp solr-4.7.2/dist/solr-4.7.0.war /usr/local/tomcat/webapps/solr.war
    
  5. Add Solr context file in /usr/local/tomcat/conf/Catalina/localhost/solr.xml and add the following code

Solr Configuration with Drupal

  1. Create the Solr directory and copy the example Solr configuration
    mkdir -p /usr/local/tomcat/solr
    cp -r solr-4.7.2/example/solr/collection1/conf /usr/local/tomcat/solr/
    
  2. Get the latest version of Search API Solr Search from Drupal ( Apache Solr Drupal module didn’t worked with Solr 4.7.2 though it used to work with Solr 4.4 )
    cd /usr/local/src
    wget http://ftp.drupal.org/files/projects/search_api_solr-7.x-1.4.tar.gz
    tar -zxf search_api_solr-*.tar.gz
    
  3. Copy Solr configuration files from Search API Solr Searchl module to Tomcat configuration directory
    rsync -av search_api_solr/solr-conf/4.x/ /usr/local/tomcat/solr/conf/
    
  4. Create Apache Solr Drupal setting in the path /usr/local/tomcat/solr/solr.xml and paste the following to define valuebound core (you can have own name for the core)
    <?xml version="1.0" encoding="UTF-8" ?>
    
  5. Make valuebound Solr core directory and copy Solr configuration files to new core
    mkdir /usr/local/tomcat/solr/valuebound
    cp -r /usr/local/tomcat/solr/conf /usr/local/tomcat/solr/valuebound/
    
  6. Now just stop tomcat and assign the permission and check this
    /usr/local/tomcat/bin/shutdown.sh	
    chown -R tomcat:tomcat /usr/local/tomcat
    sudo -u tomcat /usr/local/tomcat/bin/startup.sh
    

Now you will test your new the valuebound Solr core admin interface in http://yourdomain.com:8983/solr/#/valuebound. But you should be using http://yourdomain.com:8983/solr/valuebound URL while configuring Drupal Apache Solr.

Now to start tomcat automatically every time you restart server -

Download this tomcat init script. Create init file for tomcat at /etc/init.d/tomcat and copy paste content of tomcat.txt.

vi /etc/init.d/tomcat

 

Ref: http://www.lullabot.com/blog/article/installing-solr-use-drupal

Valuebound is a Drupal development company providing Apache Solr Implementation and integration with Drupal CMF. Contact us if you would like to use Apache Solr to improve search result for your Drupal driven web sites and applications..

 

comments powered by Disqus