How to set up and use Apache Solr in php

Posted on Tuesday, May 6, 2014
How to set up and use Apache Solr in php

 

Apache Solr is an open source search platform that allows to run search queries faster. It's quite popular because of its performance and ability to easily integrate with systems such as Drupal. It stores data in a way that is very fast for queries required by faceted search. It also provides full text searches.

Here we will be learning to install and configure apache solr in ubuntu 12.04. Download apache solr from http://lucene.apache.org/solr/downloads.html For our case we will be using Apache Solr 4.4.0 Other things we need

  • SolrClient
  • Jetty or Tomcat to run jar file which will indexes data and sends queries to XML files created by solr and return data. We will by using jetty in our case.

We will be using PECL solr extension for SolrPhpClient, for indexing solr data through its class & methods. In case you have not install PECL, you can do that by typing below command in your terminal sudo apt-get install php-pear You can install solr PECL extension by using the following command in your terminal. sudo pear install pecl/solr sudo pecl install -n solr sudo service apache2 restart For jetty, it can installed by using following command in your terminal sudo apt-get install jetty Once you have downloaded apache solr you need to put that in your www directory in case of LAMP and htdocs in you are using XAMPP for linux. After downloading solr, run start.jar by navigating to location SOLR-DIRECTORY/example/. Command to run jar file is same as its for any jar file i.e. java -jar start.jar. Once you have run start.jar, you can check if apache solr is running or not by access the url http://localhost:8983/solr/. By default solr uses 8983 port, so 8983 indicates port in the url. Now go to the solr directory that you have. Structure for it will like below

Apache solr structure

It is example directory which we will use mostly for our work purpose. In example directory there is solr directory, which holds our various collections and indexed data related to that collection.

Comments

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.