Book Image

Apache Solr PHP Integration

By : Jayant Kumar
Book Image

Apache Solr PHP Integration

By: Jayant Kumar

Overview of this book

The Search tool is a very powerful for any website. No matter what type of website, the search tool helps visitors find what they are looking for using key words and narrow down the results using facets. Solr is the popular, blazing fast, open source enterprise search platform from the Apache Lucene project. It is highly scalable, providing distributed search and index replication, and it powers the search and navigation features of many of the world's largest websites.This book is a practical, hands-on, end-to-end guide that provides you with all the tools required to build a fully-featured search application using Apache Solr and PHP. The book contains practical examples and step-by-step instructions.Starting off with the basics of installing Apache Solr and integrating it with Php, the book then proceeds to explore the features provided by Solr to improve searches using Php. You will learn how to build and maintain a Solr index using Php, discover the query modes available with Solr, and how to use them to tune the Solr queries to retrieve relevant results. You will look at how to build and use facets in your search, how to tune and use fast result highlighting, and how to build a spell check and auto complete feature using Solr. You will finish by learning some of the advanced concepts required to runa large-scale enterprise level search infrastructure.
Table of Contents (15 chapters)
Apache Solr PHP Integration
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Configuring Tomcat to run Solr


The web server jetty used by default Solr is meant for development purposes only. For production environment, we would want Solr to run as a part of a more convenient setup involving a more reliable web server. Solr can be configured to run on any J2EE container such as IBM Websphere or JBoss or any other server. Apache Tomcat is the most commonly used server. Let us see how to set up Solr as a part of Apache Tomcat web server. We have Apache Tomcat installed on our Windows or Linux environment.

To run Solr as a part of Apache Tomcat web server, you need to create a context for /solr in the configuration. The following solr.xml file needs to be put at the appropriate location in Windows and Linux inside the Tomcat configuration folder at <tomcat_home>/conf/Catalina/localhost.

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="/home/jayant/solr-4.3.1/example/webapps/solr.war" >
<Environment name="solr/home" type="java.lang.String" value="/home/jayant/solr-4.3.1/example/solr" override="true" />
</Context>

Change docBase to <solr_path>/example/webapps/solr.war and the value attribute in Environment to <solr_path>/example/solr. The environment named solr/home tells Tomcat the location where Solr configuration files are to be found. In addition to this, let us change the configuration of Solr in the <solr_path>/example/solr/solr.xml file. Search for hostPort and change it to match Tomcat's port 8080. Similarly search for hostContext and change it to solr.

Note

Windows users, use \ instead of / in your configuration XML files for path variables. Do not change the / in solr/home.

Restart your Tomcat server and you should be able to go to the following URL to see Solr working along with Tomcat:

http://localhost:8080/solr/

Tip

If you see an error "404 not found" on the preceding URL, it may be because of some libraries of Solr that Tomcat is not able to find. You can check the exact error in Tomcat error logs in the <tomcat_home>/logs/catalina.out folder. To resolve the missing library issue, copy all JAR files from the <solr_home>/example/lib/ext to <tomcat_home>/lib folder.

You can also enable advanced logging in your Tomcat logs by copying the log4j.properties file from the <solr_home>/example/resources folder to your <tomcat_home>/lib folder.